Page 1 of 1

How can I send a message to WindowEvent?

Posted: Sun Jul 18, 2010 10:16 pm
by zxtunes.com

Code: Select all

hhkLLMouse = SetWindowsHookEx_(#WH_MOUSE_LL,@HookProc(),GetModuleHandle_(0),0) 
I cutched clicking mouse buttons and a special procedure if the key is pressed I need to initiate WindowEvent, how to do this? (Send a message to any WindowEvent)

Re: How can I send a message to WindowEvent?

Posted: Mon Jul 19, 2010 7:57 am
by zxtunes.com
Surely no one knows the answer?
I do not understand or ask a question? :oops:

Re: How can I send a message to WindowEvent?

Posted: Mon Jul 19, 2010 1:29 pm
by Vera
Hi zxtunes.com,

seeing your code expample I know immediately I can't help you :(

But trying to understand your question makes me confuse.
What I understand is:

1. you want to transform a MouseEvent into a WindowEvent.
But maybe you like a WindowEvent to happen somewhere else like oftit is trying to do here: http://www.purebasic.fr/english/viewtop ... 34&start=0

2. you cannot send an event to an event.
An event is something that is happening which you may intercept, but an event itself is not statically awaiting to receive a demand.

Maybe you could make your question more clearly or even tell us what you want to achieve with your action.

Greetings ~ Vera

Re: How can I send a message to WindowEvent?

Posted: Mon Jul 19, 2010 2:19 pm
by srod
You can register your own Window's messages and then fire them at your main window as and when appropriate. A callback will retrieve these messages without a problem.

Alternatively, you can use SendMessage_() / PostMessage_() to synthesise some events (e.g. menu events via #WM_COMMAND) which will be picked up.

Alternatively, you can import PB's PB_Gadget_SendGadgetCommand() function as with the following which simulates a #PB_EventType_LeftClick type event :

Code: Select all

Import "Gadget.lib"
  PB_Gadget_SendGadgetCommand(hWnd, EventType)
EndImport

If OpenWindow(0, 0, 0, 230, 120, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(1, 10, 10, 150, 100, "ListIcon", 140, #PB_ListIcon_GridLines) 
  For a = 1 To 4 
    AddGadgetItem(1, -1, "Line "+Str(a)) 
  Next
  PB_Gadget_SendGadgetCommand(GadgetID(1), #PB_EventType_LeftClick)
  Repeat
    eventID = WaitWindowEvent()
    Select eventID
      Case #PB_Event_Gadget
        If EventType() = #PB_EventType_LeftClick
          Debug "Left clicked gadget " + Str(EventGadget())
        EndIf       
    EndSelect
  Until eventID = #PB_Event_CloseWindow
EndIf
If you are looking to pick up custom messages within your application (not between processes) then consider using a custom message identifier and then simply post this message to your main window etc.

Code: Select all

#MyMessage = #WM_APP + 1

Procedure MyWindowCallback(hWnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #MyMessage
      Debug "#MyMessage received!" 
  EndSelect    

  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 230, 120, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(1, 10, 10, 150, 100, "ListIcon", 140, #PB_ListIcon_GridLines) 
  For a = 1 To 4 
    AddGadgetItem(1, -1, "Line "+Str(a)) 
  Next
  SetWindowCallback(@MyWindowCallback())
  SendMessage_(WindowID(0), #MyMessage, 0, 0)
  Repeat
    eventID = WaitWindowEvent()
  Until eventID = #PB_Event_CloseWindow
EndIf
For between processes then register your own window message and broadcast it to all top-level windows etc.

Re: How can I send a message to WindowEvent?

Posted: Mon Jul 19, 2010 8:34 pm
by zxtunes.com
Srod, this not working:

Code: Select all

#MyMessage = #WM_APP + 1


If OpenWindow(0, 0, 0, 230, 120, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)


  SendMessage_(WindowID(0), #MyMessage, 0, 0)

  Repeat
    EventID = WaitWindowEvent()
    
    If EventID = #MyMessage: Debug "Work?": EndIf
    
  Until EventID = #PB_Event_CloseWindow
EndIf

Re: How can I send a message to WindowEvent?

Posted: Mon Jul 19, 2010 8:43 pm
by netmaestro

Code: Select all

#MyMessage = #WM_APP + 1


If OpenWindow(0, 0, 0, 230, 120, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)


  PostMessage_(WindowID(0), #MyMessage, 0, 0)

  Repeat
    EventID = WaitWindowEvent()
    
    If EventID = #MyMessage: Debug "Work?": EndIf
    
  Until EventID = #PB_Event_CloseWindow
EndIf
PostMessage is asynchronous. Use it from threads etc. SendMessage is usually OK from the PB loop.

Re: How can I send a message to WindowEvent?

Posted: Mon Jul 19, 2010 8:47 pm
by srod
Aye, I said Post... and then used Send...! Doh!!!

SendMessage_() will be safe if using a callback.

Re: How can I send a message to WindowEvent?

Posted: Mon Jul 19, 2010 8:48 pm
by zxtunes.com
Let me explain.
I do graphic editor.
What would define the moment you click the mouse I do hook.
Since the event is not triggered when you click and when depressed, for the editor is useless.
For consistency of the program, I would like to do that procedure hook when you press initiated event which is being followed in the main program.

Re: How can I send a message to WindowEvent?

Posted: Mon Jul 19, 2010 8:50 pm
by zxtunes.com
netmaestro wrote: PostMessage is asynchronous. Use it from threads etc. SendMessage is usually OK from the PB loop.
Yes! it work! thanx guys! :lol:

Re: How can I send a message to WindowEvent?

Posted: Mon Jul 19, 2010 10:18 pm
by Vera
@zxtunes.com

Игнорируют унижает.

~ Вера

Re: How can I send a message to WindowEvent?

Posted: Thu Jul 28, 2011 10:28 am
by djes
With threadsafe, this code doesn't work, and as I'd like to do a multiplatform code, I have no solution to send a msg from my thread to the main window.

Code: Select all

Import "Gadget.lib"
  PB_Gadget_SendGadgetCommand(hWnd, EventType)
EndImport

Procedure t(Null)
  PB_Gadget_SendGadgetCommand(GadgetID(1), #PB_EventType_LeftClick)
EndProcedure

If OpenWindow(0, 0, 0, 230, 120, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(1, 10, 10, 150, 100, "ListIcon", 140, #PB_ListIcon_GridLines) 
  For a = 1 To 4 
    AddGadgetItem(1, -1, "Line "+Str(a)) 
  Next
  CreateThread(@t(), Null)
  Repeat
    eventID = WaitWindowEvent()
    Select eventID
      Case #PB_Event_Gadget
        If EventType() = #PB_EventType_LeftClick
          Debug "Left clicked gadget " + Str(EventGadget())
        EndIf       
    EndSelect

  Until eventID = #PB_Event_CloseWindow
EndIf

Re: How can I send a message to WindowEvent?

Posted: Fri Jul 29, 2011 7:26 am
by idle
have you tried to use a #WM_USER message and PostMessage_ ?

I think I've done that in the past but can't remember if it came through the pb event loop or a call back

Re: How can I send a message to WindowEvent?

Posted: Fri Jul 29, 2011 8:17 am
by djes
idle wrote:have you tried to use a #WM_USER message and PostMessage_ ?

I think I've done that in the past but can't remember if it came through the pb event loop or a call back
I'd like to do it in a multiplatform way. We have threads, multiple windows, but the command to send messages between them needs a little hack or api, or ugly code. I think this command has to be implemented.

Re: How can I send a message to WindowEvent?

Posted: Fri Jul 29, 2011 9:56 pm
by idle
I missed the cross platform part. :oops: