Getting Message problem....
-
I'm writing a program that requires to check the message queue (or event..i don't know...)frequently. These messages or events are not from VC library. I need to wait for these messages or events from a DRIVER. Once the user make any changes on the device, the DRIVER will notify the program to do something. So, the changes can happen anytime....... In DOS version, I used a infinite loop to do this: e.g. int main() { * * * for ( ;; ) { check message(); * * } } But in MFC programming, there is no main function, so how can I check the message queue very frequently? And what function can I use?
-
I'm writing a program that requires to check the message queue (or event..i don't know...)frequently. These messages or events are not from VC library. I need to wait for these messages or events from a DRIVER. Once the user make any changes on the device, the DRIVER will notify the program to do something. So, the changes can happen anytime....... In DOS version, I used a infinite loop to do this: e.g. int main() { * * * for ( ;; ) { check message(); * * } } But in MFC programming, there is no main function, so how can I check the message queue very frequently? And what function can I use?
sounds odd to do it by polling the device message queue in effect does the driver generate a driver-defined windows message? if so you could handle that notification with a wm_message or wm_command handler in the message map for the app --- "every year we invent better idiot proof systems and every year they invent better idiots"
-
sounds odd to do it by polling the device message queue in effect does the driver generate a driver-defined windows message? if so you could handle that notification with a wm_message or wm_command handler in the message map for the app --- "every year we invent better idiot proof systems and every year they invent better idiots"
yes....the driver can generate message. But I don't know how to make the program get the notification of these messages.....can you give me an example??? Or what function I should use?? WindowProc()??? or what.....I just don't know how to do and where to start. thanks alot...
-
sounds odd to do it by polling the device message queue in effect does the driver generate a driver-defined windows message? if so you could handle that notification with a wm_message or wm_command handler in the message map for the app --- "every year we invent better idiot proof systems and every year they invent better idiots"
yes....the driver can generate message. But I don't know how to make the program get the notification of these messages.....can you give me an example??? Or what function I should use?? WindowProc()??? or what..... thanks alot...
-
yes....the driver can generate message. But I don't know how to make the program get the notification of these messages.....can you give me an example??? Or what function I should use?? WindowProc()??? or what.....I just don't know how to do and where to start. thanks alot...
ok ... first what messages does the driver produce? --- "every year we invent better idiot proof systems and every year they invent better idiots"
-
yes....the driver can generate message. But I don't know how to make the program get the notification of these messages.....can you give me an example??? Or what function I should use?? WindowProc()??? or what.....I just don't know how to do and where to start. thanks alot...
e.g. In my MIDI-Callback function (like your Device-Driver-Message) I post a Message to the Message-Queue of the window that should receive the message with: PostMessage(WM_MYMESSAGE); You have to: #define WM_USER + 100 WM_MYMESSAGE (in your Resource.h) afx_msg void OnMyMessage(); (in the destination window's MessageMap MyClass.h) ON_MESSAGE(WM_MYMESSAGE, OnMyMessage) (in the destination window's MessageMap MyClass.cpp) before posting the Message. You have to do it manually (VC++5) for the Class-Wizard does not support User-Messages to be created... In OnMyMessage() which is directly called by your driver-message you can write your Code now. Hope that helps Manfred
-
ok ... first what messages does the driver produce? --- "every year we invent better idiot proof systems and every year they invent better idiots"
Actually it is a touch screen driver. Once the user touch the screen, it generates a message and the program shows its coordinate. It can happen anytime. The message is something liked (WM_USER + 0x0A) or 0x0B....etc
-
Actually it is a touch screen driver. Once the user touch the screen, it generates a message and the program shows its coordinate. It can happen anytime. The message is something liked (WM_USER + 0x0A) or 0x0B....etc
groovy so now follow manfred's instructions below and voila (i was gonna post all that stuff next) --- "every year we invent better idiot proof systems and every year they invent better idiots"
-
ok ... first what messages does the driver produce? --- "every year we invent better idiot proof systems and every year they invent better idiots"
All these messages will wait in the message queue.......right....then I need to get them from the queue...
-
All these messages will wait in the message queue.......right....then I need to get them from the queue...
not really your message handler function will be called when the message arrives just process the message in as quick a way as possible (you dont want to be taking ages in a (pseudo-)interrupt handler --- "every year we invent better idiot proof systems and every year they invent better idiots"
-
e.g. In my MIDI-Callback function (like your Device-Driver-Message) I post a Message to the Message-Queue of the window that should receive the message with: PostMessage(WM_MYMESSAGE); You have to: #define WM_USER + 100 WM_MYMESSAGE (in your Resource.h) afx_msg void OnMyMessage(); (in the destination window's MessageMap MyClass.h) ON_MESSAGE(WM_MYMESSAGE, OnMyMessage) (in the destination window's MessageMap MyClass.cpp) before posting the Message. You have to do it manually (VC++5) for the Class-Wizard does not support User-Messages to be created... In OnMyMessage() which is directly called by your driver-message you can write your Code now. Hope that helps Manfred
Sorry.....i cannot make it work.... I put the #define WM_MYMESSAGE WM_USER+0x0D in resource.h then i put afx_msg void OnMyMessage(); in the MyProgramView.h then ON_MESSAGE(WM_MYMESSAGE, OnMyMessage) in the MyProgramView.cpp then i put void MyProgramView::OnMyMessage() { AfxMessageBox("yes"); } but no message box pop up when i touch the screen.....did I make anything wrong? How about the PostMessage or GetMessage stuff.... Also, should I put some parameters in the OnMyMessage()? For example, lparam or wparam. Thanks