Post Events Between *Two* wxApps

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
todd_machmotion
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon Mar 14, 2016 4:24 pm

Post Events Between *Two* wxApps

Post by todd_machmotion »

There's a lot of info about queueing/posting events from other threads into the wxApp's event queue.
What I can't find much information about (or don't know how to look for it) is how to queue/post an event to a different wxApp's event queue.

I have a plugin in another app that is running its own event loop. There are some GUI actions that I need to do, but I need to do them from the main application's thread/event loop. It happens to be wxWidgets, but my app can't really know this (right??), and I probably wouldn't want to because if there were any binary incompatibilities between versions, things could very easily Go Bad™.

Is there a way to post a wxEvent to a native event loop/queue and have it (eventually) call my event handler?

I'm using Windows. (I realize this is not exactly a Windows/WinAPI developer forum, but the question is inherently wxWidgets-related.)
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Post Events Between *Two* wxApps

Post by doublemax »

You can't use "normal" wxEvents to communicate between applications. For communication between two wxWidgets apps check this: https://docs.wxwidgets.org/trunk/overview_ipc.html

Under Windows there is a simple way by using "RegisterWindowMessage".
https://docs.microsoft.com/en-us/window ... owmessagew
Use the source, Luke!
todd_machmotion
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon Mar 14, 2016 4:24 pm

Re: Post Events Between *Two* wxApps

Post by todd_machmotion »

doublemax wrote:Under Windows there is a simple way by using "RegisterWindowMessage".
https://docs.microsoft.com/en-us/window ... owmessagew
This might prove fruitful. Thanks.

How do I register a handler? Or how do I get the wx event loop to invoke my handler? Is there a way to embed a wxEvent in the message object so that some wxEvtHandler will get called?
wxWindowMSW::MSWHandleMessage() looks like the WndProc handler. I don't see "user" events in there. The fall-through for unrecognized messages is to consult a manually registered message handler, but I only see a (private/impl) method to register a windows event handler, but I don't know if I can do that with wxWidgets, without, say, subclassing wxWindow or something. Is there a good way to do this?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Post Events Between *Two* wxApps

Post by doublemax »

Code: Select all

g_my_windows_message = RegisterWindowMessage(TEXT("SomeMessage"));
///
WXLRESULT MyFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
  if ( nMsg == g_my_windows_message ) {
    // do your stuff here
    return TRUE;
  }
  return wxFrame::MSWWindowProc(nMsg, wParam, lParam);
}
Use the source, Luke!
Post Reply