Announcement

Collapse
No announcement yet.

New Dialogs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • New Dialogs

    Under certain conditions when I create a new dialog from my main dialog, I want the new dialog to finish the statements defined under wm_initdialog and then create another new dialog.

    I have the creation of the second new dialog under the wm_initDialog of the first. The problem I have is the second is not active (and is not on top). It seems this cannot be done while within the Wm_initdialog of the first new dialog.



    ------------------
    Brent Boshart

  • #2
    Brent --
    Even if your app was not foreground, it's possible by simple minimize/restore.
    If your app had focus before, this process is much easy.
    Post a fragment.


    ------------------
    E-MAIL: [email protected]

    Comment


    • #3
      Brent;

      Here is one possibility:

      Define a custom Message for the main dialog:

      %WM_DisplayChildDialog = %WM_USER+100

      In the parent Dialogs WM_INITDIALOG message processing code, the last
      thing to do is to send itself the message %WM_DisplayChildDialog
      but using the POST method rather than send message.

      PostMessage hMyDialog&, %WM_DisplayChildDialog, 0,0

      When a message is posted, all other messages must be processed
      first before it gets processed. The Parent Dialog should display and
      get the focus before the Posted message gets processed.

      Then in the %WM_DisplayChildDialog message, the Parent Dialog should
      create the Child Dialog which should then receive the focus and
      be displayed.

      While this is only in theory, it just may work !

      If this doesn't work, then use a global variable as a flag in the
      parent forms WM_ACTIVATE message which will be set once the parent
      Dialog gets the focus. Then when the Parent Dialog gets the
      %WM_DisplayChildDialog message and the parent hasn't been displayed yet
      and gotten the focus (check the global variable), you can repost
      the %WM_DisplayChildDialog message to itself. If you do that make
      sure you test for an infinite loop just in case that is possible.

      I am curious to see if this will work.



      ------------------
      Chris Boss
      Computer Workshop
      Developer of "EZGUI"
      http://cwsof.com
      http://twitter.com/EZGUIProGuy

      Comment


      • #4
        Brent;

        I was curious whether my idea would work, so I wrote a sample
        program that demonstrates the concept and it actually works !

        Here is the source code (generated by my Visual Designer in just
        a few minutes) :

        Code:
        #COMPILE EXE
        #REGISTER NONE
        #DIM ALL          '  This is helpful to prevent errors in coding
        
        
        #INCLUDE "win32api.inc"   ' Must come first before other include files !
        
        ' *************************************************************
        
        %WM_DISPLAYCHILDDIALOG      =   %WM_USER+100
        
        
        ' *************************************************************
        '              Application Constants and Declares
        ' *************************************************************
        
        ' --------------------------------------------------
        DECLARE SUB ShowDialog_ParentForm(BYVAL hParent&)
        DECLARE CALLBACK FUNCTION ParentForm_DLGPROC
        ' --------------------------------------------------
        ' ------------------------------------------------
        
        
        %CHILDFORM_BUTTON1            = 100
        %CHILDFORM_BUTTON2            = 105
        ' --------------------------------------------------
        DECLARE SUB ShowDialog_ChildForm(BYVAL hParent&)
        DECLARE CALLBACK FUNCTION ChildForm_DLGPROC
        
        
        ' *************************************************************
        '            Application Global Variables and Types
        ' *************************************************************
        
        GLOBAL App_Brush&
        
        
        GLOBAL hParentForm&    ' Dialog handle
        GLOBAL hChildForm&    ' Dialog handle
        
        ' *************************************************************
        '                    Application Entrance
        ' *************************************************************
        
        FUNCTION PBMAIN
            LOCAL Count&
            App_Brush&=CreateSolidBrush(RGB(160,255,160))
            ShowDialog_ParentForm 0
            DO
                DIALOG DOEVENTS TO Count&
            LOOP UNTIL Count&=0
            DeleteObject App_Brush&
        END FUNCTION
        
        
        ' *************************************************************
        '                    Application Dialogs
        ' *************************************************************
        
        SUB ShowDialog_ParentForm(BYVAL hParent&)
            LOCAL Style&, ExStyle&
            LOCAL N&, CT&        '  Variables used for Reading Data in Arrays for Listbox and Combobox
            '   hParent& = 0 if no parent Dialog
            Style& = %WS_POPUP OR %DS_MODALFRAME OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %DS_CENTER
            ExStyle& = 0
            DIALOG NEW hParent&, "Parent Form", 0, 0,  267,  177, Style&, ExStyle& TO hParentForm&
            CONTROL ADD "Button", hParentForm&,  %CHILDFORM_BUTTON1,  "Button  1", 3, 3, 53, 15, _
                %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP
        
            DIALOG SHOW MODELESS hParentForm& , CALL ParentForm_DLGPROC
        END SUB
        
        
        CALLBACK FUNCTION ParentForm_DLGPROC
            SELECT CASE CBMSG
                ' ----------------------------------------
                ' The code below is how to impliment the Child Dialog so it gets focus
                ' rather than the parent dialog.
                ' ----------------------------------------
                CASE %WM_INITDIALOG
                    PostMessage hParentForm&, %WM_DISPLAYCHILDDIALOG,0,0
                CASE %WM_DISPLAYCHILDDIALOG
                    ShowDialog_ChildForm hParentForm&
                CASE ELSE
            END SELECT
        END FUNCTION
        
        
        SUB ShowDialog_ChildForm(BYVAL hParent&)
            LOCAL Style&, ExStyle&
            LOCAL N&, CT&        '  Variables used for Reading Data in Arrays for Listbox and Combobox
            '   hParent& = 0 if no parent Dialog
            Style& = %WS_POPUP OR %DS_MODALFRAME OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %DS_CENTER
            ExStyle& = 0
            DIALOG NEW hParent&, "Child Form", 0, 0,  181,  118, Style&, ExStyle& TO hChildForm&
            CONTROL ADD "Button", hChildForm&,  %CHILDFORM_BUTTON1,  "Button  1", 64, 17, 53, 15, _
                %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP
            CONTROL ADD "Button", hChildForm&,  %CHILDFORM_BUTTON2,  "Button  2", 64, 39, 53, 15, _
                %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP
            DIALOG SHOW MODELESS hChildForm& , CALL ChildForm_DLGPROC
        END SUB
        
        ' *************************************************************
        '                             Dialog Callback Procedure
        '                             for Form ChildForm
        '                             uses Global Handle - hChildForm&
        ' *************************************************************
        
        CALLBACK FUNCTION ChildForm_DLGPROC
            SELECT CASE CBMSG
                CASE %WM_CTLCOLORDLG
                    IF CBLPARAM=CBHNDL THEN
                        ' Dialogs colors
                        SetTextColor CBWPARAM, 0
                        SetBkColor   CBWPARAM, RGB(255,255,255)
                        FUNCTION=App_Brush&
                    END IF
                CASE ELSE
            END SELECT
        END FUNCTION

        I removed all the unnecessary code to make it simpler !


        [This message has been edited by Chris Boss (edited January 14, 2001).]
        Chris Boss
        Computer Workshop
        Developer of "EZGUI"
        http://cwsof.com
        http://twitter.com/EZGUIProGuy

        Comment


        • #5
          Chris, by any chance, does your code generator have a "minimal" mode? It is just that these kind of posting seem excessively large, given the context of your posting.

          For example, the code above is supposedly demonstrating a couple of simple callback message handlers... it makes it very hard to clearly identify the portion of the code that actually pertains to the original question, making it look more like a subliminal advertisment for your products?!

          TO be clear, I'm not knocking your fine product (or you). However I do have concerns over the size of the posting given the nature of the question.

          Thanks!

          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            I agree Lance;

            Sadly, the program doesn't have a minimal mode. I haven't had time to make the program
            better and likely it will be replaced by a commercial version.

            I was in a hurry when I made the test program so I didn't have time
            to remove all the unnecessary code. Time is at a premium right now.


            [This message has been edited by Chris Boss (edited January 14, 2001).]
            Chris Boss
            Computer Workshop
            Developer of "EZGUI"
            http://cwsof.com
            http://twitter.com/EZGUIProGuy

            Comment


            • #7
              Lance;

              I never write GUI code by hand anymore and I don't work with DDT
              very much, so I simply used my Visual Designer. I felt an actual
              program that proves that the technique worked was important, so
              I used what was fastest for me (the Visual Designer).

              Most apps have a lot more stuff in them, so most of the seemly useless
              code in my library code will likely be used. Also if a new Dialog
              is added later, the library code is already there which may be
              needed in future modifications.

              Most of the programmers who are used to hand coding DDT code could
              have written the sample above quicker than me, but for me I am used
              to generated code.

              I don't really have the time to devote to posting on the PB forum,
              like I would like to, so anything that speeds up the process is
              useful to me.

              Sorry if the code above was a distraction !


              ------------------
              Chris Boss
              Computer Workshop
              Developer of "EZGUI"
              http://cwsof.com
              http://twitter.com/EZGUIProGuy

              Comment

              Working...
              X