How to set whole program acive

Just starting out? Need help? Post your questions and find answers here.
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

How to set whole program acive

Post by karu »

I need to set whole my program active but not with SetActiveWindow() because SetActiveWindow() change also what windows is active in my program, but how?

Thanks
Karu
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: How to set whole program acive

Post by IdeasVacuum »

Do you mean all the windows of your app 'working as one'? If so, the easiest approach is to have them all in your main loop, instead of each having it's own individual loop. You can use Select EventWindow(), with each case being a #Window, so that if the Event is, say, #PB_Event_CloseWindow, you Close/Hide the correct one.

Another approach is to have an MDI window - one parent window hosts all the others. That is/was supported by PB but I couldn't find it in the help just now.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

Re: How to set whole program acive

Post by karu »

No, you didn't understand. Example, i have running my prog with many open windows, now if i switch to another prog, my prog will bi inactive. Now how i can set my whole prog active without pointing to any window.
User avatar
Demivec
Addict
Addict
Posts: 4261
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: How to set whole program acive

Post by Demivec »

karu wrote:No, you didn't understand. Example, i have running my prog with many open windows, now if i switch to another prog, my prog will bi inactive. Now how i can set my whole prog active without pointing to any window.
That's called multi-tasking. :mrgreen:


What do you mean by inactive?

If you mean it doesn't receive input from the mouse or keyboard then you would have to make one of your windows active again so that it can process input events. You might also use a hook of some sort to receive things such as keyboard events when another application is active.

If you mean your windows aren't on top then you can make a window 'Sticky' using StickyWindow(). You can do this with all of your windows if you want and they will all stay on top (though they may hide another application's windows if it becomes active instead).
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How to set whole program acive

Post by netmaestro »

You can try this idea, see if anything looks like what you are going for:
To test:
1) paste the first code snippet into an empty tab in the IDE.
2) Paste the second code snippet into a new tab in the IDE.
3) Run the first code, the windows will show.
4) Click the tab with the second snippet, the windows will dive down to the taskbar.
5) Run the second code, the windows *should* reappear.

Code: Select all

; First Snippet

Structure windowstate
  window.i
  visible.i
  focused.i
EndStructure

Global NewList windowstates.windowstate()

