📄 syncmanager.cpp
字号:
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hWnd;
mbi.nToolBarId = IDR_MENU;
mbi.hInstRes = g_hInst;
if (!SHCreateMenuBar(&mbi))
{
g_hWndMenuBar = NULL;
}
else
{
g_hWndMenuBar = mbi.hwndMB;
}
#ifndef WIN32_PLATFORM_WFSP
// Initialize the shell activate info structure
memset(&s_sai, 0, sizeof (s_sai));
s_sai.cbSize = sizeof (s_sai);
#endif // !WIN32_PLATFORM_WFSP
#endif // SHELL_AYGSHELL
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
#ifdef SHELL_AYGSHELL
CommandBar_Destroy(g_hWndMenuBar);
#endif // SHELL_AYGSHELL
Unregister();
PostQuitMessage(0);
break;
#if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP)
case WM_ACTIVATE:
// Notify shell of our activate message
SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
break;
case WM_SETTINGCHANGE:
SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
break;
#endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP
// Handle the Cradling Status Change Message
case WM_CHANGE_CRDL_REG:
ShowCradleStatus(wParam);
break;
// Handle the Sync Status Change Message
case WM_CHANGE_SYNC_REG:
ShowSyncStatus(wParam);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
#ifndef WIN32_PLATFORM_WFSP
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
#ifdef SHELL_AYGSHELL
{
// Create a Done button and size it.
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
}
#endif // SHELL_AYGSHELL
return (INT_PTR)TRUE;
case WM_COMMAND:
#ifdef SHELL_AYGSHELL
if (LOWORD(wParam) == IDOK)
#endif
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
case WM_CLOSE:
EndDialog(hDlg, message);
return (INT_PTR)TRUE;
#ifdef _DEVICE_RESOLUTION_AWARE
case WM_SIZE:
{
DRA::RelayoutDialog(
g_hInst,
hDlg,
DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_ABOUTBOX_WIDE) : MAKEINTRESOURCE(IDD_ABOUTBOX));
}
break;
#endif
}
return (INT_PTR)FALSE;
}
#endif // !WIN32_PLATFORM_WFSP
//
// This function initialises the Cradle and Sync Status to be displayed to the user
// By reading the State and Notification Entries
// It then registers for StatStor Notifications using USer-defined Windows Messages.
//
HRESULT OnInit()
{
DWORD val = 0;
GetRegistryCradled(&val);
ShowCradleStatus(val);
GetRegistrySynchronizing(&val);
ShowSyncStatus(val);
// Register for Synchronisation and Cradling Notifications
Register();
return S_OK;
}
//
// This function displays the appropriate Sync status depending on the StatStor Value
//
HRESULT ShowSyncStatus(int val)
{
if (val == 0)
{
SetDlgItemText(g_hCurWndDialog, IDC_SYNC, TEXT("Not Synchronizing"));
}
else if (val == 1)
{
SetDlgItemText(g_hCurWndDialog, IDC_SYNC, TEXT("Synchronizing"));
}
else
{
SetDlgItemText(g_hCurWndDialog, IDC_SYNC, TEXT("UnKnown"));
}
UpdateWindow(g_hCurWndDialog);
return S_OK;
}
//
// This function displays the appropriate Cradle status depending on the StatStor Value
//
HRESULT ShowCradleStatus(int val)
{
if (val == 0)
{
SetDlgItemText(g_hCurWndDialog, IDC_CRADLED, TEXT("Un Cradled"));
}
else if (val == 1)
{
SetDlgItemText(g_hCurWndDialog, IDC_CRADLED, TEXT("Cradled"));
}
else
{
SetDlgItemText(g_hCurWndDialog, IDC_CRADLED, TEXT("UnKnown"));
}
UpdateWindow(g_hCurWndDialog);
return S_OK;
}
//
// This function registers for notifications using the
// State and Notification (StatStor) API's
//
HRESULT Register()
{
HRESULT hr;
NOTIFICATIONCONDITION nc;
//
// Register for the sync value changes
//
nc.ctComparisonType = REG_CT_ANYCHANGE;
nc.dwMask = 0xFFFFFFFF;
nc.TargetValue.dw = 0;
hr = RegistryNotifyWindow(
HKEY_LOCAL_MACHINE,
c_wszHardwareStatStore,
c_wszCradled,
g_hCurWndDialog,
WM_CHANGE_CRDL_REG,
IDC_CRADLED,
&nc,
&g_CrdlReg
);
if (FAILED(hr))
{
goto Error;
}
hr = RegistryNotifyWindow(
HKEY_LOCAL_MACHINE,
c_wszActiveSyncStatStore,
c_wszSynchronizing,
g_hCurWndDialog,
WM_CHANGE_SYNC_REG,
IDC_SYNC,
&nc,
&g_SyncReg
);
if (FAILED(hr))
{
goto Error;
}
Error:
return hr;
}
//
// This function unregisters the Main Window from receiving StatStor notifications.
//
HRESULT Unregister()
{
if (g_CrdlReg)
{
RegistryCloseNotification(g_CrdlReg);
g_CrdlReg = 0;
}
if (g_SyncReg)
{
RegistryCloseNotification(g_SyncReg);
g_SyncReg = 0;
}
return S_OK;
}
//
// This is a Util function to simply read a Registry Key.
//
HRESULT ReadRegistry(HKEY hKey, LPCWSTR wszSubKey, LPCWSTR wszName, DWORD *pdwValue)
{
HRESULT hr = S_OK;
hr = RegistryGetDWORD(hKey, wszSubKey, wszName, pdwValue);
return hr;
}
//
// This function Gets the Cradle Status Statstor Entry
//
HRESULT GetRegistryCradled(DWORD *pdwValue)
{
return ReadRegistry(
HKEY_LOCAL_MACHINE,
c_wszHardwareStatStore,
c_wszCradled,
pdwValue
);
}
//
// This function Gets the Sync Status Statstor Entry
//
HRESULT GetRegistrySynchronizing(DWORD *pdwValue)
{
return ReadRegistry(
HKEY_LOCAL_MACHINE,
c_wszActiveSyncStatStore,
c_wszSynchronizing,
pdwValue
);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -