Bring (hidden) window to front when clicking systray icon
Bring (hidden) window to front when clicking systray icon
It's a bit unfair. Some apps (for example Teams) move / reopen their window and give it focus when clicking on their systray icon.
I searched the forum, but haven't found a suitable solution yet. Does anyone have a suggestion how to accomplish this?
I searched the forum, but haven't found a suitable solution yet. Does anyone have a suggestion how to accomplish this?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Bring (hidden) window to front when clicking systray icon
maybe
Code: Select all
SetActiveWindow(#Window)
Re: Bring (hidden) window to front when clicking systray icon
Tried it, doesn't work. It seems that the click on the icon, in spite of the event arriving, doesn't shift focus.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Bring (hidden) window to front when clicking systray icon
Try this:
Code: Select all
ShowWindow_(HWnd,#SW_RESTORE)
Re: Bring (hidden) window to front when clicking systray icon
Code: Select all
SendMessage_(#HWND_BROADCAST, #WM_SYSCOMMAND, #SC_HOTKEY, hWnd)
Egypt my love
Re: Bring (hidden) window to front when clicking systray icon
Hmm... this did it. Weird. I have to puzzle out why...
Thx anyway!
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Bring (hidden) window to front when clicking systray icon
And this one works as well, okay, now I have two ways Thx!RASHAD wrote: ↑Fri Sep 17, 2021 9:36 pmCode: Select all
SendMessage_(#HWND_BROADCAST, #WM_SYSCOMMAND, #SC_HOTKEY, hWnd)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Bring (hidden) window to front when clicking systray icon
MSDN: https://docs.microsoft.com/en-us/window ... oundwindow
Example (Update)
Code: Select all
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Macro SetActiveWindow(Window)
SetForegroundWindow_(WindowID(Window))
EndMacro
CompilerEndIf
Code: Select all
;-TOP
EnableExplicit
;- Constant
Enumeration Windows
#Main
EndEnumeration
Enumeration Menus
#Menu
EndEnumeration
Enumeration MenuItems
#MenuExitApplication
EndEnumeration
Enumeration Gadgets
#List
EndEnumeration
Enumeration Statusbar
#Status
EndEnumeration
Enumeration Images
#SystrayImage
EndEnumeration
;- Global Variable
Global ExitApplication
;- Functions
Procedure UpdateWindow()
Protected x, y, dx, dy, menu, status
menu = MenuHeight()
If IsStatusBar(#Status)
status = StatusBarHeight(#Status)
Else
status = 0
EndIf
x = 0
y = 0
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - menu - status
ResizeGadget(#List, x, y, dx, dy)
EndProcedure
Procedure InitSysTray()
CreateImage(#SystrayImage, 16, 16, 32, #Red)
AddSysTrayIcon(0, WindowID(#Main), ImageID(#SystrayImage))
EndProcedure
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Macro SetActiveWindow(Window)
SetForegroundWindow_(WindowID(Window))
EndMacro
CompilerEndIf
;- Main
Procedure Main()
Protected event, dx, dy
#WinStyle = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
dx = 800
dy = 600
If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, dx, dy, "Main Window", #WinStyle)
; Menu
CreateMenu(#Menu, WindowID(#Main))
MenuTitle("File")
MenuItem(#MenuExitApplication, "E&xit")
; Gadgets
ListViewGadget(#List, 0, 0, dx, dy)
; Statusbar
CreateStatusBar(#Status, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
; Systray
InitSysTray()
; Init
UpdateWindow()
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
; Main Loop
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Menu
Select EventMenu()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Case #PB_Menu_About
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
ExitApplication = #True
CompilerEndIf
Case #MenuExitApplication
ExitApplication = #True
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #List
EndSelect
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Main
ExitApplication = #True
EndSelect
Case #PB_Event_MinimizeWindow
SetWindowState(#Main, #PB_Window_Minimize)
HideWindow(#Main, #True)
Case #PB_Event_SysTray
HideWindow(#Main, #False)
SetWindowState(#Main, #PB_Window_Normal)
SetActiveWindow(#Main)
EndSelect
Until ExitApplication
EndIf
EndProcedure : Main()
End
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Bring (hidden) window to front when clicking systray icon
Nope, setforegroundwindow_ didn't to the job. It was one of the things I already tried. I don't know why...mk-soft wrote: ↑Sat Sep 18, 2021 10:16 am MSDN: https://docs.microsoft.com/en-us/window ... oundwindow
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Bring (hidden) window to front when clicking systray icon
Doesn't my example work?
I can hide the window with "Minimise" and also hide the window behind another window.
I can hide the window with "Minimise" and also hide the window behind another window.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Bring (hidden) window to front when clicking systray icon
It does sometimes, but not always. The 'sendmessage' did it. I changed it to 'postmessage' and now it skips the 'hickups' as well.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )