Announcement

Collapse
No announcement yet.

Focus Outside Dialog after restore???

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

  • Alexander Holzer
    replied
    Originally posted by Simon Morgan View Post
    Change:
    Code:
    ShowDIALOG2 %HWND_DESKTOP
    to
    Code:
    ShowDIALOG2 CBHNDL
    so that Dialog2 is a child of Dialog1 (and not of the Desktop).
    It is exactly!
    Thank you!


    @StanHelton
    It goes also, if this init routine (CALLBACK) begun...
    thanks
    Last edited by Alexander Holzer; 31 Mar 2008, 07:33 AM.

    Leave a comment:


  • StanHelton
    replied
    After I posted this I saw Simon's post. His solution is more elegant and probably has less overhead. I'd would use his solution.

    Originally posted by Alexander Holzer View Post
    I have a problem:
    - after restore focus is lost

    Dialog2 should disable dialod1 during showing...
    Where is the mistake? Help please.
    for example

    I would try this (added code marked *** in comment line:
    Code:
    CALLBACK FUNCTION ShowDIALOG1Proc()
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                ' 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
                        ShowDIALOG2 %HWND_DESKTOP
    
                        're-enable Dialog1 when Dialog2 closes     ***
                        DIALOG ENABLE Dialog1                         '***
    
                END SELECT
        END SELECT
    END FUNCTION
    
    CALLBACK FUNCTION ShowDIALOG2Proc()
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                ' Initialization handler
    
                'disable the Dialog1 when Dialog2 starts ***
                DIALOG DISABLE Dialog1                     '***
    
            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_BUTTON2
                        DIALOG END CBHNDL, 0
    
                END SELECT
        END SELECT
    END FUNCTION
    This way Dialog2 disables Dialog1 whenever it starts and Dialog1 re-enables itself when Dialog2 ends.

    This may look like a recursive call and it sort-of is, but because your CALLBACK doesn't handle the %WM_ENABLE message the Windows system handles if for you.

    Hope this takes care of it for you.
    Stan
    Last edited by StanHelton; 31 Mar 2008, 06:47 AM. Reason: take account of a better solution by Simon Morgan

    Leave a comment:


  • Simon Morgan
    replied
    Change:
    Code:
    ShowDIALOG2 %HWND_DESKTOP
    to
    Code:
    ShowDIALOG2 CBHNDL
    so that Dialog2 is a child of Dialog1 (and not of the Desktop).

    Leave a comment:


  • Alexander Holzer
    started a topic Focus Outside Dialog after restore???

    Focus Outside Dialog after restore???

    I have a problem:
    - after restore focus is lost

    Dialog2 should disable dialod1 during showing...
    Where is the mistake? Help please.
    for example
    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
    %IDD_DIALOG2 =  102
    %IDC_BUTTON2 = 1002
    #PBFORMS END CONSTANTS
    '------------------------------------------------------------------------------------------------------------------------------
    
    GLOBAL hDlgShow1 AS DWORD
    GLOBAL hDlgShow2 AS DWORD
    
    '------------------------------------------------------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE CALLBACK FUNCTION ShowDIALOG2Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    DECLARE FUNCTION ShowDIALOG2(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    '------------------------------------------------------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                ' 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
                        ShowDIALOG2 %HWND_DESKTOP
    
                END SELECT
        END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG2Proc()
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                ' 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_BUTTON2
                        DIALOG END CBHNDL, 0
    
                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 hParent, "Dialog1", 246, 167, 400, 200, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU _
            OR %WS_MINIMIZEBOX OR %WS_VISIBLE OR %DS_CENTER 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, "Dialog1", 120, 84, 56, 16
    #PBFORMS END DIALOG
    
        hDlgShow1 = hDlg
    
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
    #PBFORMS END CLEANUP
    
        FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------------------------------------------------------
    FUNCTION ShowDIALOG2(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt AS LONG
    
    #PBFORMS BEGIN DIALOG %IDD_DIALOG2->->
        LOCAL hDlg  AS DWORD
    
        DIALOG NEW hParent, "Dialog2", 259, 183, 201, 121, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU _
            OR %WS_VISIBLE OR %DS_CENTER 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_BUTTON2, "Close", 124, 88, 56, 16
    #PBFORMS END DIALOG
    
        hDlgShow2 = hDlg
        
        DIALOG DISABLE hDlgShow1
    
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG2Proc TO lRslt
    
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG2
    #PBFORMS END CLEANUP
    
        DIALOG ENABLE hDlgShow1
        DIALOG SHOW STATE hDlgShow1, %SW_SHOWNORMAL
    
        FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------------------------------------------------------
    Thanks
Working...
X