Intercept a WM message into a C++ class
-
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?
---
-
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?
---
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.
-
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?
---
-
an own WinProc is the generic solution. But be aware that it dont gets "spaghetti ocde" :wtf:
Press F1 for help or google it. Greetings from Germany
-
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?
---
One approach would be to store all message processing objects in a std::map<> container. Although this will only give you a 1 to 1 relationship between the expected window message and the object which handles it you'll have a nice start to begin expanding. When you receive the device notification message you can retrieve the object for that message and then call the appropriate method to handle the operation.
// Call this from your window procedure
void HandleDeviceMessage(UINT msg, WPARAM wParam, LPARAM lParam)
{
ProcObject *obj;
std::map::iterator iter;iter = m\_DevNotifyMap.find(msg); if(iter == m\_DevNotifyMap.end()) { return; // no object available to handle this notification } iter->second->OnNotification(msg, wParam, lParam);
}
I am a lean mean ground beef machine!!!
-
If I put the WinProc function in my class, it will need a hwnd handle I think. What handle am I supposed to give it? Should I require one to the application which is going to use my class? (this would exclude console apps, that's just a pity)
---
yes you need a hwnd for it. The main hwnd of the app is fine. If you havent a hwnd in your app, you must create one. It is common use to have in this cases an invisible (or minimized) window. Believe me :-O
Press F1 for help or google it. Greetings from Germany
-
yes you need a hwnd for it. The main hwnd of the app is fine. If you havent a hwnd in your app, you must create one. It is common use to have in this cases an invisible (or minimized) window. Believe me :-O
Press F1 for help or google it. Greetings from Germany