Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

%wm_initdialog

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

  • %wm_initdialog

    Hi,

    In reading the help file for "DIALOG NEW" (PBWIN v8), I noted that the WM_INITDIALOG is for doing something "before" the dialog is displayed.

    Is there a corresponding message for "after" the the display is complete?

    (I know... that's when you start mousing buttons, etc... But I'd like my user to see what happens after the program is all loaded, and w/o user intervention.)

    The reason for my question is because of the different results I was getting using the PIXELS keyword in the DIALOG NEW statement in a program I was working on.

    To save space, I wrote a short test program which follows. To see the different behaviors I'm talking about, re-comment the appropriate line in the "show dialog" function.

    Sincerely,

    Ken
    Code:
    #PBFORMS CREATED V1.51
    '------------------------------------------------------------------------------
    ' The first line in this file is a PB/Forms metastatement.
    ' It should ALWAYS be the first line of the file. Other
    ' PB/Forms metastatements are placed at the beginning and
    ' end of "Named Blocks" of code that should be edited
    ' with PBForms only. Do not manually edit or delete these
    ' metastatements or PB/Forms will not be able to reread
    ' the file correctly.  See the PB/Forms documentation for
    ' more information.
    ' Named blocks begin like this:    #PBFORMS BEGIN ...
    ' Named blocks end like this:      #PBFORMS END ...
    ' Other PB/Forms metastatements such as:
    '     #PBFORMS DECLARATIONS
    ' are used by PB/Forms to insert additional code.
    ' Feel free to make changes anywhere else in the file.
    '------------------------------------------------------------------------------
    
    #COMPILE EXE
    #DIM ALL
    
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES
    #IF NOT %DEF(%WINAPI)
        #INCLUDE "WIN32API.INC"
    #ENDIF
    #PBFORMS END INCLUDES
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS
    %IDD_DIALOG1 =  101
    %IDC_BUTTON1 = 1001
    #PBFORMS END CONSTANTS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
        LOCAL High&, Wide&
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                DIALOG GET CLIENT CBHNDL TO wide&, high&
                MSGBOX "Width = " & STR$(wide&) & "  Height = " & STR$(high&)
                ' Initialization handler
    
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
    
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CBCTL
                    CASE %IDC_BUTTON1
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            DIALOG SHOW STATE CBHNDL, %SW_MAXIMIZE
                            DIALOG GET CLIENT CBHNDL TO wide&, high&
                            MSGBOX "Width = " & STR$(wide&) & "  Height = " & STR$(high&)
                        END IF
    
                END SELECT
        END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt AS LONG
    
    #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
        LOCAL hDlg  AS DWORD
    
    '    DIALOG NEW PIXELS, hParent, "Dialog1", 86, 109, 416, 299, %WS_MAXIMIZE TO hDlg
        DIALOG NEW hParent, "Dialog1", 86, 109, 416, 299, %WS_MAXIMIZE TO hDlg
        CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Maximize", 52, 32, 128, 41
    #PBFORMS END DIALOG
    
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
    #PBFORMS END CLEANUP
    
        FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------
    Ken S. Elvehjem
    [email protected]

  • #2
    The reason for my question is because of the different results I was getting using the PIXELS keyword in the DIALOG NEW statement in a program I was working on.
    Definitely expected behavior. When the PIXELS keyword is omitted, all DDT statements operate on DIALOG UNITS. When the PIXELS keyword is used, all DDT statements operate on PIXELS instead.
    Adam Drake
    Drake Software

    Comment


    • #3
      > Is there a corresponding message for "after" the the display is complete?

      Other than WM_SHOWWINDOW, not directly. A good method is to use "DIALOG POST CBHNDL, %WM_USER+400, 0, 0" from the WM_INITDIALOG handler. This will post a custom message (I defined it as WM_USER+400, but it could be anything above WM_USER), the 'POST' basically indicates that the message is low priority and will be received by the callback procedure after more important messages. When you receive the custom message you'll know the dialog has loaded and been shown.

      This is useful for example when you want to display a splash or status window whilst loading important startup data that may cause a delay. You can simply destroy the status window when you get the custom message.
      kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

      Comment


      • #4
        Well, yes... not to be funny or anything, but I *did* get that...

        Let me explain further.... (Or you could run the code yourself ;>)

        Using the following Dialog New command:

        DIALOG NEW hParent, "Dialog1", 86, 109, 416, 299, %WS_MAXIMIZE TO hDlg

        I get a dialog telling how big it's gonna be. When I OK the message box, it maximizes. Then, I hit the maximize button (a little redundant because it already is maximized) and it tells me again how big it is.

        Using the following Dialog New command:

        DIALOG NEW PIXELS, hParent, "Dialog1", 86, 109, 416, 299, %WS_MAXIMIZE TO hDlg

        I get a message box telling me the size from the Dialog New command (in this case, 416 x 299) but the dialog does not maximize.

        Further, when you press the maximize button it also does not "maximize" in the sense that I would expect, but the message box reports the size it "should" be, but it does not move the dialog to the upper left hand coroner of the screen.

        This behavior has me a li'l confused... It's just not something I've had to deal with.

        Ken
        Ken S. Elvehjem
        [email protected]

        Comment


        • #5
          Kev,

          Thanks for the reply; I did find that reference as I was digging through the forum for "INITDIALOG".

          On trying it, however, I got the same results as just putting my code in the INITDALOG segment.

          Ken
          Ken S. Elvehjem
          [email protected]

          Comment


          • #6
            Sorry, mis-read that one, and definitely assumed I read the whole thing right. Sorry about that. That is an interesting feature, and I have no clue why it's happening. However, it is actually maximizing, it is just placing the top left coordinates when maximized in the wrong place.
            Adam Drake
            Drake Software

            Comment


            • #7
              Adam,

              Yep, and the problem is that if I want to assume a maximized screen, and calculate positions from that in pixels, then I can't seem to do it automagically -- Have to wait and get user input.

              And please don't call it a "feature" ... it might cost extra in the future! ;>)

              Ken
              Ken S. Elvehjem
              [email protected]

              Comment


              • #8
                Kev,

                You might want to give Kev's suggestion a try, where you post a custom message inside %WM_INITDIALOG, and check the size of the dialog there.

                Something like this (I added some styles so I had min/max/close buttons):

                Code:
                #PBFORMS CREATED V1.51
                '------------------------------------------------------------------------------
                ' The first line in this file is a PB/Forms metastatement.
                ' It should ALWAYS be the first line of the file. Other
                ' PB/Forms metastatements are placed at the beginning and
                ' end of "Named Blocks" of code that should be edited
                ' with PBForms only. Do not manually edit or delete these
                ' metastatements or PB/Forms will not be able to reread
                ' the file correctly.  See the PB/Forms documentation for
                ' more information.
                ' Named blocks begin like this:    #PBFORMS BEGIN ...
                ' Named blocks end like this:      #PBFORMS END ...
                ' Other PB/Forms metastatements such as:
                '     #PBFORMS DECLARATIONS
                ' are used by PB/Forms to insert additional code.
                ' Feel free to make changes anywhere else in the file.
                '------------------------------------------------------------------------------
                
                #COMPILE EXE
                #DIM ALL
                
                '------------------------------------------------------------------------------
                '   ** Includes **
                '------------------------------------------------------------------------------
                #PBFORMS BEGIN INCLUDES
                #IF NOT %DEF(%WINAPI)
                    #INCLUDE "WIN32API.INC"
                #ENDIF
                #PBFORMS END INCLUDES
                '------------------------------------------------------------------------------
                
                '------------------------------------------------------------------------------
                '   ** Constants **
                '------------------------------------------------------------------------------
                #PBFORMS BEGIN CONSTANTS
                %IDD_DIALOG1 =  101
                %IDC_BUTTON1 = 1001
                #PBFORMS END CONSTANTS
                '------------------------------------------------------------------------------
                
                '------------------------------------------------------------------------------
                '   ** Declarations **
                '------------------------------------------------------------------------------
                DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
                DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                #PBFORMS DECLARATIONS
                '------------------------------------------------------------------------------
                
                '------------------------------------------------------------------------------
                '   ** Main Application Entry Point **
                '------------------------------------------------------------------------------
                FUNCTION PBMAIN()
                    ShowDIALOG1 %HWND_DESKTOP
                END FUNCTION
                '------------------------------------------------------------------------------
                
                '------------------------------------------------------------------------------
                '   ** CallBacks **
                '------------------------------------------------------------------------------
                CALLBACK FUNCTION ShowDIALOG1Proc()
                    LOCAL High&, Wide&
                
                    SELECT CASE AS LONG CBMSG
                        CASE %WM_INITDIALOG
                            DIALOG POST CBHNDL, %WM_USER + 400, 0, 0
                
                        CASE %WM_NCACTIVATE
                            STATIC hWndSaveFocus AS DWORD
                            IF ISFALSE CBWPARAM THEN
                                ' Save control focus
                                hWndSaveFocus = GetFocus()
                            ELSEIF hWndSaveFocus THEN
                                ' Restore control focus
                                SetFocus(hWndSaveFocus)
                                hWndSaveFocus = 0
                            END IF
                
                        CASE %WM_USER + 400
                
                            DIALOG GET CLIENT CBHNDL TO wide&, high&
                            MSGBOX "Width = " & STR$(wide&) & "  Height = " & STR$(high&)
                
                        CASE %WM_COMMAND
                            ' Process control notifications
                            SELECT CASE AS LONG CBCTL
                                CASE %IDC_BUTTON1
                                    IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                        DIALOG SHOW STATE CBHNDL, %SW_MAXIMIZE
                                        DIALOG GET CLIENT CBHNDL TO wide&, high&
                '                        dialog units cbhndl, wide&, high& to pixels wide&, high&
                                        MSGBOX "Width = " & STR$(wide&) & "  Height = " & STR$(high&)
                                    END IF
                
                            END SELECT
                    END SELECT
                END FUNCTION
                '------------------------------------------------------------------------------
                
                '------------------------------------------------------------------------------
                '   ** Dialogs **
                '------------------------------------------------------------------------------
                FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                    LOCAL lRslt AS LONG
                
                #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
                    LOCAL hDlg  AS DWORD
                
                    DIALOG NEW PIXELS, hParent, "Dialog1", 86, 109, 416, 299, %WS_MAXIMIZE OR %WS_POPUP OR %WS_BORDER _
                        OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _
                        %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME _
                        OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
                        %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                        %WS_EX_RIGHTSCROLLBAR, TO hDlg
                '    DIALOG NEW hParent, "Dialog1", 86, 109, 416, 299, %WS_MAXIMIZE or %WS_POPUP OR %WS_BORDER _
                '        OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _
                '        %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME _
                '        OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
                '        %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                '        %WS_EX_RIGHTSCROLLBAR, TO hDlg
                    CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Maximize", 52, 32, 128, 41
                #PBFORMS END DIALOG
                
                    DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                
                #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
                #PBFORMS END CLEANUP
                
                    FUNCTION = lRslt
                END FUNCTION
                '------------------------------------------------------------------------------
                Adam Drake
                Drake Software

                Comment


                • #9
                  Adam,

                  Your version works... and then I changed the origin of the DIALOG NEW:

                  DIALOG NEW PIXELS, hParent, "Dialog1", 0, 0, 40, 40......

                  And it puts it where it belongs -- *and* reports the correct size on startup.

                  I'm going to try it with my app... again... and let you know.

                  It still doesn't explain y it does not 1.) Honor the WS_MAXIMIZE in the DIALOG NEW PIXEL mode 2.) MAXIMIZE it into the UL corner of the screen, and 3.) tell me what other Gotchas might be lurking in the PIXEL mode of the dialog.

                  Ken
                  Ken S. Elvehjem
                  [email protected]

                  Comment


                  • #10
                    Adam,

                    Kev's suggestion is working fine now -- I must have made some kind of mistake the first time around.

                    I still wish someone would explain this behavior... it would be nice to know for sure if it's a feature or a bug;>)

                    Many thanks to Kev and Adam for your help.

                    Ken
                    Ken S. Elvehjem
                    [email protected]

                    Comment


                    • #11
                      Re: Message for "after" the the display is complete. Here's a slight tweak to Kev's suggestion.
                      If you comment out Dialog Redraw CbHndl and enable the WinBeep statement, you'll see that the dialog is shown but not yet the control(s) when %WM_USER + message arrives.
                      Code:
                          SELECT CASE AS LONG CBMSG
                              CASE %WM_INITDIALOG
                                  ' Initialization handler
                                  Dialog Post CbHndl, %WM_USER + 1000, 0, 0 
                                  ' PB help for Dialog Post suggests %WM_USER + >500 prefered.
                       
                              Case %WM_USER + 1000            ' Equiv to ShowWindow,
                                  Dialog Redraw CbHndl        ' UpDateWindow in SDK style? ;)
                      '            WinBeep 500, 1000
                                  DIALOG GET CLIENT CBHNDL TO wide&, high&
                                  MSGBOX "Width = " & STR$(wide&) & "  Height = " & STR$(high&)
                      There have been a number of 'fixes' to DIALOG NEW PIXELS in the last few releases - seems like another may be needed!
                      Code:
                          DIALOG NEW PIXELS, hParent, "Dialog1", 86, 109, 416, 299, TO hDlg
                          Dialog Show State hDlg, %SW_MAXIMIZE
                      Behaves the same as..
                      Code:
                          DIALOG NEW hParent, "Dialog1", 86, 109, 416, 299, %WS_MAXIMIZE TO hDlg
                      Rgds, Dave

                      Comment


                      • #12
                        There have been a number of 'fixes' to DIALOG NEW PIXELS in the last few releases -
                        That may be true, but... any number of postings here about problems 'showing' a dialog at the correct time at the correct size in the correct location have involved trying to use the WinAPI calls (MoveWindow/SetWindowPos + ShowWindow) instead of the DDT DIALOG SET SIZE|LOC + DIALOG SHOW STATE statements.

                        i.e., mix and match code styles can be fraught with traps.

                        Not a factor in this case 'as far as posted code would indicate,' but nonetheless something of which one should be aware.
                        Michael Mattias
                        Tal Systems Inc. (retired)
                        Racine WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          David and Michael,

                          Thanks for your responses as well. I have my app functioning now, and the fix prescribed first by Kev did works fine.

                          I should probably sign off and leave it alone, but part of me wants to know if there is a logical cause for the apparent aberrant behavior of the DIALOG NEW PIXELS -- meaning that the results could logically be expected, or if it's something that the PB staff would rather it *not* do -- read "bug."

                          Anyway, thanks again for the comments and responses!

                          Ken
                          Ken S. Elvehjem
                          [email protected]

                          Comment


                          • #14
                            sorry, button got whacked twice...
                            Ken S. Elvehjem
                            [email protected]

                            Comment


                            • #15
                              If you suspect a bug, you have to mail it in to [email protected]

                              Include compilable (or not compilable if that is the problem) source code demonstrating the problem, and make sure you include compiler name and version(s) used. Best, too, if you include in your attached file(s) all header ("#INCLUDE") files used, with your source code set up so there are no relative or named paths in your #INCLUDE statements. (So support personnel can 'unzip' into a clean folder and compile from there).

                              Just think about what you'd like your users to do when they claim there is a problem with your program... the PB Support people want exactly the same things -primarily, the ability to easily "make it happen here. "

                              Note the Peer Support Forum is NOT an approved venue for such reports.

                              MCM
                              Michael Mattias
                              Tal Systems Inc. (retired)
                              Racine WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                              • #16
                                Point taken, Michael.

                                Have sent a report complete with a link to this thread, which, I think, contains all the relevant code.

                                Ken
                                Ken S. Elvehjem
                                [email protected]

                                Comment


                                • #17
                                  I think the easiest thing to do would be to remove the %WS_MAXIMIZE style from the dialog and issue a DIALOG SHOW STATE CBHNDL, %SW_MAXIMIZE in the %WM_INITDIALOG handler. Or keep the %WS_MAXIMIZE style and issue a DIALOG SET LOC CBHNDL, 0, 0 in the %WM_INITDIALOG handler.
                                  Sincerely,

                                  Steve Rossell
                                  PowerBASIC Staff

                                  Comment

                                  Working...
                                  X