Problem about injecting a dll to another process and use it to send menu message issues.
-
I write a simple dll and inject to another process, i communicate with the target process by sending message via a named pipe. But now, the problem is that, although i can retrieve a top-level window of the target process,i will get no response if i send menu messages to it(the hwnd i retrieved, using EnumWindows, no matter i send the messages in the callback functions of EnumWindows or not, the results are the same). So, i think, the hwnd handle i retrieved was not the target hwnd handle witch was responsible to such activity. But, how could i get the right hwnd to handle these menu messages? Thanks
-
I write a simple dll and inject to another process, i communicate with the target process by sending message via a named pipe. But now, the problem is that, although i can retrieve a top-level window of the target process,i will get no response if i send menu messages to it(the hwnd i retrieved, using EnumWindows, no matter i send the messages in the callback functions of EnumWindows or not, the results are the same). So, i think, the hwnd handle i retrieved was not the target hwnd handle witch was responsible to such activity. But, how could i get the right hwnd to handle these menu messages? Thanks
i will get no response if i send menu messages to it(the hwnd i retrieved, using EnumWindows, no matter i send the messages in the callback functions of EnumWindows or not, the results are the same) Can you please post some code lines (sending menu messages) ?
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:**** -
i will get no response if i send menu messages to it(the hwnd i retrieved, using EnumWindows, no matter i send the messages in the callback functions of EnumWindows or not, the results are the same) Can you please post some code lines (sending menu messages) ?
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:****I wrote enumwindows callback function like following:
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
DWORD procId;
GetWindowThreadProcessId(hwnd,&procId);
log_message("Main window search callback function is called.");
if(procId==(DWORD)lParam){....the message would to be send here return FALSE; }
return TRUE;
}I send the menu message in two ways: 1. HMENU trayMenu = GetMenu(hwnd); if(trayMenu!=NULL){//usually equal to NULL, and according to the failure in method 2(send msg no response) i think i got the wrong hwnd handle HMENU subMenu = GetSubMenu(trayMenu,0); if(subMenu!=NULL){ DWORD menuItemId=GetMenuItemID(subMenu,0); if(menuItemId!=-1) SendMessage(hwnd,WM_COMMAND,menuItemId,0); } } 2.Because i can get the menu resource id, and, this code is implemented in a injected dll to the target process, so, there is a second method here: HMENU trayMenu = LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDM_MENU)); if(trayMenu!=NULL){//successfully always ...the other code looks the same with the method 1, but the target process's specified routine will not be actived, because its no response.
-
I wrote enumwindows callback function like following:
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
DWORD procId;
GetWindowThreadProcessId(hwnd,&procId);
log_message("Main window search callback function is called.");
if(procId==(DWORD)lParam){....the message would to be send here return FALSE; }
return TRUE;
}I send the menu message in two ways: 1. HMENU trayMenu = GetMenu(hwnd); if(trayMenu!=NULL){//usually equal to NULL, and according to the failure in method 2(send msg no response) i think i got the wrong hwnd handle HMENU subMenu = GetSubMenu(trayMenu,0); if(subMenu!=NULL){ DWORD menuItemId=GetMenuItemID(subMenu,0); if(menuItemId!=-1) SendMessage(hwnd,WM_COMMAND,menuItemId,0); } } 2.Because i can get the menu resource id, and, this code is implemented in a injected dll to the target process, so, there is a second method here: HMENU trayMenu = LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDM_MENU)); if(trayMenu!=NULL){//successfully always ...the other code looks the same with the method 1, but the target process's specified routine will not be actived, because its no response.
Try to find out whether you are retrieving ID of the right menu item. Call GetMenuString() for that item and debug print it. If you send the message for menu item which consists of submenu, that won't help you (application doesn't display out the submenu as a result).
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:**** -
Try to find out whether you are retrieving ID of the right menu item. Call GetMenuString() for that item and debug print it. If you send the message for menu item which consists of submenu, that won't help you (application doesn't display out the submenu as a result).
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:****im sorry to reply so latter. i have gone to another city. and i know them problem now, i got the right menu, menuitems and menuIDs, but sent the menu message to a wrong hwnd. The program has more than one toplevel hwnd, so, i retieve all its top level hwnds and send menu message it them. then, when i got the right hwnd, the message would send successfully.