First of all, I would like to thank Jia baili and yonsm, the cosmic youth, for their answers to my questions and posts embedded in the snow forum. I have no idea about them. And thanks to Brother Shan from the mobileside Development Group this afternoon. The key to solving this problem is as shown in. This is a small trap that Microsoft has made. If you're lazy, you don't even know that you should look for the handle of the window ......
Mappings: 1. Dialing
2. In the call (the main character of this article)
3. The call ends.
The class name controls in these three windows have the same names. The only difference is the text names of those buttons, and the call status window and call end window are dynamically switched, that is, you can only see the call end window in normal state, while the call end window is killed by a bunch of ms_phone_button controls during the call. The ID of the "open speaker" button is idc_speaker (which is known when cprog is analyzed). You can use getdlgctrlid to obtain that its ID is 23016. # Define idc_speaker 23016 Then we need to obtain the messages sent to this window and the specified button. Therefore, we need to subclass The subclass. wince does not have setwindowshook and other related functions, and can only be implemented using setwindowlong. I don't talk nonsense, but I still need to post code to save my time. Today I am busy for a day and have a DLL injection, and I have to do it again. I am exhausted ...... The Code demonstrates how to control the "open speaker" button and "Open speaker" menu. Some IDs in the code come from actual analysis and are not officially declared. Code:# Define idm_speaker 21426 # define idc_speaker 23016 unsigned int timerid; static wndproc s_oldwndproc = NULL; static wndproc s_oldspkbtnproc = NULL; handle s_hexit = NULL; hwnd Limit = NULL; lresult callback newspkbtnproc (hwnd, uint umsg, wparam, lparam) {If (timerid! = 0) {killtimer (null, timerid); timerid = 0;} switch (umsg) {Case wm_lbuttondown: {setspeakerphone (); break;} return callwindowproc (s_oldspkbtnproc, hwnd, umsg, wparam, lparam);} lresult callback newwndproc (hwnd, uint umsg, wparam, lparam) {If (timerid! = 0) {killtimer (null, timerid); timerid = 0;} switch (umsg) {Case wm_command: {// setwindowtext (lpcallstatwin, text ("wm_command ")); if (loword (wparam) = idm_speaker) setspeakerphone (); break;} case wm_size: {If (wparam = size_minimized) _ debug (L "size_minimized "); _ debug (L "wm_size: wparam: % 08x, lparam: % 08x", wparam, lparam); break;} case wm_syscommand: {_ debug (L "SYSCOMMAND "); break;} case wm_activate :{_ Debug (L "wm_activate: wparam: % 08x, lparam: % 08x", wparam, lparam); break;} case wm_killfocus: {_ debug (L "wm_killfocus: wparam: % 08x, lparam: % 08x ", wparam, lparam); break;} case wm_destroy: {If (s_hexit) {// _ debug (L" posting exit MSG... "); setevent (s_hexit);} break;} return callwindowproc (s_oldwndproc, hwnd, umsg, wparam, lparam);} int sethook (hwnd lphookhwnd) {s_hexit = createevent (null, false, false, Null); If (lphookhwnd! = NULL) {lpcallstatwin = lphookhwnd; Signature = (wndproc) getwindowlong (lphookhwnd, callback); setwindowlong (lphookhwnd, callback, (DWORD) newwndproc); Signature = (wndproc) getwindowlong (response, response); setwindowlong (response, response, (DWORD) newspkbtnproc); waitforsingleobject (s_hexit, infinite); setwindowlong (lphookhwnd, response, (DWORD) s_oldwndproc ); Setwindowlong (gradient, gwl_wndproc, (DWORD) handle);} return 0;} hwnd findphonehandle () {hwnd lpnextwindow = NULL; hwnd lpforeground = NULL; tchar lpclassname [64]; int lpcontrolid; // lpwstr lpcontroltext; // lpstr test; lpforeground = getforegroundwindow (); If (lpforeground = NULL) return 0; lpnextwindow = getwindow (lpforeground, gw_child ); lpnextwindow = getwindow (lpnextwindow, GW _ Hwndfirst); While (lpnextwindow! = 0) {getclassname (lpnextwindow, lpclassname, 64); // _ debug (L "main handle: % d, classname: % s", lpforeground, lpclassname); If (! _ Tcscmp (lpclassname, text ("ms_phone_button") {// confirm that it is a button on the phone interface and start to judge idc_speaker lpcontrolid = getdlgctrlid (lpnextwindow ); if (lpcontrolid = idc_speaker) {// _ debug (L "speaker found"); lpspeakerphonebtn = lpnextwindow; hwnd lprealhandle = getparent (lpnextwindow ); // _ debug (L "parenthandle: % d, lpforeground: % d", lprealhandle, lpforeground); If (lprealhandle! = NULL) {return lprealhandle;} return lpforeground;} lpnextwindow = getwindow (lpnextwindow, gw_hwndnext);} return 0;} void callback timeproc (hwnd, uint message, uint idtimer, DWORD dwtime) {hwnd lpcallstatuswindow; lpcallstatuswindow = findphonehandle (); If (lpcallstatuswindow! = 0) {sethook (lpcallstatuswindow) ;}} int winapi winmain (hinstance, hinstance hprevinstance, lptstr lpcmdline, int ncmdshow) {// icationicationcondition condition; timerid = settimer (null,, timeproc); MSG; while (getmessage (& MSG, 0) {// receives the wm_timer message and processes it // _ debug (L "MSG. message: % d ", MSG. message); If (MSG. message = wm_timer) {dispatchmessage (& MSG) ;}} return 0 ;} |