Announcement

Collapse
No announcement yet.

ws_topmost, BringWindowToTop, F4 closing wrong dialog

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

  • ws_topmost, BringWindowToTop, F4 closing wrong dialog

    Attempting to preserve the z-relationship between two dialogs, so that the popup one always appears to overlay the other.

    Although this arrangement works, pressing F4 after task-switching closes the wrong dialog - ie, not the top one!

    Would someone care to spot my mistake?

    Code:
    ' F4 problem
    ' in this example, after task-switching away from
    ' then back to the "popup" dialog, F4 appears to close the "wrong"
    ' dialog - i.e., not the top one.
    ' Possibly a consequence of using BringWindowtoTop,
    ' which is used to preserve the z-relationship between
    ' the "main" and "popup" dialogs, but how to correct it?
    '
    ' Chris Holbrook 21st Jan 2009
    '
    #compile exe
    #dim all
    #include "win32api.inc"
    '------------------------------------------------------------------
    callback function CBPopup
        static hMain as dword
        local n as long
    
        select case as long cb.msg
            case %wm_initdialog
                'BringWindowToTop(hMain)
    
            case %wm_user + 400
                hMain = cb.wparam
                enablewindow hMain, %false
    
            case %wm_destroy
                enablewindow hMain, %true
                BringWindowToTop(hMain)
                setfocus (hMain)
    
            case %wm_syscommand
                'n = cb.wparam and &HFFF0
                'dialog set text cb.hndl, "sys " + hex$(n)
                'sleep 500
    
            case %wm_ncactivate
                'dialog set text cb.hndl, "NCA " + hex$(cb.wparam)
                'sleep 500
                if cb.wparam = %false then exit select ' we are losing focus
                enablewindow hMain, %true
                BringWindowToTop(hMain)
                enablewindow hMain, %false
                setfocus (cb.hndl)
        end select
    end function
    
    '------------------------------------------------------------------
    callback function CB1
        static hpopup, hDmain as dword
        local lresult, W, H as long
    
        select case as long cb.msg
            case %wm_command
                if cb.ctl = 1001 then
                    if hpopup <> 0 then exit select ' child window already exists
                    dialog new 0, "popup", 110, 110, 80, 80, _
                           %ws_popup or %ws_caption, %ws_ex_topmost to hpopup
                    dialog show modeless hpopup call CBpopup to lresult
                    dialog send hpopup, %wm_user + 400, cb.hndl, 0
                    do
                        dialog doevents
                        dialog get size hpopup to H, W
                    loop while H
                    hPopup = 0
                end if
        end select
    end function
    '------------------------------------------------------------------
    function pbmain () as long
        local lresult as long
        local hdlg as long
    
        dialog new 0, "main", 100, 100, 100, 100, _
               %ws_visible or %ws_popup or %ws_caption, to hDlg
        control add label, hDlg, 1001, "click here for popup dialog", 5, 90, 90, 15,  %ss_notify
        control set color hDlg, 1001, %white, %gray
        dialog show modal hDlg call CB1 to lresult
    
    end function

  • #2
    <Alt>-<F4> trapped in parent ...

    Code:
    '------------------------------------------------------------------
    callback function CB1
        static hpopup, hDmain as dword
        local lresult, W, H as long
    
        select case as long cb.msg
            case %wm_command
                if cb.ctl = 1001 then
                    
                    '----- Alter this line
                    'if hpopup <> 0 then exit select ' child window already exists
                    
                    '----- To read ...
                    If IsWindow(hpopup) then exit select
    
                    dialog new 0, "popup", 110, 110, 80, 80, _
                           %ws_popup or %ws_caption, %ws_ex_topmost to hpopup
                    dialog show modeless hpopup call CBpopup to lresult
                    dialog send hpopup, %wm_user + 400, cb.hndl, 0
                    
                    '----- Is this really necessary?
                    'do
                    '    dialog doevents
                    '    dialog get size hpopup to H, W
                    'loop while H
                    'hPopup = 0
    
                end if
             
             '----- You could add this too ...
             Case %wm_syscommand
                If IsWindow(hpopup) then
                    Msgbox "We are here"
                    Dialog End hpopup
                    Function=1
                End If 
        end select
    end function

    Comment


    • #3
      Originally posted by John Reinking View Post
      <Alt>-<F4> trapped in parent ...
      John, thanks for responding, the changes which you suggest, however, do not change the behaviour.

      It looks as if having sent the Bringwindowtotop to the "main" dialog, then even though the "popup" is still topmost, the "main" gets the F4. So before task switching, the popup is killed by F4, after task switching away then back to the popup, it is the "main" which is killed by F4.

      Comment


      • #4
        Originally posted by SDK
        Remarks

        Use the BringWindowToTop function to uncover any window that is partially or completely obscured by other windows.

        Calling this function is similar to calling the SetWindowPos function to change a window's position in the Z order. BringWindowToTop does not make a window a top-level window.
        So maybe try using the SetWindowPos to make a Z order adjustment when either form recognizes that it's got the focus back from ALT+F4?
        Furcadia, an interesting online MMORPG in which you can create and program your own content.

        Comment


        • #5
          Originally posted by colin glenn View Post
          SetWindowPos...
          has a lucky aura. I shall try it.

          Comment


          • #6
            SetWindowPos is exactly what is needed.

            Code:
            ' F4 problem solved by using SetWindowPos to place the
            ' dialogs in the correct z-relationship  - Thank you Colin Glenn!
            '
            ' Chris Holbrook 21st Jan 2009
            '
            #compile exe
            #dim all
            #include "win32api.inc"
            '------------------------------------------------------------------
            callback function CBPopup
                static hMain as dword
                local n as long
            
                select case as long cb.msg
                    case %wm_user + 400
                        hMain = cb.wparam
                        enablewindow hMain, %false
            
                    case %wm_destroy
                        enablewindow hMain, %true
                        BringWindowToTop(hMain)
                        setfocus (hMain)
            
                    case %wm_ncactivate
                        if cb.wparam = %false then exit select ' we are losing focus
                        enablewindow hMain, %true
                        setwindowpos(hMain, cb.hndl, 0, 0, 0, 0, %SWP_NOACTIVATE or %SWP_NOMOVE or %SWP_NOSIZE)
                        enablewindow hMain, %false
                        setfocus (cb.hndl)
                end select
            end function
            
            '------------------------------------------------------------------
            callback function CB1
                static hpopup, hDmain as dword
                local lresult, W, H as long
            
                select case as long cb.msg
                     case %wm_syscommand
                         
                         if IsWindow(hpopup) then
                             msgbox "We are here"
                             dialog end hpopup
                             function=1
                         end if
                        
                    case %wm_command
                        if cb.ctl = 1001 then
                            if iswindow(hpopup) then exit select ' child window already exists
                            dialog new 0, "popup", 110, 110, 80, 80, _
                                   %ws_popup or %ws_caption, %ws_ex_topmost to hpopup
                            dialog show modeless hpopup call CBpopup to lresult
                            dialog send hpopup, %wm_user + 400, cb.hndl, 0
                        end if
                end select
            end function
            '------------------------------------------------------------------
            function pbmain () as long
                local lresult as long
                local hdlg as long
            
                dialog new 0, "main", 100, 100, 100, 100, _
                       %ws_visible or %ws_popup or %ws_caption, to hDlg
                control add label, hDlg, 1001, "click here for popup dialog", 5, 90, 90, 15,  %ss_notify
                control set color hDlg, 1001, %white, %gray
                dialog show modal hDlg call CB1 to lresult
            
            end function

            Comment

            Working...
            X