Procedure WinProc(hwnd, msg, wparam, lparam)
  result=#PB_ProcessPureBasicEvents
  
  Select msg
    Case #WM_SYSCOMMAND
      If wparam = #SC_HOTKEY
        
        ForEach windowstates()
          If windowstates()\visible
            SetWindowPos_(WindowID(windowstates()\window), #HWND_TOPMOST, 0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE|#SWP_SHOWWINDOW)
          EndIf
          If windowstates()\focused
            SetActiveWindow(windowstates()\window)
          EndIf
        Next
        result=0
      EndIf
      
  EndSelect
  
  ProcedureReturn result
  
EndProcedure

OpenWindow(0,40,200,320,240,"thistest")
SetWindowCallback(@WinProc())
AddElement(windowstates())
With windowstates()
  \window = 0
  \visible = 1
  \focused = 0
EndWith

OpenWindow(1,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
AddElement(windowstates())
With windowstates()
  \window = 1
  \visible = 1
  \focused = 1
EndWith
StringGadget(0,10,10,200,20,"")
SetActiveGadget(0)

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

Code: Select all

; Second snippet

this = FindWindow_(0, "thistest")
If this
  SendMessage_(this, #WM_SYSCOMMAND, #SC_HOTKEY, 0)
Else
  Debug "Window not found"
EndIf
BERESHEIT
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

Re: How to set whole program acive

Post by karu »

Thanks
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: How to set whole program acive

Post by PB »

> Another approach is to have an MDI window - one parent window hosts all the others.
> That is/was supported by PB but I couldn't find it in the help just now.

It's an MDIGadget() .
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: How to set whole program active

Post by charvista »

This is my problem as well.
I must miss something, but I don't see what.
When the program runs, click outside of the window, you will hear intermittent beeps, instead of only once, because the window do not want to be active again.
The window is made visible again, but not focused again.

Code: Select all

Structure windowstate
    window.i
    visible.i
    focused.i
EndStructure

Global NewList windowstates.windowstate()

Procedure WinProc(hwnd, msg, wparam, lparam)
    result=#PB_ProcessPureBasicEvents
    Select msg
    Case #WM_SYSCOMMAND
        If wparam = #SC_HOTKEY
            ForEach windowstates()
                If windowstates()\visible
                    Debug "made visible again"
                    SetWindowPos_(WindowID(windowstates()\window), #HWND_TOPMOST, 0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE|#SWP_SHOWWINDOW)
                EndIf
                If windowstates()\focused
                    Debug "made focused again"
                    SetActiveWindow(windowstates()\window)
                EndIf
            Next
            result=0
        EndIf
    EndSelect
    ProcedureReturn result
EndProcedure

Enumeration
    #ZWin
    #ZG1
    #ZG2
    #ZG3
    #ZG4
    #ZG5
    #ZG6
EndEnumeration


OpenWindow(#ZWin,300,250,400,200,"Sticky Window Problem",#PB_Window_SystemMenu)
SetWindowCallback(@WinProc())
AddElement(windowstates())
With windowstates()
    \window  = #ZWin
    \visible = 1
    \focused = 1
EndWith
StickyWindow(#ZWin,#True); make it top window

ButtonGadget(#ZG1,50,50,60,25,Str(#ZG1))
ButtonGadget(#ZG2,150,50,60,25,Str(#ZG2))
ButtonGadget(#ZG3,250,50,60,25,Str(#ZG3))
StringGadget(#ZG4,50,100,260,21,Str(#ZG4))
CheckBoxGadget(#ZG5,50,130,260,21,Str(#ZG5))
TextGadget(#ZG6,50,170,350,20,"")

Ag=#ZG1
SetActiveGadget(Ag)
SetGadgetText(#ZG6,"Current active gadget: "+Str(Ag))



Repeat
    If GetActiveWindow()=#ZWin And GetActiveGadget()<>Ag
        Ag=GetActiveGadget()
        SetGadgetText(#ZG6,"Current active gadget: "+Str(Ag))
    EndIf
    
    If GetActiveWindow()<>#ZWin
        Beep_(600,150)
        This=FindWindow_(0,"Sticky Window Problem")
        Debug This
        If This
            SendMessage_(This,#WM_SYSCOMMAND,#SC_HOTKEY,0)
        EndIf
        
        
        ;SetFocus_(WindowID(#ZWin))
        ;SetActiveWindow(#ZWin)
        ;SetActiveGadget(Ag)
    EndIf
    
    Event=WaitWindowEvent(70)
    Select Event
        
    Case #PB_Event_CloseWindow
        ExitEventLoop=#True
        
        ;     Case #PB_Event_Gadget
        ;         Gadget=EventGadget()      
        ;         EvType=EventType()
        ;         Debug Str(Gadget)+"    "+Str(EvType)
        
        
    EndSelect
Until ExitEventLoop
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4948
Joined: Sun Apr 12, 2009 6:27 am

Re: How to set whole program acive

Post by RASHAD »

Maybe like this :)

Code: Select all

Structure windowstate
    window.i
    visible.i
    focused.i
EndStructure

Global NewList windowstates.windowstate()

Procedure WinProc(hwnd, msg, wparam, lparam)
    result=#PB_ProcessPureBasicEvents
    Select msg
    Case #WM_SYSCOMMAND
        If wparam = #SC_HOTKEY
            ForEach windowstates()
                If windowstates()\visible
                    Debug "made visible again"
                    SetWindowPos_(WindowID(windowstates()\window), #HWND_TOPMOST, 0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE|#SWP_SHOWWINDOW)
                EndIf
                If windowstates()\focused
                    Debug "made focused again"
                    SetActiveWindow(windowstates()\window)
                EndIf
            Next
            result=0
        EndIf
    EndSelect
    ProcedureReturn result
EndProcedure

Enumeration
    #ZWin
    #ZG1
    #ZG2
    #ZG3
    #ZG4
    #ZG5
    #ZG6
EndEnumeration


OpenWindow(#ZWin,300,250,400,200,"Sticky Window Problem",#PB_Window_SystemMenu)
SetWindowCallback(@WinProc())
AddElement(windowstates())
With windowstates()
    \window  = #ZWin
    \visible = 1
    \focused = 1
EndWith
StickyWindow(#ZWin,#True); make it top window

ButtonGadget(#ZG1,50,50,60,25,Str(#ZG1))
ButtonGadget(#ZG2,150,50,60,25,Str(#ZG2))
ButtonGadget(#ZG3,250,50,60,25,Str(#ZG3))
StringGadget(#ZG4,50,100,260,21,Str(#ZG4))
CheckBoxGadget(#ZG5,50,130,260,21,Str(#ZG5))
TextGadget(#ZG6,50,170,350,20,"")

Ag=#ZG1
SetActiveGadget(Ag)
SetGadgetText(#ZG6,"Current active gadget: "+Str(Ag))



Repeat
    If GetActiveWindow()=#ZWin And GetActiveGadget()<>Ag
        Ag=GetActiveGadget()
        SetGadgetText(#ZG6,"Current active gadget: "+Str(Ag))
    EndIf
   
    If GetActiveWindow()<>#ZWin
        Beep_(600,150)
        This=FindWindow_(0,"Sticky Window Problem")
        Debug This
        If This
            SendMessage_(#HWND_BROADCAST, #WM_SYSCOMMAND, #SC_HOTKEY, This)
        EndIf
       
       
        ;SetFocus_(WindowID(#ZWin))
        ;SetActiveWindow(#ZWin)
        ;SetActiveGadget(Ag)
    EndIf
   
    Event=WaitWindowEvent(70)
    Select Event
       
    Case #PB_Event_CloseWindow
        ExitEventLoop=#True
       
        ;     Case #PB_Event_Gadget
        ;         Gadget=EventGadget()     
        ;         EvType=EventType()
        ;         Debug Str(Gadget)+"    "+Str(EvType)
       
       
    EndSelect
Until ExitEventLoop
Egypt my love
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: How to set whole program acive

Post by charvista »

Superb! :D
You are really good in API coding, RASHAD :D

Perhaps I will sleep sooner tonight :mrgreen:

Happy coding!
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Post Reply