How can I send a message to WindowEvent?

Just starting out? Need help? Post your questions and find answers here.
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

How can I send a message to WindowEvent?

Post 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)
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Re: How can I send a message to WindowEvent?

Post by zxtunes.com »

Surely no one knows the answer?
I do not understand or ask a question? :oops:
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: How can I send a message to WindowEvent?

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: How can I send a message to WindowEvent?

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Re: How can I send a message to WindowEvent?

Post 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
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How can I send a message to WindowEvent?

Post 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.
Last edited by netmaestro on Mon Jul 19, 2010 8:49 pm, edited 1 time in total.
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: How can I send a message to WindowEvent?

Post by srod »

Aye, I said Post... and then used Send...! Doh!!!

SendMessage_() will be safe if using a callback.
I may look like a mule, but I'm not a complete ass.
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Re: How can I send a message to WindowEvent?

Post 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.
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Re: How can I send a message to WindowEvent?

Post 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:
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: How can I send a message to WindowEvent?

Post by Vera »

@zxtunes.com

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

~ Вера
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: How can I send a message to WindowEvent?

Post 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
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: How can I send a message to WindowEvent?

Post 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
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: How can I send a message to WindowEvent?

Post 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.
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: How can I send a message to WindowEvent?

Post by idle »

I missed the cross platform part. :oops:
Windows 11, Manjaro, Raspberry Pi OS
Image
Post Reply