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. SendMessage()

SendMessage()

Scheduled Pinned Locked Moved C / C++ / MFC
8 Posts 4 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.
  • J Offline
    J Offline
    John Uhlenbrock
    wrote on last edited by
    #1

    I am attempting to use SendMessage, and I need to pass a CString as one of the arguements. I can't seem to get this to work.

    M 1 Reply Last reply
    0
    • J John Uhlenbrock

      I am attempting to use SendMessage, and I need to pass a CString as one of the arguements. I can't seem to get this to work.

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

      Pass string ( TCHAR * ) not CString. CString is an C++ object, and passing it may produce problems.

      J 2 Replies Last reply
      0
      • M Mukkie

        Pass string ( TCHAR * ) not CString. CString is an C++ object, and passing it may produce problems.

        J Offline
        J Offline
        John Uhlenbrock
        wrote on last edited by
        #3

        Wouldn't passing the (LPCTSTR) of the CString be the same thing? Using LPCTSTR I get "cannot convert parameter 2 from 'const char *' to 'unsigned int'" on compile. Using TCHAR I get "cannot convert parameter 2 from 'char [100]' to 'unsigned int'" on compile.

        1 Reply Last reply
        0
        • M Mukkie

          Pass string ( TCHAR * ) not CString. CString is an C++ object, and passing it may produce problems.

          J Offline
          J Offline
          John Uhlenbrock
          wrote on last edited by
          #4

          CString myString

          SendMessage(MY_MESSAGE, *myString, 0);

          void CMainFrm::OnMyMessage(WPARAM wParam, LPARAM)
          {
          CString test = wParam;
          }

          This gives me only the first character of the string myString.

          D 1 Reply Last reply
          0
          • J John Uhlenbrock

            CString myString

            SendMessage(MY_MESSAGE, *myString, 0);

            void CMainFrm::OnMyMessage(WPARAM wParam, LPARAM)
            {
            CString test = wParam;
            }

            This gives me only the first character of the string myString.

            D Offline
            D Offline
            dfields326
            wrote on last edited by
            #5

            Try This put the address of the string in a DWORD and passes as the LPARAM; DWORD pdwAddress =(DWORD)&myString; SendMessage(MY_MESSAGE, 0, pdwAddress); void CMainFrm::OnMyMessage( WPARAM wParam, LPARAM lParam ) { CString s; s = *(CString *)lParam; }

            M J 2 Replies Last reply
            0
            • D dfields326

              Try This put the address of the string in a DWORD and passes as the LPARAM; DWORD pdwAddress =(DWORD)&myString; SendMessage(MY_MESSAGE, 0, pdwAddress); void CMainFrm::OnMyMessage( WPARAM wParam, LPARAM lParam ) { CString s; s = *(CString *)lParam; }

              M Offline
              M Offline
              Mukkie
              wrote on last edited by
              #6

              Exactly.

              1 Reply Last reply
              0
              • D dfields326

                Try This put the address of the string in a DWORD and passes as the LPARAM; DWORD pdwAddress =(DWORD)&myString; SendMessage(MY_MESSAGE, 0, pdwAddress); void CMainFrm::OnMyMessage( WPARAM wParam, LPARAM lParam ) { CString s; s = *(CString *)lParam; }

                J Offline
                J Offline
                John Uhlenbrock
                wrote on last edited by
                #7

                Perfect! It worked great, but I realized that it would better fit my needs to use PostMessage, and now it doesn't work. So what's the difference between the way they are called then, they look awfully similar to me. Thanks John

                S 1 Reply Last reply
                0
                • J John Uhlenbrock

                  Perfect! It worked great, but I realized that it would better fit my needs to use PostMessage, and now it doesn't work. So what's the difference between the way they are called then, they look awfully similar to me. Thanks John

                  S Offline
                  S Offline
                  Stefan Pedersen
                  wrote on last edited by
                  #8

                  PostMessage() puts the message in the windows message queue and then returns, no processing of the message is performed before the window's message pump gets to run. With SendMessage() you "forces" the imidiate processing of the message so the message is processed *before* SendMessage() returns. SendMessage() isn't usually a good idea since you can get weird recursive effects if you arn't careful. The most common problem people seem to have with PostMessage() is that they are passing pointers to stack-allocated objects which goes out of scope (are destroyed) before the window procedure gets hold of the pointer... As always, mind your allocations.

                  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