Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getting Message problem....

Getting Message problem....

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++data-structureshelpannouncement
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Richard Cheng

    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?

    L Offline
    L Offline
    l a u r e n
    wrote on last edited by
    #2

    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"

    R 2 Replies Last reply
    0
    • L l a u r e n

      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"

      R Offline
      R Offline
      Richard Cheng
      wrote on last edited by
      #3

      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...

      L M 2 Replies Last reply
      0
      • L l a u r e n

        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"

        R Offline
        R Offline
        Richard Cheng
        wrote on last edited by
        #4

        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...

        1 Reply Last reply
        0
        • R Richard Cheng

          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...

          L Offline
          L Offline
          l a u r e n
          wrote on last edited by
          #5

          ok ... first what messages does the driver produce? --- "every year we invent better idiot proof systems and every year they invent better idiots"

          R 2 Replies Last reply
          0
          • R Richard Cheng

            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...

            M Offline
            M Offline
            Manfred Ramosch
            wrote on last edited by
            #6

            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

            R 1 Reply Last reply
            0
            • L l a u r e n

              ok ... first what messages does the driver produce? --- "every year we invent better idiot proof systems and every year they invent better idiots"

              R Offline
              R Offline
              Richard Cheng
              wrote on last edited by
              #7

              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

              L 1 Reply Last reply
              0
              • R Richard Cheng

                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

                L Offline
                L Offline
                l a u r e n
                wrote on last edited by
                #8

                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"

                1 Reply Last reply
                0
                • L l a u r e n

                  ok ... first what messages does the driver produce? --- "every year we invent better idiot proof systems and every year they invent better idiots"

                  R Offline
                  R Offline
                  Richard Cheng
                  wrote on last edited by
                  #9

                  All these messages will wait in the message queue.......right....then I need to get them from the queue...

                  L 1 Reply Last reply
                  0
                  • R Richard Cheng

                    All these messages will wait in the message queue.......right....then I need to get them from the queue...

                    L Offline
                    L Offline
                    l a u r e n
                    wrote on last edited by
                    #10

                    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"

                    1 Reply Last reply
                    0
                    • M Manfred Ramosch

                      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

                      R Offline
                      R Offline
                      Richard Cheng
                      wrote on last edited by
                      #11

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups