The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL event loop, receiving user (WM_USER) messages in Win32 p
James Olsen
Guest

Hello everyone,

I'm very new to SDL and I've looked over the documentation and FAQ as
best I can but I haven't found the answer I'm looking for (yet). I am
trying to patch an existing program (QEMU) written using SDL and
executing on a Win32 platform to receive commands/messages from
another Win32 application. I know this can be achieved via sockets,
but that will involve changing/adding substantial amount of code, so I
thought I could make a minor modification to the QEMU source and get
it to handle "messages" sent to the main SDL window from the other
application, similar to the "minimize", "quit", and other messages it
receives from the operating system.

I've also experimented with the code hoping to discover the answer
thru trial and error but I'm not having any luck.

I would like to know how I can set up SDL to include custom Windows
messages sent to a window so I can react to them in the SDL_PollEvent
loop.

I've tried switching on event types of SDL_USEREVENT and then
experimenting with SDL_SYSWMEVENT. I am able to send other
standardized messages to it successfully, such as WM_SYSCOMMAND with
data SC_MINIMIZE to minimize the window, so I know I'm sending the
messages properly, I'm just not doing something right in the code to
process the incoming messages properly with SDL.

Please refrain your laughter and/or disgust. Smile Here is a snippet
of the code I tried:

SDL_Event ev1, *ev = &ev1;
// some QEMU code here
while (SDL_PollEvent(ev)) {
switch (ev->type) {
case SDL_SYSWMEVENT:
printf("system event");
break;
case SDL_USEREVENT:
printf("user event");
break;
case ... // rest of QEMU code here
}
}

If I put the printf's in other case branches, like SDL_MOUSEBUTTONDOWN
I get the appropriate output, so I'm sure the printf is working
properly.

I thought perhaps SDL doesn't process those event types by default,
and I tried to see if I needed to enable them first.

After performing SDL_Init, I thought it might work if I added:
SDL_EventState(SDL_USEREVENT, SDL_ENABLE);

But it still seems to ignore the SDL_USEREVENT.

Is SDL_USEREVENT not the same as the WM_USER under Win32? Again, I'm
new, so please go easy on me if this is a question with an obvious
answer.

Please have mercy on me Smile If anyone could help nudge me in the
right direction I'd greatly appreciate it.

Thank you!

--
James
Funny quote: "There are 10 types of people in the world.
Those who understand binary, and those who don't." -- Unknown
SDL event loop, receiving user (WM_USER) messages in Win32 p
Sam Lantinga
Guest

Quote:
I would like to know how I can set up SDL to include custom Windows
messages sent to a window so I can react to them in the SDL_PollEvent
loop.

If you're processing them from the same application, you can use SDL_USEREVENT.
If you're trying to send messages to another window, you'll want to use WM_USER
and then handle them in SDL_SYSWMEVENT. (I haven't tried this myself, but I
think that will work)

Quote:
Is SDL_USEREVENT not the same as the WM_USER under Win32? Again, I'm
new, so please go easy on me if this is a question with an obvious
answer.

SDL_USEREVENT is handled entirely within the SDL library within a single
application (with potentially multiple threads).

WM_USER can be posted to to another application's window, and runs through
the Windows message queue.

-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment