In some cases, we may need to prevent synchronization between the mobile phone and the computer. We can call the activesyncstop API to meet our requirements, but when can we call it?
Of course, we still need to implement it through callback. Here there are two methods: registrynotifywindow, registrynotifycallback, and registrypolicywindow will send the specified message to the specified window, registrypolicycallback is the custom callback function that sends a specified message. We need to monitor the key value cradled in HKEY_LOCAL_MACHINE // system // state // hardware, which is a judgment value for cable insertion.
# Define wm_change_crdl (wm_user+ 1000)
Const wchar c_wszhardwarestatstore [] = l "system/State/hardware ";
Const wchar c_wszcradled [] = l "Cradled ";
Bool m_crdlreg;
Icationicationcondition NC;
NC. ctcomparisontype = reg_ct_anychange;
NC. dwmask = 0 xffffffff;
NC. targetvalue. DW = 0;
HR = registrypolicywindow (
HKEY_LOCAL_MACHINE,
C_wszhardwarestatstore,
C_wszcradled,
Hwnd, // The specified message receiving window
Wm_change_crdl, // The specified custom message
Null,
& NC,
& M_crdlreg
);
The following is the processing of the receiving window, so that the synchronization will be interrupted every time the user inserts a cable.
Lresult callback dlgproc (hwnd hdlg, uint message, wparam, lparam)
...{
Switch (Message)
...{
Case wm_create:
Break;
//... Omitting other messages
Case wm_change_crdl:
Activesyncstop (); // stop synchronization such as address book
Setsystempowerstate (null, power_state_off, 0); // interrupt Data Synchronization
Break;
Default:
Return: defwindowproc (hdlg, message, wparam, lparam );
}
Return lresult;
}
You can disable the listener if (m_crdlreg) by calling registryclosenotification)
...{
Registryclosenotification (m_crdlreg );
M_crdlreg = 0;
}
The preliminary functions have been introduced. Of course, you can also monitor the Synchronizing key values under HKEY_LOCAL_MACHINE // system/State/ActiveSync for the same operation. The code is similar and I will not list them one by one.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/prince0823/archive/2007/11/22/1897701.aspx