How to send message to another program?
-
I wnat to run another prog. in my prog. So I need seng messare to the prog. I have two questions: 1.What's wrong with the following code and How to send message to a check ctrl? HWND hEditFilter = GetDlgItem(g_hExefile, ID_CHECK_EDIT); // return NULL??? // g_hExefile is the handle of another prog's dialog. PostMessage(g_hExefile, BM_SETCHECK, ID_CHECK_EDIT, 0); // no respond // I want to set the check ctrl in FALSE state. 2.How to send message to a commom dialog(like OK button)? Thanks. No pains, no gains.
-
I wnat to run another prog. in my prog. So I need seng messare to the prog. I have two questions: 1.What's wrong with the following code and How to send message to a check ctrl? HWND hEditFilter = GetDlgItem(g_hExefile, ID_CHECK_EDIT); // return NULL??? // g_hExefile is the handle of another prog's dialog. PostMessage(g_hExefile, BM_SETCHECK, ID_CHECK_EDIT, 0); // no respond // I want to set the check ctrl in FALSE state. 2.How to send message to a commom dialog(like OK button)? Thanks. No pains, no gains.
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.
-
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.
Thanks for giving me help. I think the code may has some problem.(I didn't test it yet.) I want to send BM_SETCHECK message to an edit(ID = ID_EDIT_START) and your code showed that you send BM_SETCHECK message to main window. It won't work. So I need to get the edit control's handle (It's where my problem really exists, I can't get the handle). By the way, the external dialog program has several edit controls. Thanks again. Richard Woo No pains, no gains.
-
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.
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.
-
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.
-
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.
-
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.
-
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.
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.
-
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.
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.
-
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.
-
I send you 2 apps. Plx check. Thanks a lot. No pains, no gains.
-
I send you 2 apps. Plx check. Thanks a lot. No pains, no gains.
-
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.
-
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.
-
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:
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.
-
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.
-
Have you received my email with the 2 programs? No pains, no gains.
-
Have you received my email with the 2 programs? No pains, no gains.
-
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.
-
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.