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. Send message to window

Send message to window

Scheduled Pinned Locked Moved C / C++ / MFC
help
16 Posts 5 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.
  • C capint

    I want to send a key to a window. I used Global Hook and my code is like this : //In hook proc : if(nCode <0) CallNextHookEx(MyHook,nCode,wParam,lParam); hWndApp = CWnd::FindWindow(0,_T("Test")); if (hWndApp == NULL) MessageBox(NULL,L" Can't find the window", L"",0); hWndApp->SendMessage(WM_CHAR, 8, 0); //Backspace It can find the window but it can't send the message. Some one plz help me :rose:

    S Offline
    S Offline
    sudhir_Kumar
    wrote on last edited by
    #3

    I think you should should send: WM_KEYDOWN WM_CHAR WM_KEYUP

    -@SuDhIrKuMaR@-

    C 1 Reply Last reply
    0
    • C capint

      I want to send a key to a window. I used Global Hook and my code is like this : //In hook proc : if(nCode <0) CallNextHookEx(MyHook,nCode,wParam,lParam); hWndApp = CWnd::FindWindow(0,_T("Test")); if (hWndApp == NULL) MessageBox(NULL,L" Can't find the window", L"",0); hWndApp->SendMessage(WM_CHAR, 8, 0); //Backspace It can find the window but it can't send the message. Some one plz help me :rose:

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #4

      see SendInput api of any use??

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
      Never mind - my own stupidity is the source of every "problem" - Mixture

      cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/xml>

      1 Reply Last reply
      0
      • C capint

        I want to send a key to a window. I used Global Hook and my code is like this : //In hook proc : if(nCode <0) CallNextHookEx(MyHook,nCode,wParam,lParam); hWndApp = CWnd::FindWindow(0,_T("Test")); if (hWndApp == NULL) MessageBox(NULL,L" Can't find the window", L"",0); hWndApp->SendMessage(WM_CHAR, 8, 0); //Backspace It can find the window but it can't send the message. Some one plz help me :rose:

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #5

        If the target window is active, you can use SendInput().

        "Love people and use things, not love things and use people." - Unknown

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        C 2 Replies Last reply
        0
        • S sudhir_Kumar

          I think you should should send: WM_KEYDOWN WM_CHAR WM_KEYUP

          -@SuDhIrKuMaR@-

          C Offline
          C Offline
          capint
          wrote on last edited by
          #6

          What do you mean ? Do I have to send three messages at one time ?

          1 Reply Last reply
          0
          • D David Crow

            If the target window is active, you can use SendInput().

            "Love people and use things, not love things and use people." - Unknown

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            C Offline
            C Offline
            capint
            wrote on last edited by
            #7

            Could you show me an example of using SendInput to send a key to an active window plz ? I find it difficult to find a specific example :(

            D 1 Reply Last reply
            0
            • C capint

              Could you show me an example of using SendInput to send a key to an active window plz ? I find it difficult to find a specific example :(

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #8

              I found this using Google.

              "Love people and use things, not love things and use people." - Unknown

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              C T 2 Replies Last reply
              0
              • D David Crow

                I found this using Google.

                "Love people and use things, not love things and use people." - Unknown

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                C Offline
                C Offline
                capint
                wrote on last edited by
                #9

                Thank you very much :D

                1 Reply Last reply
                0
                • D David Crow

                  I found this using Google.

                  "Love people and use things, not love things and use people." - Unknown

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #10

                  DavidCrow wrote:

                  I found this using Google.

                  he he he Answer of yahoo getting very popular

                  1 Reply Last reply
                  0
                  • D David Crow

                    If the target window is active, you can use SendInput().

                    "Love people and use things, not love things and use people." - Unknown

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    C Offline
                    C Offline
                    capint
                    wrote on last edited by
                    #11

                    Plz help me one more time. I would like to know how to send WM_KEYUP by SendInput. When I send a key, it seems to be pressed forever ...

                    D 1 Reply Last reply
                    0
                    • C capint

                      Plz help me one more time. I would like to know how to send WM_KEYUP by SendInput. When I send a key, it seems to be pressed forever ...

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #12

                      See here.

                      "Love people and use things, not love things and use people." - Unknown

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      C 1 Reply Last reply
                      0
                      • D David Crow

                        See here.

                        "Love people and use things, not love things and use people." - Unknown

                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                        C Offline
                        C Offline
                        capint
                        wrote on last edited by
                        #13

                        I've read many pages from the pages you gave me but I still can't find the answer :( They recommend to use SendMessage but it doesn't work with SendMessage...

                        D 1 Reply Last reply
                        0
                        • C capint

                          I've read many pages from the pages you gave me but I still can't find the answer :( They recommend to use SendMessage but it doesn't work with SendMessage...

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #14

                          Is the problem with sending or receiving? What does your code look like?

                          "Love people and use things, not love things and use people." - Unknown

                          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                          C 1 Reply Last reply
                          0
                          • D David Crow

                            Is the problem with sending or receiving? What does your code look like?

                            "Love people and use things, not love things and use people." - Unknown

                            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                            C Offline
                            C Offline
                            capint
                            wrote on last edited by
                            #15

                            This is my code :

                            HWND windowHandle = ::FindWindow(0, _T("Test"));
                            INPUT *key;
                            ::SetForegroundWindow(windowHandle);
                            key = new INPUT;
                            key->type = INPUT_KEYBOARD;
                            key->ki.wVk = VK_CONTROL;
                            key->ki.dwFlags = 0;
                            key->ki.time = 0;
                            key->ki.wScan = 0;
                            key->ki.dwExtraInfo = 0;
                            SendInput(1,key,sizeof(INPUT));
                            key->ki.dwExtraInfo = KEYEVENTF_KEYUP;
                            SendInput(1,key,sizeof(INPUT));

                            ::SendMessage(windowHandle,WM_KEYUP,0,0); //==> No effect ?

                            D 1 Reply Last reply
                            0
                            • C capint

                              This is my code :

                              HWND windowHandle = ::FindWindow(0, _T("Test"));
                              INPUT *key;
                              ::SetForegroundWindow(windowHandle);
                              key = new INPUT;
                              key->type = INPUT_KEYBOARD;
                              key->ki.wVk = VK_CONTROL;
                              key->ki.dwFlags = 0;
                              key->ki.time = 0;
                              key->ki.wScan = 0;
                              key->ki.dwExtraInfo = 0;
                              SendInput(1,key,sizeof(INPUT));
                              key->ki.dwExtraInfo = KEYEVENTF_KEYUP;
                              SendInput(1,key,sizeof(INPUT));

                              ::SendMessage(windowHandle,WM_KEYUP,0,0); //==> No effect ?

                              D Offline
                              D Offline
                              David Crow
                              wrote on last edited by
                              #16

                              capint wrote:

                              ::SendMessage(windowHandle,WM_KEYUP,0,0); //==> No effect ?

                              What does SendMessage() return?

                              "Love people and use things, not love things and use people." - Unknown

                              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                              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