Page 1 of 1
How to set whole program acive
Posted: Tue Oct 08, 2013 1:45 pm
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
Re: How to set whole program acive
Posted: Tue Oct 08, 2013 2:29 pm
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.
Re: How to set whole program acive
Posted: Tue Oct 08, 2013 4:22 pm
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.
Re: How to set whole program acive
Posted: Tue Oct 08, 2013 8:38 pm
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.
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).
Re: How to set whole program acive
Posted: Wed Oct 09, 2013 6:04 am
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
Re: How to set whole program acive
Posted: Sat Oct 26, 2013 2:45 pm
by karu
Thanks
Re: How to set whole program acive
Posted: Sat Oct 26, 2013 3:18 pm
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() .
Re: How to set whole program active
Posted: Wed Dec 04, 2013 7:41 pm
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
Re: How to set whole program acive
Posted: Wed Dec 04, 2013 8:20 pm
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
Re: How to set whole program acive
Posted: Wed Dec 04, 2013 8:35 pm
by charvista
Superb!
You are really good in API coding, RASHAD
Perhaps I will sleep sooner tonight
Happy coding!