سؤال

This is probably a stupid question but here it goes.

Suppose you are interacting with a Driver API. You are using C and doing entirely via command prompt. No GUI. Is it possible to recieve and handle windows message in such files?

I mean, everywhere, I am using windows handle as NULL. I have no idea if this is possible or even makes sense.

هل كانت مفيدة؟

المحلول

To use GetMessage or PeekMessage you don't need any windows in your thread: http://msdn.microsoft.com/en-us/library/ms644946%28v=vs.85%29.aspx

The thread to which the message is posted must have created a message queue, or else the call to PostThreadMessage fails.

Use the following method to handle this situation.

Create an event object, then create the thread.

Use the WaitForSingleObject function to wait for the event to be set to the signaled state before calling PostThreadMessage.

In the thread to which the message will be posted, call PeekMessage as shown here to force the system to create the message queue:

PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE) > Set the event, to indicate that the thread is ready to receive posted messages. The thread to which the message is posted retrieves the message by calling the GetMessage or PeekMessage function. The hwnd member of the returned MSG structure is NULL.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top