April 30, 2024, 05:37:48 AM

News:

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


Setting up a complete dialog in a subroutine

Started by TexasPete, May 12, 2010, 12:53:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TexasPete

I have been working on dialog's. It appears that you cannot set up a complete dialog within a subroutine. See Example.  Is this finding 100 percent correct . It appears that it must be setup in the main code. Has anyone done anything different. I would
appreciate and example is someone has one.

Thanks
Texas Pete

Rock Ridge Farm (Larry)

Where is the example?
Do you mean a dynamic dialog?
I did some code in the past that created a hidden dialog and made it visible in a
subroutine.


Larry

LarryMc

May 12, 2010, 02:18:26 PM #2 Last Edit: May 12, 2010, 02:30:00 PM by Larry McCaughn
TP
Here's an example.  Remember I said i thought there was something in the 'trash' in your code that was messing things up.

The OptionsPage subroutine is not a 'regular' subroutine; it is a message handler for a dialog.  There is a ton of stuff that is going on in the background with WINDOWS default handler for dialogs. (What ever messages you don't process the default handler takes care of.

To open the dialog it has to be defined first - that's what I did with the InitDialog subroutine.

Now, when I open the dialog with DOMODAL the dialog is opened and the controls are created and all kinds of messages are sent to the handler. One of those is the @IDINITDIALOG message and is sent after the controls are creaated .  You set fonts and stuff here because in the sequence of events it insures the controls exists.  When things are done in the @IDINITDIALOG the subroutine returns to the OS default handler to do whatever it has to do next.  There's a lot of smoke and mirrors going on with handlers, be they for dialogs or for windows.

And you can't 'nest' subroutines like:
sub mysub1 <--- intDialog
 sub mysub2 <--- dialog handler
 return
return


It has to be:
sub mysub1 <--- intDialog
return

sub mysub2 <--- dialog handler
return


Or you can do away with sub1 an just put its code inline before your waituntil run=2 statement

Hope this helps.

LarryMc


def wMain1:window
def PageOptions:dialog
def run:int
Window wMain1,0,0,600,480,0,0,"test window",main1
CONTROL wMain1,"B,Open dialog,300,240,120,35,0x50000000,20"

gosub InitDialog

run=0
Waituntil run = 2
CLOSEWINDOW wMain1
END

SUB main1
   SELECT @CLASS
      CASE @IDCLOSEWINDOW
         run = 2
      CASE @IDCONTROL
         Select @CONTROLID
            CASE 20
               result=DOMODAL PageOptions
         ENDSELECT
      CASE @IDMENUPICK
         SELECT   @MENUNUM

         ENDSELECT
      CASE @IDMOUSEMOVE
      CASE @IDLBUTTONDN    
      CASE @IDLBUTTONDBLCLK
      CASE @IDLBUTTONUP
      CASE @IDRBUTTONDN
      CASE @IDRBUTTONUP
      CASE @IDRBUTTONDBLCLK
      CASE @NOTIFYCODE
   ENDSELECT

RETURN


sub InitDialog
   DIALOG PageOptions,0,0,320,240,0x80C80080,wMain1,"Options",OptionsPage
   CONTROL PageOptions,"B,OK,127,120,70,35,0x50000000,16"
return

SUB OptionsPage
   SELECT @CLASS
      CASE @IDCONTROL
         SELECT @CONTROLID
            case 16
               CLOSEDIALOG PageOptions,@IDOK
         ENDSELECT
      'All controls should be initialized while processing the @IDINITDIALOG message
      CASE @IDINITDIALOG
         setfont PageOptions,"Comic Ms Sans", 10, 700, @SFITALIC,16
         CENTERWINDOW PageOptions
   ENDSELECT
RETURN
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

TexasPete

I noticed than in this example you did not use "DOModal" . So it appears to be at least four different styles in setting up a Dialog menu. I like learning different ways to do things.  After I learn then I pick the one style that makes the most sense to me.
I am going to play with this somemore. I think there may be at least one more way. For me dialog's were harder than windows. I like the way of using a window and making it behave like a dialog.

Thanks Larry,
Texas Pete

LarryMc

Quote from: TexasPete on May 12, 2010, 06:23:40 PM
I noticed than in this example you did not use "DOModal"
But I did!
Did you run the sample program?
If I didn't use domodal the dialog would never have opened when the button was clicked.
SUB main1
   SELECT @CLASS
      CASE @IDCLOSEWINDOW
         run = 2
      CASE @IDCONTROL
         Select @CONTROLID
            CASE 20
               result=DOMODAL PageOptions <<<<=================
         ENDSELECT
      CASE @IDMENUPICK
         SELECT   @MENUNUM

         ENDSELECT
      CASE @IDMOUSEMOVE
      CASE @IDLBUTTONDN   
      CASE @IDLBUTTONDBLCLK
      CASE @IDLBUTTONUP
      CASE @IDRBUTTONDN
      CASE @IDRBUTTONUP
      CASE @IDRBUTTONDBLCLK
      CASE @NOTIFYCODE
   ENDSELECT

RETURN


Rules of road:

1.you always have to have a stand alone subroutine which is the dialog's message handler.

2. you can either set the creation of the dialog in in-line code between the creation of the parent window and the parent window's WAITUNTIL command, or, in a separate subroutine where you can create multiple dialogs if you like(I do that all the time).

3.if you choose the latter than you have to call the init subroutine after the parent window is created and before the parent's WAITUNTIL

4. then you place the domodal command in your parent window's message handler in the case statement  for which ever button press you want to use to open the dialog.

Quote from: TexasPete on May 12, 2010, 06:23:40 PM
So it appears to be at least four different styles in setting up a Dialog menu.
We haven't mentioned menus in the past couple of days so I don't know what you mean by that.

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

LarryMc

Quote from: TexasPete on May 12, 2010, 12:53:00 PM
I have been working on dialog's.  See Example. 
Post your example (that you forgot to post) and let's see where you're having the problem.

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

TexasPete

Larry , I see the domodel now!. Does Showdialog behave the exact sam way as domodel. I will Play with it and see.
Thanks
Texas Pete

LarryMc

Quote from: TexasPete on May 14, 2010, 06:00:36 AM
Does Showdialog behave the exact sam way as domodel.
No; from the help file
QuoteUnlike DOMODAL a dialog shown with SHOWDIALOG does not block user input with other window. A non-modal dialog requires normal message processing with a WAIT or WAITUNTIL loop.

LarryMc

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

TexasPete

May 14, 2010, 11:08:45 AM #8 Last Edit: May 14, 2010, 11:30:41 AM by TexasPete
Thanks Larry,  That was some excellent information. I will assume that using showdialog will allow the dialog to behave more like a window. You could then use "   EnableWindow(wMain1,0) " commands to disable input from the main window which would cause the called dialog to behave as if you  used modal  instead of Show Dialog. Or course you must reenable the original window before you exit the dialog. An example below.



def run:int
def wMain1:window
def PageOptions:dialog
Window wMain1,0,0,600,480,0,0,"test window",main1
CONTROL wMain1,"B,Open dialog,300,240,120,35,0x50000000,20"

'gosub InitDialog

run=0
Waituntil run = 2
CLOSEWINDOW wMain1
END

SUB main1
   SELECT @CLASS
      CASE @IDCLOSEWINDOW
         run = 2
      CASE @IDCONTROL
         Select @CONTROLID
            CASE 20
              gosub InitDialog 
         ENDSELECT
      CASE @IDMENUPICK
         SELECT   @MENUNUM

         ENDSELECT
      CASE @IDMOUSEMOVE
      CASE @IDLBUTTONDN   
      CASE @IDLBUTTONDBLCLK
      CASE @IDLBUTTONUP
      CASE @IDRBUTTONDN
      CASE @IDRBUTTONUP
      CASE @IDRBUTTONDBLCLK
      CASE @NOTIFYCODE
   ENDSELECT

RETURN


sub InitDialog
 
def drun:int
DIALOG PageOptions,0,0,320,240,0x80C80080,wMain1,"Options",OptionsPage
   CONTROL PageOptions,"B,OK,127,120,70,35,0x50000000,16"
showDialog PageOptions
drun=0
Waituntil drun = 2


return

SUB OptionsPage
   SELECT @CLASS
      CASE @IDCONTROL
         SELECT @CONTROLID
            case 16
           drun = 2:CLOSEDialog PageOptions
 
         ENDSELECT
      'All controls should be initialized while processing the @IDINITDIALOG message
      CASE @IDINITDIALOG
         setfont PageOptions,"Comic Ms Sans", 10, 700, @SFITALIC,16
         CENTERWINDOW PageOptions
   ENDSELECT
RETURN


Something like the above could be done.? Now larry the above worked the first run thru. However , trying to display the dialog a second time caused it to have and error message that the dialog was defined twice. Why did't closeing the dialog destroy  The original defined dialog , Like it was starting all over. I thought placing anything in a sub routine unless it was global would destroy the contents of the sub routine.

Thanks Texas Pete


Texas Pete

aurelCB

Hi pete
Your main problem is becose you create Dialog inside subroutine.
You must create dialog after window is created and is not showed.OK
Then you show dialog inside sub init:
I hope that help... ;)

