October 06, 2022, 11:18:36 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


5c. Adding code

Started by LarryMc, October 14, 2014, 04:50:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

In this section we will address the creation of our child dialog along with the basic message handler to go with it.

Referring to our original scope:
2. A DIALOG which is opened via a button on the main window.
   a)the dialog is configured in a subroutine
   b) the handler for the dialog
   c) both 2a and 2b are together in their own file
   d)the dialog processes information passed to it via a global value
   e)after processing the resulting data is displayed in the main window



To comply with 2a. above we place the CREATEDIALOG line in the dialog_1.iwb file in its own subroutine.
This will result in the dialog_1.iwb file looking like this:
$include "globals.iwb"
global sub InitDlg1()

createdialog dlg1, 0, 0, 800, 700, @CAPTION|@SYSMENU, w1, "dlg1", &dlg1_Handler

return
endsub


Again, notice the use of the GLOBAL keyword preceding SUB.
This is a requirement for any subroutine that will be called from a different source file.

To comply with 2b. and 2c. above we place the dialog message handler code in the same dialog_1.iwb file. This will result in the dialog_1.iwb file looking like this:

$include "globals.iwb"

global sub InitDlg1()

createdialog dlg1, 0, 0, 400, 400, @CAPTION|@SYSMENU, w1, "dlg1", &dlg1_Handler

return
endsub

SUB dlg1_Handler(),INT
   SELECT @MESSAGE
CASE @IDINITDIALOG
centerwindow dlg1
case @idcontrol
SELECT @controlid

ENDSELECT
CASE @IDCLOSEWINDOW
closedialog dlg1
endselect
return 0
endsub


Notice this time we did not add the Global keyword in front of SUB dlg1_handler(),int.
This is because the handler is in the same source file at the CREATEDIALOG command.

Now we add a call to the InitDlg1() routine in the main.iwb file
This will result in the main.iwb file looking like this:

$MAIN
$include "globals.iwb"

InitMain()
InitDlg1()


WAITUNTIL iswindowclosed(w1)
END

global SUB w1_Handler(),INT
   SELECT @MESSAGE
CASE @IDCREATE
centerwindow w1
case @idcontrol
SELECT @controlid
'CASE ID_GRID1
' SELECT @NOTIFYCODE

' ENDSELECT
ENDSELECT
CASE @IDCLOSEWINDOW
closewindow w1
endselect
return 0
endsub


Since the dialog dlg1 will be opened from some other source file in our Project we need to make it Project Global just like we did with w1. We'll put the declaration in the globals.iwb file which will now look like this:

AUTODEFINE "OFF" /* I always use this - personal preference */
$include "windowssdk.inc"  /* I always use this - personal preference */
'$include "Commctrl.inc"
'$include "ctl.inc"

/******* structure definitions ******************************************/
'$INCLUDE "struct.inc"

/******* end of structure definitions ***********************************/

/******* constants definitions ******************************************/
'$INCLUDE "const.inc"

/******* end of constants definitions ***********************************/

/******* extern definitions ******************************************/
'$INCLUDE "extern.inc"
declare extern w1_Handler(),INT
declare extern InitMain()
/******* end of extern definitions ***********************************/

projectglobal "on"
window w1
dialog dlg1


projectglobal "off"


We're not quite through. What we haven't done is tell the other source files that the InitDlg1() subroutine is available.

To take care of this we go back to the globals.iwb file
We add two lines to the externals section of the file which looks like this.


/******* extern definitions ******************************************/
'$INCLUDE "extern.inc"
declare extern w1_Handler(),INT
declare extern InitMain()
declare extern InitDlg1()
/******* end of extern definitions ***********************************/


We will revisit these source files as we flesh out the rest of our application.

If our Project was going to use 50 different dialogs we would set up each one exactly like this.
And since dialogs don't really exist until they are opened with SHOWDIALOG or DOMODAL we use our INIT... routines to create the dialogs just once at the beginning of our application. Once a dialog is created it can be opened and closed as many times as you want without having to recreate it.

This completes 5c. Adding Code 


 

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library