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

Windows Messages

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingworkspace
3 Posts 2 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 Offline
    R Offline
    ROK_RShadow
    wrote on last edited by
    #1

    Hmm.. As usual something that has first appeared obvious to me.. isn't. I am using a class that sends the view a User Defined Message to notify it of some events that are taking place. However after setting up the command handlers for the view I realized that the view was not recieving or processing the message.. so I decided to setup a test message.. and it is not working either.. so I must be doing something wrong.. and I just can't figure it out. I setup the test message handler as such. afx_msg void OnTestMsg(WPARAM wParam, LPARAM lParam); ON_COMMAND(WM_TESTMSG, OnTestMsg) void CMyView::OnTestMsg(WPARAM wParam, LPARAM lParam) { TRACE("Test Message"); } defined message in view header as such #define WM_TESTMSG WM_USER + 5 Created a command ID with the following SendMessage(WM_TESTMSG); SendMessage(WM_TESTMSG,0,0); ::SendMessage(GetSafeHwnd(), WM_TESTMSG); ::SendMessage(GetSafeHwnd(), WM_TESTMSG,0,0); but the message function is never fired.. Anybody see anything obvious that I am doing wrong. Thank you.

    M 1 Reply Last reply
    0
    • R ROK_RShadow

      Hmm.. As usual something that has first appeared obvious to me.. isn't. I am using a class that sends the view a User Defined Message to notify it of some events that are taking place. However after setting up the command handlers for the view I realized that the view was not recieving or processing the message.. so I decided to setup a test message.. and it is not working either.. so I must be doing something wrong.. and I just can't figure it out. I setup the test message handler as such. afx_msg void OnTestMsg(WPARAM wParam, LPARAM lParam); ON_COMMAND(WM_TESTMSG, OnTestMsg) void CMyView::OnTestMsg(WPARAM wParam, LPARAM lParam) { TRACE("Test Message"); } defined message in view header as such #define WM_TESTMSG WM_USER + 5 Created a command ID with the following SendMessage(WM_TESTMSG); SendMessage(WM_TESTMSG,0,0); ::SendMessage(GetSafeHwnd(), WM_TESTMSG); ::SendMessage(GetSafeHwnd(), WM_TESTMSG,0,0); but the message function is never fired.. Anybody see anything obvious that I am doing wrong. Thank you.

      M Offline
      M Offline
      MAAK
      wrote on last edited by
      #2

      ON_COMMAND is not used for handling user defined messages. For user define messages you should rather use the macro ON_MESSAGE. In addition, the handler function for user defined messages, or that should be passed for ON_MESSAGE macro takes the follwing form: LRESULT OnTestMsg(WPARAM wParam, LPARAM lParam); Therefore, your code should be like this

      #define WM_TESTMSG WM_USER + 5
      .
      afx_msg LRESULT OnTestMsg(WPARAM wParam, LPARAM lParam);
      
      ON_MESSAGE(WM_TESTMSG, OnTestMsg)
      .
      .
      .
      LRESULT CMyView::OnTestMsg(WPARAM wParam, LPARAM lParam)
      {
          TRACE("Test Message");
      }
      .
      .
      .
      SendMessage(WM_TESTMSG);
      
      R 1 Reply Last reply
      0
      • M MAAK

        ON_COMMAND is not used for handling user defined messages. For user define messages you should rather use the macro ON_MESSAGE. In addition, the handler function for user defined messages, or that should be passed for ON_MESSAGE macro takes the follwing form: LRESULT OnTestMsg(WPARAM wParam, LPARAM lParam); Therefore, your code should be like this

        #define WM_TESTMSG WM_USER + 5
        .
        afx_msg LRESULT OnTestMsg(WPARAM wParam, LPARAM lParam);
        
        ON_MESSAGE(WM_TESTMSG, OnTestMsg)
        .
        .
        .
        LRESULT CMyView::OnTestMsg(WPARAM wParam, LPARAM lParam)
        {
            TRACE("Test Message");
        }
        .
        .
        .
        SendMessage(WM_TESTMSG);
        
        R Offline
        R Offline
        ROK_RShadow
        wrote on last edited by
        #3

        LOL... Thank you.. first simple solution I have ran across. Thank you very much for your help

        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