def run:int
def drun:INT
def wMain1:window
def PageOptions:dialog
Window wMain1,0,0,600,480,0,0,"test window",main1
CONTROL wMain1,"B,Open dialog,300,240,120,35,0x50000000,20"
'create dialog here
DIALOG PageOptions,0,0,320,240,0x80C80080,wMain1,"Options",OptionsPage
CONTROL PageOptions,"B,OK,127,120,70,35,0x50000000,16"


run=1
Waituntil run = 0
CLOSEWINDOW wMain1
END

SUB main1
   SELECT @CLASS
      CASE @IDCLOSEWINDOW
         run = 0

      CASE @IDCONTROL
         Select @CONTROLID
            CASE 20
             IF drun=0 then Gosub InitDialog
MessageBox 0,"DRUN:"+str$(drun),"test"
         ENDSELECT

     
   ENDSELECT

RETURN


SUB InitDialog
 
SHOWDIALOG PageOptions
drun=1

'Waituntil drun = 2
Return drun

SUB OptionsPage
   SELECT @CLASS
      CASE @IDCONTROL
         SELECT @CONTROLID
            CASE 16
            CLOSEDIALOG PageOptions,@idok
drun=0
MessageBox 0,"DRUN:"+str$(drun),"test"
 
         ENDSELECT
      'All controls should be initialized while processing the @IDINITDIALOG message
      CASE @IDINITDIALOG
         setfont PageOptions,"Comic Ms Sans", 10, 700, @SFITALIC,16
         CENTERWINDOW PageOptions
   ENDSELECT
