I’m using the RegisterHotKey API call to be notified when a specific shortcut is pressed. Up to now, I was using a dummy window, always hidden, to process the callback, like this:
#if TargetWindows then dim p As Ptr=AddressOf WindowProc //WindowProc: a method with these parameters: hWnd As Integer,uMsg As Integer,wParam As Integer,lParam As Integer Declare Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongW" _ (ByVal hWnd as int32,ByVal nIndex as Int32, ByVal dwNewLong as Ptr) as Int32 lpPrevWndProc=SetWindowLongPtr(WinHandle,-4,p) #endif
In the WindowProc method, I check if the message is about the shortcut key (and handle it). If not, it’s passed back to the OS using:
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Integer, ByVal hWnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lparam As Integer) As Integer Return CallWindowProc(lpPrevWndProc,hWnd,uMsg,wParam,lparam)
This worked fine, but I’d now like to use the same technique in a console app, so without a valid window’s handle.
The documentation about the RegisterHotKey API says this about the 1st parameter (the hwnd parameter):
If this parameter is NULL , WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop.
I presume the “calling thread” is Xojo’s main thread, the one handling the UI. Xojo doesn’t provide the handle of a thread (I’m assuming ThreadID is an internal Xojo property, not the system handle), so I bet I’d lose my time in searching for an API to obtain the thread’s messages.
Is there a way I’m not seeing to monitor the message loop of a Xojo thread?