Page 1 of 1

[Solved] Need two events to always react

Posted: Wed Feb 15, 2017 11:05 am
by Dude
SOLVED - See next post. :D

I may have asked this before but I couldn't find it. :(

My app has a hotkey event and button event that BOTH need to be triggered at any time, no matter what the user is doing. My event loop currently looks like the below, but as you can see, as soon as something interrupts the loop (the ColorRequester) then the hotkey can't respond anymore.

I tried BindEvent(#WM_HOTKEY,@HotKeyEvent()) but #WM_HOTKEY isn't valid. :(

So what's the logical way to accomplish this goal? Thanks!

Code: Select all

Procedure HotKeyEvent()
  MessageRequester("Dammit","Now you can't click the ButtonGadget! :)")
EndProcedure

hWnd=OpenWindow(0,200,200,220,40,"test",#PB_Window_SystemMenu)
RegisterHotKey_(hWnd,0,#MOD_CONTROL,#VK_BACK) ; Ctrl+Backspace.

ButtonGadget(0,10,10,200,20,"Click me and try to use the hotkey :(")

Repeat
  Event=WaitWindowEvent()
  If Event=#WM_HOTKEY
    HotKeyEvent()
  ElseIf Event=#PB_Event_Gadget
    ColorRequester()
  EndIf
Until Event=#PB_Event_CloseWindow
I also tried this, but if the MessageRequester is open then I can't click the ButtonGadget:

Code: Select all

Procedure HotKeyEvent()
  MessageRequester("Dammit","Now you can't click the ButtonGadget! :)")
EndProcedure

Procedure MyCallback(hWnd,uMsg,WParam,LParam)
  If uMsg=#WM_HOTKEY
    HotKeyEvent()
  EndIf
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

hWnd=OpenWindow(0,200,200,220,40,"test",#PB_Window_SystemMenu)
RegisterHotKey_(hWnd,0,#MOD_CONTROL,#VK_BACK) ; Ctrl+Backspace.

ButtonGadget(0,10,10,200,20,"Click me and try to use the hotkey :(")

SetWindowCallback(@MyCallback())

Repeat
  Event=WaitWindowEvent()
  If Event=#PB_Event_Gadget
    ColorRequester()
  EndIf
Until Event=#PB_Event_CloseWindow
Even doing the HotKeyEvent() as a thread doesn't work:

Code: Select all

Procedure HotKeyEvent(null)
  MessageRequester("Dammit","Now you can't click the ButtonGadget! :)")
EndProcedure

Procedure MyCallback(hWnd,uMsg,WParam,LParam)
  If uMsg=#WM_HOTKEY
    CreateThread(@HotKeyEvent(),0)
  EndIf
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

hWnd=OpenWindow(0,200,200,220,40,"test",#PB_Window_SystemMenu)
RegisterHotKey_(hWnd,0,#MOD_CONTROL,#VK_BACK) ; Ctrl+Backspace.

ButtonGadget(0,10,10,200,20,"Click me and try to use the hotkey :(")

SetWindowCallback(@MyCallback())

Repeat
  Event=WaitWindowEvent()
  If Event=#PB_Event_Gadget
    ColorRequester()
  EndIf
Until Event=#PB_Event_CloseWindow
So I'm fresh out of ideas. :(

Re: [Solved] Need two events to always react

Posted: Wed Feb 15, 2017 11:49 am
by Dude
Turns out PureBasic's MessageRequester() is MODAL, thus preventing my main event loop from reacting. :(

If I replace it with the non-modal MessageBox_() API version, it all works as I want. Woohoo! :D

Code: Select all

Procedure HotKeyEvent(null)
  ;MessageRequester("Dammit","Now you can't click the ButtonGadget! :(")
  MessageBox_(0,"ButtonGadget always works!","Woohoo!",#MB_ICONASTERISK)
EndProcedure

Procedure MyCallback(hWnd,uMsg,WParam,LParam)
  If uMsg=#WM_HOTKEY
    CreateThread(@HotKeyEvent(),0)
  EndIf
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

hWnd=OpenWindow(0,200,200,220,40,"test",#PB_Window_SystemMenu)
RegisterHotKey_(hWnd,0,#MOD_CONTROL,#VK_BACK) ; Ctrl+Backspace.

ButtonGadget(0,10,10,200,20,"Click me and try to use the hotkey :(")

SetWindowCallback(@MyCallback())

Repeat
  Event=WaitWindowEvent()
  If Event=#PB_Event_Gadget
    ColorRequester()
  EndIf
Until Event=#PB_Event_CloseWindow

Re: [Solved] Need two events to always react

Posted: Wed Feb 15, 2017 4:06 pm
by skywalk
Your code would match PB's MessageRequester() if you passed your window's hWnd to MessageBox_().

Code: Select all

int WINAPI MessageBox(
  _In_opt_ HWND    hWnd,
  _In_opt_ LPCTSTR lpText,
  _In_opt_ LPCTSTR lpCaption,
  _In_     UINT    uType
);
Parameters:
hWnd [in, optional]
Type: HWND
A handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.