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. How to send message to another program?

How to send message to another program?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
20 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.
  • W Williams

    Heare are the steps and code to send messages to another program. 1. Remember that on Windows all are windows, so you need to get a HWND to your target window. 2. With the target HWND you call GetDlgItem to retrieve a handlw to window control. 3. Send the message to the window´s control directly. code: // buffer to get the target caption window returned by // GetWindowText char szWindowName[60]; CString szTargetWindowName = "MyApp"; // Target window int nFound; int nLength = strlen(szTargetWindowName); HWND hSearchHandle; //Search around our "MyApp" for(hSearchHandle=::GetWindow(::GetDesktopWindow(),GW_CHILD);hSearchHandle; hSearchHandle = ::GetWindow(hSearchHandle, GW_HWNDNEXT)) { ::GetWindowText(hSearchHandle, szWindowName, 20); szWindowName[nLength] = '\0'; nFound = lstrcmpi(szWindowName,szTargetWindowName); if(nFound == 0) { CWnd pCwnd; // WPARAM 1: Check, 0: uncheck ::SendMessage(::GetDlgItem(hSearchHandle,, BM_SETCHECK,1,0); } } if you have any problem with the code above contact me . Asta la vista.

    R Offline
    R Offline
    RichardWdy
    wrote on last edited by
    #4

    I made a mistake with the former reply. I tried this: ::SendMessage(::GetDlgItem(hSearchHandle, ID_EDIT_START), BM_SETCHECK, 1, 0); No response at all. I have solved it in another way. My question has a little change. How to get a special edit control in a dialog program's handle? Could you help me? Thanks a lot. Richard Woo No pains, no gains.

    W 1 Reply Last reply
    0
    • R RichardWdy

      I made a mistake with the former reply. I tried this: ::SendMessage(::GetDlgItem(hSearchHandle, ID_EDIT_START), BM_SETCHECK, 1, 0); No response at all. I have solved it in another way. My question has a little change. How to get a special edit control in a dialog program's handle? Could you help me? Thanks a lot. Richard Woo No pains, no gains.

      W Offline
      W Offline
      Williams
      wrote on last edited by
      #5

      Hi, BM_SETCHECK works only to checkbox buttons!! Talk more about your last question!

      R 2 Replies Last reply
      0
      • W Williams

        Hi, BM_SETCHECK works only to checkbox buttons!! Talk more about your last question!

        R Offline
        R Offline
        RichardWdy
        wrote on last edited by
        #6

        Thank you. I want to run another dialog program. It has several edit controls. I want to fill the edit controls automatically, which requests send message to the edit control. I tried several ways, but I couldn't the handle of the edit control. The following is my code. HWND h = ::GetDlgItem(hDlg, ID_EDIT_START); // hDlg is the handle of the dialog. h return NULL. Could you tell me what's wrong? How can I perform that? Richard Woo No pains, no gains.

        1 Reply Last reply
        0
        • W Williams

          Hi, BM_SETCHECK works only to checkbox buttons!! Talk more about your last question!

          R Offline
          R Offline
          RichardWdy
          wrote on last edited by
          #7

          Thank you. I want to run another dialog program. It has several edit controls. I want to fill the edit controls automatically, which requests send message to the edit control. I tried several ways, but I couldn't get the handle of the edit control. The following is my code. HWND h = ::GetDlgItem(hDlg, ID_EDIT_START); // hDlg is the handle of the dialog. h return NULL. Could you tell me what's wrong? How can I perform that? Richard Woo No pains, no gains.

          W 1 Reply Last reply
          0
          • R RichardWdy

            Thank you. I want to run another dialog program. It has several edit controls. I want to fill the edit controls automatically, which requests send message to the edit control. I tried several ways, but I couldn't get the handle of the edit control. The following is my code. HWND h = ::GetDlgItem(hDlg, ID_EDIT_START); // hDlg is the handle of the dialog. h return NULL. Could you tell me what's wrong? How can I perform that? Richard Woo No pains, no gains.

            W Offline
            W Offline
            Williams
            wrote on last edited by
            #8

            Hello, How you get the handle to dialog? did you use the GetWindow methode described in the firts posts? To get the handle to another app(eg your another dialog app) you have to search for window´s caption and compare with your target window´s caption. Once you have the window´s handle you can call GetDlgItem to retrieve a handle to dialog items. I can send you two tests apps that explain it better.

            R 1 Reply Last reply
            0
            • W Williams

              Hello, How you get the handle to dialog? did you use the GetWindow methode described in the firts posts? To get the handle to another app(eg your another dialog app) you have to search for window´s caption and compare with your target window´s caption. Once you have the window´s handle you can call GetDlgItem to retrieve a handle to dialog items. I can send you two tests apps that explain it better.

              R Offline
              R Offline
              RichardWdy
              wrote on last edited by
              #9

              I can get the handle of the dialog and the ID of the edit control. But the edit control only has ID, not caption. I do use GetWindow() to enumerate the desktop windows. It's a good way that can replace FindWindow function. My problem is I don't know how to use ID of the control to get the handle. I tried several functions, as GetDlgItem, GetDlgCtlID,... Could you give me further information? Thanks a lot. Richard Woo No pains, no gains.

              W 1 Reply Last reply
              0
              • R RichardWdy

                I can get the handle of the dialog and the ID of the edit control. But the edit control only has ID, not caption. I do use GetWindow() to enumerate the desktop windows. It's a good way that can replace FindWindow function. My problem is I don't know how to use ID of the control to get the handle. I tried several functions, as GetDlgItem, GetDlgCtlID,... Could you give me further information? Thanks a lot. Richard Woo No pains, no gains.

                W Offline
                W Offline
                Williams
                wrote on last edited by
                #10

                Send me your two tests dialog apps.

                R 1 Reply Last reply
                0
                • W Williams

                  Send me your two tests dialog apps.

                  R Offline
                  R Offline
                  RichardWdy
                  wrote on last edited by
                  #11

                  I send you 2 apps. Plx check. Thanks a lot. No pains, no gains.

                  W 1 Reply Last reply
                  0
                  • R RichardWdy

                    I send you 2 apps. Plx check. Thanks a lot. No pains, no gains.

                    W Offline
                    W Offline
                    Williams
                    wrote on last edited by
                    #12

                    you say its ok? I dont understand what do you want. whats is wrong so!?

                    R 1 Reply Last reply
                    0
                    • W Williams

                      you say its ok? I dont understand what do you want. whats is wrong so!?

                      R Offline
                      R Offline
                      RichardWdy
                      wrote on last edited by
                      #13

                      I don't know why it works! Just before I sent you the 2 apps, it showed "Not Found". HWND g_FindSpecialControl(LPCSTR lpWndCap, int nIDDlgItem) { HWND hWnd; int nID; hWnd = FindWindow(NULL, lpWndCap); if (hWnd == NULL) return NULL; hWnd = GetWindow(hWnd, GW_CHILD); while (hWnd != NULL) { hWnd = GetWindow(hWnd, GW_HWNDNEXT); nID = GetDlgCtrlID(hWnd); if (nID == nIDDlgItem) return hWnd; } return NULL; } It's strange! No pains, no gains.

                      W 1 Reply Last reply
                      0
                      • R RichardWdy

                        I don't know why it works! Just before I sent you the 2 apps, it showed "Not Found". HWND g_FindSpecialControl(LPCSTR lpWndCap, int nIDDlgItem) { HWND hWnd; int nID; hWnd = FindWindow(NULL, lpWndCap); if (hWnd == NULL) return NULL; hWnd = GetWindow(hWnd, GW_CHILD); while (hWnd != NULL) { hWnd = GetWindow(hWnd, GW_HWNDNEXT); nID = GetDlgCtrlID(hWnd); if (nID == nIDDlgItem) return hWnd; } return NULL; } It's strange! No pains, no gains.

                        W Offline
                        W Offline
                        Williams
                        wrote on last edited by
                        #14

                        Its really very strange, I didn´t no changes but the path to test dialog.Now I think that there is nothing more to do!:cool:

                        R 1 Reply Last reply
                        0
                        • W Williams

                          Its really very strange, I didn´t no changes but the path to test dialog.Now I think that there is nothing more to do!:cool:

                          R Offline
                          R Offline
                          RichardWdy
                          wrote on last edited by
                          #15

                          Sorry about my troubling you. I have to send my whole project to you. Plx take some time to help me. Thanks. Richard Woo No pains, no gains.

                          W 1 Reply Last reply
                          0
                          • R RichardWdy

                            Sorry about my troubling you. I have to send my whole project to you. Plx take some time to help me. Thanks. Richard Woo No pains, no gains.

                            W Offline
                            W Offline
                            Williams
                            wrote on last edited by
                            #16

                            Ok. I will try.:)

                            R 1 Reply Last reply
                            0
                            • W Williams

                              Ok. I will try.:)

                              R Offline
                              R Offline
                              RichardWdy
                              wrote on last edited by
                              #17

                              Have you received my email with the 2 programs? No pains, no gains.

                              W 1 Reply Last reply
                              0
                              • R RichardWdy

                                Have you received my email with the 2 programs? No pains, no gains.

                                W Offline
                                W Offline
                                Williams
                                wrote on last edited by
                                #18

                                No. try again.

                                R 1 Reply Last reply
                                0
                                • W Williams

                                  No. try again.

                                  R Offline
                                  R Offline
                                  RichardWdy
                                  wrote on last edited by
                                  #19

                                  Hi, I tried another way and it did work! I used EnumChildWindows function to enumerate all child windows of the dialog and I could get the handle of the edit control through a callback function. Thanks for help. Richard Woo No pains, no gains.

                                  W 1 Reply Last reply
                                  0
                                  • R RichardWdy

                                    Hi, I tried another way and it did work! I used EnumChildWindows function to enumerate all child windows of the dialog and I could get the handle of the edit control through a callback function. Thanks for help. Richard Woo No pains, no gains.

                                    W Offline
                                    W Offline
                                    Williams
                                    wrote on last edited by
                                    #20

                                    Congratulations! Glad to know you! :-D

                                    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