📄 notedemo.cpp
字号:
}
memset (&nt, 0, sizeof (CE_NOTIFICATION_TRIGGER));
nt.dwSize = sizeof (CE_NOTIFICATION_TRIGGER);
nt.dwType = CNT_PERIOD;
nt.lpszApplication = szExeName;
nt.lpszArguments = szArgs;
nt.stStartTime = st;
nt.stEndTime = ste;
GetModuleFileName (hInst, szExeName, sizeof (szExeName));
hNotify = CeSetUserNotificationEx (0, &nt, &g_ceun);
// Tell the user the notification was set.
if (hNotify)
wsprintf (szText, TEXT ("User notification set for %d:%02d:%02d"),
st.wHour, st.wMinute, st.wSecond);
else
wsprintf (szText, TEXT ("User notification failed. rc = %d"),
GetLastError());
MessageBox (hWnd, szText, szAppName, MB_OK);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandConfigUserNotification - Process Config user
// notification button.
//
LPARAM DoMainCommandConfigUserNotification (HWND hWnd, WORD idItem,
HWND hwndCtl, WORD wNotifyCode) {
// Display the system-provided configuration dialog.
CeGetUserNotificationPreferences (hWnd, &g_ceun);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandAddSysNotification - Process Add Sys notify button.
//
LPARAM DoMainCommandAddSysNotification (HWND hWnd, WORD idItem,
HWND hwndCtl, WORD wNotifyCode) {
DialogBox (hInst, TEXT ("SysNotifyConfig"), hWnd,
SetEventNotifyDlgProc);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandAddTimerNotification - Process add timer notify button.
//
LPARAM DoMainCommandAddTimerNotification (HWND hWnd, WORD idItem,
HWND hwndCtl, WORD wNotifyCode) {
SYSTEMTIME st;
HANDLE hNotify;
CE_NOTIFICATION_TRIGGER nt;
TCHAR szExeName[MAX_PATH], szText[128];
TCHAR szArgs[128] = TEXT("This is my timer notification string.");
// Initialize time structure with local time.
GetLocalTime (&st);
// Do a trivial amount of error checking.
if (st.wMinute == 59) {
st.wHour++;
st.wMinute = 0;
} else
st.wMinute++;
memset (&nt, 0, sizeof (CE_NOTIFICATION_TRIGGER));
nt.dwSize = sizeof (CE_NOTIFICATION_TRIGGER);
nt.dwType = CNT_TIME;
nt.lpszApplication = szExeName;
nt.lpszArguments = szArgs;
nt.stStartTime = st;
StringCchCopy (szExeName, dim(szExeName), NAMED_EVENT_PREFIX_TEXT);
StringCchCat (szExeName, dim(szExeName), szEventName);
// Set the notification.
hNotify = CeSetUserNotificationEx (0, &nt, NULL);
if (hNotify)
wsprintf (szText, TEXT ("Timer notification set for %d:%02d:%02d"),
st.wHour, st.wMinute, st.wSecond);
else
wsprintf (szText, TEXT ("Timer notification failed. rc = %d"),
GetLastError());
MessageBox (hWnd, szText, szAppName, MB_OK);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandClearNotifications - Clear all notifications pointing
// to this application. Note: this is a fairly large stack frame.
//
LPARAM DoMainCommandClearNotifications (HWND hWnd, WORD idItem,
HWND hwndCtl, WORD wNotifyCode) {
PBYTE pBuff = NULL;
PCE_NOTIFICATION_INFO_HEADER pnih;
HANDLE hNotHandles[128]; // Assume this is large enough.
int rc, nCnt = 0;
TCHAR szExeName[MAX_PATH], szText[128];
DWORD i, dwSize, nHandCnt = 0;
// Get our filename.
GetModuleFileName (hInst, szExeName, sizeof (szExeName));
pBuff = (PBYTE)LocalAlloc (LPTR, 8192);
if (!pBuff) {
MessageBox (hWnd, TEXT ("Out of memory"), szAppName, MB_OK);
return 0;
}
rc = CeGetUserNotificationHandles (hNotHandles, dim (hNotHandles),
&nHandCnt);
if (rc) {
for (i = 0; i < nHandCnt; i++) {
// Query info on a single handle.
rc = CeGetUserNotification (hNotHandles[i], 8192,
&dwSize, pBuff);
if (rc) {
pnih = (PCE_NOTIFICATION_INFO_HEADER)pBuff;
if (!lstrcmp (pnih->pcent->lpszApplication, szExeName)){
if (CeClearUserNotification (pnih->hNotification))
nCnt++;
}
}
}
wsprintf (szText, TEXT ("Cleared %d notifications"), nCnt);
MessageBox (hWnd, szText, szAppName, MB_OK);
} else
MessageBox (hWnd, TEXT ("Could not query handles"),
szAppName, MB_OK);
LocalFree (pBuff);
return 0;
}
//----------------------------------------------------------------------
// MySetEventNotification - Sets event notifications
//
int MySetEventNotification (HWND hWnd, DWORD dwEvent) {
TCHAR szArgs[] = TEXT("This is my event notification string.");
CE_NOTIFICATION_TRIGGER nt;
HANDLE hNotify;
TCHAR szExeName[MAX_PATH], szText[128];
memset (&nt, 0, sizeof (CE_NOTIFICATION_TRIGGER));
nt.dwSize = sizeof (CE_NOTIFICATION_TRIGGER);
nt.dwType = CNT_EVENT;
nt.dwEvent = dwEvent;
nt.lpszApplication = szExeName;
nt.lpszArguments = szArgs;
GetModuleFileName (hInst, szExeName, sizeof (szExeName));
// Set the notification.
hNotify = CeSetUserNotificationEx (0, &nt, NULL);
if (hNotify)
wsprintf (szText, TEXT ("Event notification set for %08x"),
dwEvent);
else
wsprintf (szText, TEXT("Set Event notification failed rc: %d"),
GetLastError());
MessageBox (hWnd, szText, szAppName, MB_OK);
return 0;
}
//----------------------------------------------------------------------
// Add2List - Add string to the report list box.
//
void Add2List (HWND hWnd, LPTSTR lpszFormat, ...) {
int i, nBuf;
TCHAR szBuffer[512];
va_list args;
va_start(args, lpszFormat);
nBuf = _vstprintf_s (szBuffer, dim (szBuffer), lpszFormat, args);
i = SendDlgItemMessage (hWnd, IDD_OUTPUT, WM_SETTEXT, 0,
(LPARAM)(LPCTSTR)szBuffer);
va_end(args);
}
//======================================================================
// SetEventNotifyDlgProc - Callback function for Event dialog box
//
BOOL CALLBACK SetEventNotifyDlgProc (HWND hWnd, UINT wMsg,
WPARAM wParam, LPARAM lParam) {
DWORD dwEvent;
int i;
switch (wMsg) {
case WM_COMMAND:
{
WORD idItem = LOWORD (wParam);
switch (idItem) {
case IDOK:
dwEvent = 0;
for (i = 0; i < dim (SysTypeBtns); i++) {
if (IsDlgButtonChecked (hWnd,
SysTypeBtns[i].dwID) == 1)
dwEvent |= SysTypeBtns[i].dwFlag;
}
// Call my set event notification function above.
MySetEventNotification (hWnd, dwEvent);
EndDialog (hWnd, 1);
return TRUE;
case IDCANCEL:
EndDialog (hWnd, 0);
return TRUE;
}
}
break;
}
return FALSE;
}
//======================================================================
// MonitorThread - Monitors event for timer notificaiton
//
DWORD WINAPI MonitorThread (PVOID pArg) {
int rc;
while (g_fContinue) {
rc = WaitForSingleObject (g_hNoteEvent, INFINITE);
if (!g_fContinue)
break;
if (rc == WAIT_OBJECT_0)
SendMessage (g_hMain, MYMSG_TELLNOTIFY, 0, (LPARAM)g_hNoteEvent);
else
break;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -