As far as I know, there is no such event.
Instead, how about this way?
Edit: a bug fixed.
Code: Select all
; Inspired by:
; Simple transparent sticky reminder message by OgreVorbis
; https://www.purebasic.fr/english/viewtopic.php?p=578302
EnableExplicit
Enumeration
#MainWindow
#DummyWindow
#InfoWindow
EndEnumeration
#ColorKey= $FFFFFF
Define TheMessage.s
Define Event.i
Procedure MoveText()
ResizeWindow(#InfoWindow, WindowX(#MainWindow)+8, WindowY(#MainWindow)+28, #PB_Ignore, #PB_Ignore)
;added lines
SetWindowPos_(WindowID(#InfoWindow), #HWND_TOP, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE | #SWP_FRAMECHANGED | #SWP_NOACTIVATE)
SetWindowPos_(WindowID(#MainWindow), WindowID(#InfoWindow), 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE | #SWP_FRAMECHANGED)
EndProcedure
Procedure InfoKeyHandler()
Static WindowState=0
WindowState=1-WindowState
HideWindow(#InfoWindow, WindowState)
SetActiveWindow(#MainWindow)
EndProcedure
Procedure MyWindowCallback(WindowID, Message, WParam, LParam)
Protected Result = #PB_ProcessPureBasicEvents
If Message = #WM_ACTIVATE Or Message = #WM_MOVE ;Or Message = #WM_SETCURSOR Or Message = #WM_ACTIVATEAPP
MoveText()
EndIf
If Message = #WM_WINDOWPOSCHANGED
SetWindowPos_(WindowID(#InfoWindow), #HWND_TOP, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE | #SWP_FRAMECHANGED | #SWP_NOACTIVATE)
EndIf
ProcedureReturn Result
EndProcedure
OpenWindow(#MainWindow, 10, 10, 120, 120,"")
OpenWindow(#DummyWindow, 0, 0, 1,1, "Dummy", #PB_Window_Invisible)
OpenWindow(#InfoWindow, 0, 0, 128, 32, "Info", #PB_Window_BorderLess | #PB_Window_ScreenCentered, WindowID(#DummyWindow))
SetWindowColor(#DummyWindow, #colorkey)
SetWindowColor(#InfoWindow, #colorkey)
SetWindowLong_(WindowID(#InfoWindow), #GWL_EXSTYLE, #WS_EX_LAYERED) ;unnecessary #WS_EX_TOPMOST
SetLayeredWindowAttributes_(WindowID(#InfoWindow), #colorkey, 100, #LWA_COLORKEY)
;StickyWindow(#InfoWindow, #True) ;remove
TheMessage = "Scale 4:1"
TextGadget(0, 0, 0, 80, 20, TheMessage)
SetGadgetColor(0, #PB_Gadget_FrontColor, #Red)
SetGadgetColor(0, #PB_Gadget_BackColor, #colorkey)
MoveText()
;BindEvent(#PB_Event_MoveWindow, @MoveText()) ;remove
SetWindowCallback(@MyWindowCallback(), #MainWindow) ;added line
AddKeyboardShortcut(#MainWindow, #PB_Shortcut_Space, 1)
InfoKeyHandler()
BindEvent(#PB_Event_Menu, @infoKeyHandler())
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
Old version.
Code: Select all
; Inspired by:
; Simple transparent sticky reminder message by OgreVorbis
; https://www.purebasic.fr/english/viewtopic.php?p=578302
EnableExplicit
Enumeration
#MainWindow
#DummyWindow
#InfoWindow
EndEnumeration
#ColorKey= $FFFFFF
Define TheMessage.s
Define Event.i
Procedure MoveText()
ResizeWindow(#InfoWindow, WindowX(#MainWindow)+8, WindowY(#MainWindow)+28, #PB_Ignore, #PB_Ignore)
;added lines.
SetWindowPos_(WindowID(#InfoWindow), #HWND_TOP, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE | #SWP_FRAMECHANGED | #SWP_NOACTIVATE)
SetWindowPos_(WindowID(#MainWindow), WindowID(#InfoWindow), 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE | #SWP_FRAMECHANGED)
EndProcedure
Procedure InfoKeyHandler()
Static WindowState=0
WindowState=1-WindowState
HideWindow(#InfoWindow, WindowState)
SetActiveWindow(#MainWindow)
EndProcedure
OpenWindow(#MainWindow, 10, 10, 120, 120,"")
OpenWindow(#DummyWindow, 0, 0, 1,1, "Dummy", #PB_Window_Invisible)
OpenWindow(#InfoWindow, 0, 0, 128, 32, "Info", #PB_Window_BorderLess | #PB_Window_ScreenCentered, WindowID(#DummyWindow))
SetWindowColor(#DummyWindow, #colorkey)
SetWindowColor(#InfoWindow, #colorkey)
SetWindowLong_(WindowID(#InfoWindow), #GWL_EXSTYLE, #WS_EX_LAYERED | #WS_EX_TOPMOST)
SetLayeredWindowAttributes_(WindowID(#InfoWindow), #colorkey, 100, #LWA_COLORKEY)
;StickyWindow(#InfoWindow, #True) ;remove
TheMessage = "Scale 4:1"
TextGadget(0, 0, 0, 80, 20, TheMessage)
SetGadgetColor(0, #PB_Gadget_FrontColor, #Red)
SetGadgetColor(0, #PB_Gadget_BackColor, #colorkey)
MoveText()
;BindEvent(#PB_Event_MoveWindow, @MoveText())
BindEvent(#PB_Event_MoveWindow, @MoveText(), #MainWindow) ;explicitly designating the target window
BindEvent(#PB_Event_ActivateWindow, @MoveText(), #MainWindow) ;added line
AddKeyboardShortcut(#MainWindow, #PB_Shortcut_Space, 1)
InfoKeyHandler()
BindEvent(#PB_Event_Menu, @infoKeyHandler())
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver