Hiding an inactive modal window

Just starting out? Need help? Post your questions and find answers here.
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Hiding an inactive modal window

Post 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
Last edited by mestnyi on Sun Sep 22, 2024 8:41 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Hiding an inactive window

Post 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
Last edited by infratec on Sun Sep 22, 2024 8:44 pm, edited 1 time in total.
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Re: Hiding an inactive window

Post 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
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Hiding an inactive window

Post 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
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Re: Hiding an inactive window

Post 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
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Hiding an inactive modal window

Post 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.
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Hiding an inactive window

Post by boddhi »

mestnyi wrote: There is no typo here.
:oops: I misunderstood the meaning of your message. :) :wink:
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Re: Hiding an inactive window

Post 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?
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Re: Hiding an inactive modal window

Post by mestnyi »

Can someone check this is a bug in purebasic or winapi?
User avatar
TI-994A
Addict
Addict
Posts: 2751
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Hiding an inactive modal window

Post 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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Re: Hiding an inactive modal window

Post by mestnyi »

Thank you very much.
Post Reply