Page 1 of 1

Hiding an inactive modal window

Posted: Fri Sep 20, 2024 8:32 pm
by mestnyi
if the main window is activated, then hide the test window by hovering the mouse cursor over the canvas, after which the main window deactivation events will occur. (it's bad)

if the main window is activated, then show the test window by hovering the mouse cursor over the canvas, after which the main window deactivation events will not occur. (it's good)

why does this happen in the first case?
tested on the windows

Code: Select all

Global mainwin = 0
Global testwin 

If OpenWindow(mainwin, 0, 0, 600, 400, "Main Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   TextGadget(-1,5,50,40,24, "show")
   CanvasGadget(0,5,70,40,24)
   TextGadget(-1,50,50,40,24, "hide")
   CanvasGadget(1,50,70,40,24)
   
   OpenWindow(11,0,0,400,200,"11", #PB_Window_NoActivate|#PB_Window_WindowCentered | #PB_Window_Tool,WindowID(mainwin))
   mainwin = 11 ; comment/uncoment to see
   OpenWindow(12,0,0,200,100,"12", #PB_Window_NoActivate|#PB_Window_WindowCentered | #PB_Window_Tool,WindowID(mainwin))
   
   testwin = 12
   
   Repeat
      Select WaitWindowEvent()
         Case #PB_Event_CloseWindow
            Quit = 1
            
         Case #PB_Event_ActivateWindow
            Debug "active - "+EventWindow()
            
         Case #PB_Event_DeactivateWindow
            Debug "deactive - "+EventWindow()
            
         Case #PB_Event_Gadget
            Select EventGadget()          
               Case 0
                  HideWindow(testwin, 0, #PB_Window_NoActivate )
                  
               Case 1
                  HideWindow(testwin, 1, #PB_Window_NoActivate )
                  
                  
            EndSelect
      EndSelect
      
   Until Quit = 1
   
EndIf

Re: Hiding an inactive window

Posted: Fri Sep 20, 2024 9:45 pm
by infratec
With #PB_Window_NoActivate you get no event for activation :wink:
And HideWIndow() does not deactivate the window,

Try this code:

Code: Select all

Define Event.i


If OpenWindow(10, 0, 0, 600, 400, "Main Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  TextGadget(#PB_Any,5,50,40,24, "show")
  CanvasGadget(0,5,70,40,24)
  TextGadget(#PB_Any,50,50,40,24, "hide")
  CanvasGadget(1,50,70,40,24)
  
  OpenWindow(11,0,0,400,200,"11", #PB_Window_NoActivate|#PB_Window_WindowCentered | #PB_Window_Tool,WindowID(10))
  OpenWindow(12,0,0,200,100,"12", #PB_Window_NoActivate|#PB_Window_WindowCentered | #PB_Window_Tool,WindowID(10))
  
  SetActiveWindow(10)
  
  Repeat
    Event = WaitWindowEvent()
    Select EventWindow()
      Case 10
        Select Event
          Case #PB_Event_CloseWindow
            Quit = #True
            
          Case #PB_Event_ActivateWindow
            Debug "active - 10"
            
          Case #PB_Event_DeactivateWindow
            Debug "deactive - 10"
            
          Case #PB_Event_Gadget
            Select EventGadget()
              Case 0
                If EventType() = #PB_EventType_MouseEnter
                  HideWindow(12, #False, #PB_Window_NoActivate)
                EndIf
                
              Case 1
                If EventType() = #PB_EventType_MouseEnter
                  HideWindow(12, #True, #PB_Window_NoActivate)
                EndIf
                
                
            EndSelect
        EndSelect
        
      Case 11
        Select Event
          Case #PB_Event_ActivateWindow
            Debug "active - 11"
          Case #PB_Event_DeactivateWindow
            Debug "deactive - 11"
        EndSelect
        
      Case 12
        Select Event
          Case #PB_Event_ActivateWindow
            Debug "active - 12"
          Case #PB_Event_DeactivateWindow
            Debug "deactive - 12"
        EndSelect
        
    EndSelect
    
  Until Quit
  
EndIf

Re: Hiding an inactive window

Posted: Sat Sep 21, 2024 4:48 am
by mestnyi
Thank you for answering my question.
My problem is this.

Code: Select all

OpenWindow(11,...,WindowID(#mainwin))
  OpenWindow(12,...,WindowID(11))
  OpenWindow(13,...,WindowID(12))
  
There is no problem here.

Code: Select all

OpenWindow(11,...,WindowID(#mainwin))
  OpenWindow(12,...,WindowID(#mainwin))
  OpenWindow(13,...,WindowID(#mainwin))
  

my first example works fine on mac os just not on windows :x

Re: Hiding an inactive window

Posted: Sat Sep 21, 2024 8:16 am
by boddhi
Hello,

Typing error?

Code: Select all

Window(13,...,WindowID(12))
isn't the same than

Code: Select all

OpenWindow(13,...,WindowID(#mainwin))
On first line, WindowID of a modal window
On the 2nd line, WindowID on the main window

Re: Hiding an inactive window

Posted: Sun Sep 22, 2024 8:34 pm
by mestnyi

Code: Select all

OpenWindow(13,...,WindowID(12))
There is no typo here.
Here's what I want to say: when you need to create a modal window, the parent modal window does not work as expected

Re: Hiding an inactive modal window

Posted: Sun Sep 22, 2024 8:45 pm
by infratec
I changed my listing above.

I see only an activate - 10, which is Ok, since I used SetActiveWindow(10).
As I explained, this is what I expect.

Re: Hiding an inactive window

Posted: Sun Sep 22, 2024 9:32 pm
by boddhi
mestnyi wrote: There is no typo here.
:oops: I misunderstood the meaning of your message. :) :wink:

Re: Hiding an inactive window

Posted: Sun Sep 22, 2024 10:01 pm
by mestnyi
infratec wrote: Fri Sep 20, 2024 9:45 pm

Code: Select all

  OpenWindow(11,0,0,400,200,"11", #PB_Window_NoActivate|#PB_Window_WindowCentered | #PB_Window_Tool,WindowID(10))
  OpenWindow(12,0,0,200,100,"12", #PB_Window_NoActivate|#PB_Window_WindowCentered | #PB_Window_Tool,WindowID(11))
Why are you changing the ID of the last modal window to the ID of the main window? My question is, why doesn't it work the way it does? Then how does it work in other operating systems, maybe it's a bug after all?

Re: Hiding an inactive modal window

Posted: Fri Sep 27, 2024 5:20 pm
by mestnyi
Can someone check this is a bug in purebasic or winapi?

Re: Hiding an inactive modal window

Posted: Fri Sep 27, 2024 7:41 pm
by TI-994A
mestnyi wrote: Fri Sep 27, 2024 5:20 pm... this is a bug in purebasic or winapi?

When PureBasic's HideWindow() function is replaced with the WinAPI ShowWindow() function (line 33), the code works as expected.

Code: Select all

Global mainwin = 0
Global testwin 

If OpenWindow(mainwin, 0, 0, 600, 400, "Main Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  TextGadget(-1,5,50,40,24, "show")
  CanvasGadget(0,5,70,40,24)
  TextGadget(-1,50,50,40,24, "hide")
  CanvasGadget(1,50,70,40,24)
  
  OpenWindow(11,0,0,400,200,"11", #PB_Window_NoActivate|#PB_Window_WindowCentered | #PB_Window_Tool,WindowID(mainwin))
  mainwin = 11 ; comment/uncoment to see
  OpenWindow(12,0,0,200,100,"12", #PB_Window_NoActivate|#PB_Window_WindowCentered | #PB_Window_Tool,WindowID(mainwin))
  
  testwin = 12
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = 1
        
      Case #PB_Event_ActivateWindow
        Debug "active - "+EventWindow()
        
      Case #PB_Event_DeactivateWindow
        Debug "deactive - "+EventWindow()
        
      Case #PB_Event_Gadget
        Select EventGadget()          
          Case 0
            HideWindow(testwin, 0, #PB_Window_NoActivate )
            
          Case 1
            ;HideWindow(testwin, 1, #PB_Window_NoActivate )
            ShowWindow_(WindowID(testwin), #SW_HIDE)
            
        EndSelect
    EndSelect
    
  Until Quit = 1
  
EndIf
So, perhaps not a WinAPI issue. It's possible that PureBasic's HideWindow() function returns focus to the parent window when a child is hidden.

Re: Hiding an inactive modal window

Posted: Fri Sep 27, 2024 8:14 pm
by mestnyi
Thank you very much.