The system above wm5 uses the notification broker mechanism to obtain the status of all calls.

Source: Internet
Author: User

After checking a lot of information, only the code in one status is triggered for notification broker, but for a function improvement, I need a method for obtaining multiple call statuses (outbound call, incoming call, and call ......) Because the program needs to be triggered proactively, registrynotifyapp is used as the active broker. After checking msdn, it finds that there is no excessive explanation on how the registrypolicyapp can be started in multiple events, continue to translate other msdn, and finally see two lines of text with fuzzy meanings in the interpretation of notificationcondition:
Dwmask
Applies only to DWORD values. This mask is applied to the changed registry value before comparison. by specifying a bit mask, the communications broker notifies the clients only when specific bits in the registry value changes.
This mask is not applied to targetvalue. If dwmask is 0, targetvalue is treated as a string (type reg_sz), otherwise it is treated as type REG_DWORD.

Targetvalue
If the changed value is type REG_SZ, then comparison is done between psz and the changed value. if the changed value is type REG_DWORD, then dwmask is applied to the changed value and then the result is compared to DW. if the changed value is neither REG_SZ nor REG_DWORD, then notification is sent without any comparison. you must set dwmask to-1 to test against the whole doubleword.

As you can see, dwmask =-1 seems to have something fun to do, and immediately write the code for testing:

Code:
#define SN_PHONECALLTALKING_ROOT HKEY_LOCAL_MACHINE#define SN_PHONECALLTALKING_PATH TEXT("System//State//Phone")#define SN_PHONECALLTALKING_VALUE TEXT("Status")#define SN_PHONECALLTALKING_BITMASK 536870912#define SN_PHONECALLCALLING_BITMASK 131072#define SN_PHONEINCOMINGCALL_BITMASK 65536#define MY_NOTIFICATION_NAME TEXT("testnotification")DWORD GetCurrentNotificationStatus(){    DWORD lpPhoneTalking = 0;    HRESULT hr;    hr = RegistryGetDWORD(SN_PHONECALLTALKING_ROOT,       SN_PHONECALLTALKING_PATH,       SN_PHONECALLTALKING_VALUE,       &lpPhoneTalking);    if(SUCCEEDED(hr))    {      if(lpPhoneTalking & SN_PHONECALLTALKING_BITMASK){        return SN_PHONECALLTALKING_BITMASK;      }else if(lpPhoneTalking & SN_PHONECALLCALLING_BITMASK){        return SN_PHONECALLCALLING_BITMASK;      }else if(lpPhoneTalking & SN_PHONEINCOMINGCALL_BITMASK){        return SN_PHONEINCOMINGCALL_BITMASK;      }else{        return lpPhoneTalking;      }    }else{      return 0;    }}HRESULT RegisterNotification(){    HRESULT hr = NULL;    NOTIFICATIONCONDITION nc;    nc.dwMask = -1;    nc.ctComparisonType = REG_CT_ANYCHANGE;    nc.TargetValue.dw = 0x01;    hr = RegistryNotifyApp(SN_PHONECALLTALKING_ROOT, SN_PHONECALLTALKING_PATH,      SN_PHONECALLTALKING_VALUE, MY_NOTIFICATION_NAME, szExeFile,      NULL, NULL, 0x00, RNAF_NONAMEONCMDLINE, &nc);    return hr;}int _tmain(int argc, _TCHAR* argv[]){    GetModuleFileName(NULL,szExeFile,256);    HRESULT hr = RegisterNotification();    LPCTSTR currStatus;    DWORD dStatus;    dStatus=GetCurrentNotificationStatus();    switch(dStatus){      case SN_PHONECALLCALLING_BITMASK:        currStatus=L"Calling";        break;      case SN_PHONECALLTALKING_BITMASK:        currStatus=L"Talking";        break;      case SN_PHONEINCOMINGCALL_BITMASK:        currStatus=L"Incoming";        break;      default:        currStatus=(LPCTSTR)dStatus;    }    MessageBox(GetActiveWindow(),currStatus,TEXT("test"),MB_SETFOREGROUND | MB_ICONINFORMATION | MB_OK);    return 0;}

Execute the program, find the registry and register a new broker "testnotification". Then, test the call phone number and call and answer. Three statuses are obtained successfully.

Therefore, if you want to monitor the overall status of an event in your notification broker program, use dwmask =-1 with ctcomparisontype = reg_ct_anychange.

 

Interception of the call status window of the telephone process and subclass hook in wm6
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 ;}

Http://hi.baidu.com/net%5Flk007/blog/item/8874f635a8c7921990ef395d.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.