Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I was wondering how to intercept a WM_ specific message into a C++ class, I need to use the RegisterDeviceNotification function to register a specific WM_ message (I need a window here right?) and then intercept it and call the appropriate function

The C++ class should be included in any project, from a console one to a win32 to a mfc one. My idea is to create the skeleton of a win32 window and then use the WndProc for that window, is this stupid?

Is there any (surely) better solution?
Posted
Updated 19-Nov-09 11:23am
v3

You definitely need to have a Window Proc to recieve your message, because it is associated specifically with a registered Windows class. The documentation over at MSDN should show you how. See this: Windows Procedures Overview[^]
You can also define your own custom Windows messages using a define, and by selecting a value above WM_USER.
 
Share this answer
 
Well, you will need a message pump. As long as you can get a message pump running in your console app, then yeah, your solution sounds great. Can be tricky, because usually console apps aren't event driven. If concurrency is an issue for you, you might have to create a worker thread in which you house both the message pump and window. If concurrency isn't an issue, all you have to do is start a while(GetMessage(...) { DispatchMessage(...) }-loop, while you wait for the message.

You might also be interested in using message-only windows for your code. http://msdn.microsoft.com/en-us/library/ms632599(VS.85).aspx#message_[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900