RETURN

LarryMc

QuoteWhy did't closeing the dialog destroy  The original defined dialog , Like it was starting all over. I thought placing anything in a sub routine unless it was global would destroy the contents of the sub routine.
If closing the dialog destroyed it then the domal way of calling a dialog (like I showed you before) wouldn't allow you to keep calling the dialog over and over(which you can).
I think it is going to boil down that's just the way the DIALOG command works.

I don't understand why you are even trying to do it that way.

You're telling me you want to open the dialog and disable the parent window until you close the dialog.
To do it the way you are trying, you have to:
1. add a line of code to call the dialog routine
2. add 2 lines of code to disable and enable the parent window
3. a line to define drun
4. add a line to actually open the dialog(showDialog)
5. add 2 lines to handle the drun/waituntil setup

That's a total of 7 lines of code and you have not addressed the situation where you tell the main program the return code from the dialog.

In my example below:
You don't need the 5 lines (2, 3, and 5 from above)
#1 from above remains in you main program but is placed right after where you create the parent window.
#4 is placed in your main handler where you want to open the dialog and changed to domodal.
And the disabling and enabling of the parent window is handled automatically.

LarryMc

def run:int
def wMain1:window
def PageOptions:dialog
Window wMain1,0,0,600,480,0,0,"test window",main1
CONTROL wMain1,"B,Open dialog,300,240,120,35,0x50000000,20"

gosub InitDialog

run=0
Waituntil run = 2
CLOSEWINDOW wMain1
END

SUB main1
   SELECT @CLASS
      CASE @IDCLOSEWINDOW
         run = 2
      CASE @IDCONTROL
         Select @CONTROLID
            CASE 20
              domodal PageOptions
         ENDSELECT
      CASE @IDMENUPICK
         SELECT   @MENUNUM

         ENDSELECT
   ENDSELECT
RETURN


sub InitDialog
DIALOG PageOptions,0,0,320,240,0x80C80080,wMain1,"Options",OptionsPage
   CONTROL PageOptions,"B,OK,127,120,70,35,0x50000000,16"
return

SUB OptionsPage
   SELECT @CLASS
      CASE @IDCONTROL
         SELECT @CONTROLID
            case 16
            CLOSEDialog PageOptions,@IDOK
          ENDSELECT
      'All controls should be initialized while processing the @IDINITDIALOG message
      CASE @IDINITDIALOG
         setfont PageOptions,"Comic Ms Sans", 10, 700, @SFITALIC,16
         CENTERWINDOW PageOptions
   ENDSELECT
RETURN
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Yes Pete Larry is right your request is little bit confusing.
So if you want disabled (unfocused ) main window when dialog is open use Larry example
with modal type of dialog.
If you need nomodal type of dialog use mine example.

Aurel

TexasPete

Ok ,  I think I get it . I just can't do it that way. Thanks for everybody's time. I wanted to do it that way because I could in the other language.  I like being able to organize my modules as one complete section and not having code strung out all over the place.  I thought if I could do it in the other language there must be a way to do it that way here.
I 'll just drop it. I think I have worn Dialogs out.

Thanks
Texas Pete

LarryMc

Like the old joke,"If it hurts when you do that; then don't do that".

What I typically do is "create" the dialogs (and my windows for that matter) in one or more subroutines so I don't have to keep looking at them.
Since I use EBasic I put them in a separate source file so I don't even have to have the file open.

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

TexasPete

Larry , I learned my lesson.  I won't do that.
Thanks
Texas Pete