📄 notify.cpp
字号:
break;
case CUSTOM_NOTIFICATION:
pCurrentNotification->dwID = g_iIDCounter;
pCurrentNotification->clsid = guidNotifyApp;
pCurrentNotification->npPriority = g_shnpNotifyType;
pCurrentNotification->csDuration = g_iConvertedTime;
pCurrentNotification->hwndSink = hDlg;
pCurrentNotification->pszHTML = g_szCustomHTMLSampleText;
pCurrentNotification->hicon = hIcon;
pCurrentNotification->cbStruct = sizeof(SHNOTIFICATIONDATA);
pCurrentNotification->pszTitle = g_szCustomTitle;
pCurrentNotification->grfFlags = g_dwCustomFlags;
g_iIDCounter++;
SHNotificationAdd(pCurrentNotification);
break;
default:
pCurrentNotification->dwID = g_iIDCounter;
pCurrentNotification->clsid = guidNotifyApp;
pCurrentNotification->npPriority = SHNP_INFORM;
pCurrentNotification->csDuration = 20;
pCurrentNotification->hwndSink = hDlg;
pCurrentNotification->pszHTML = IDS_DEFAULTHTMLMESSAGE;
pCurrentNotification->hicon = hIcon;
pCurrentNotification->cbStruct = sizeof(SHNOTIFICATIONDATA);
pCurrentNotification->pszTitle = IDS_DEFAULTTITLE;
pCurrentNotification->grfFlags = NULL;
g_iIDCounter++;
SHNotificationAdd(pCurrentNotification);
break;
}
break;
// if the user clicks the custom dialog
case IDC_CUSTOM:
// check and see of the user has Custom Selected
hPriorityListCtrl = GetDlgItem(hDlg, IDC_NOTIFICATIONPRIORITY);
iItemNumber = SendMessage(hPriorityListCtrl, CB_GETCURSEL, 0, 0);
shnpNotifyType =(SHNP)SendMessage(hPriorityListCtrl, CB_GETITEMDATA,(WPARAM)iItemNumber, 0);
if (shnpNotifyType == CUSTOM_NOTIFICATION)
{
DialogBox(g_hInst,(LPCTSTR)IDD_CUSTOMOPTIONS, NULL,(DLGPROC)CustomOptions);
}
else
{
// change the selection to custom and proceed to the dialog
iItemNumber = SendMessage(hPriorityListCtrl, CB_FINDSTRINGEXACT,(WPARAM)-1,(LPARAM)(LPCSTR)IDS_CUSTOM);
SendMessage(hPriorityListCtrl, CB_SETCURSEL,(WPARAM)iItemNumber, 0);
DialogBox(g_hInst,(LPCTSTR)IDD_CUSTOMOPTIONS, NULL,(DLGPROC)CustomOptions);
}
break;
// if user clicks remove
case IDC_REMOVE:
hRemoveListCtrl = GetDlgItem(hDlg, IDC_REMOVELIST);
iItemNumber = SendMessage(hRemoveListCtrl, LB_GETCURSEL, 0, 0);
iRemoveID =(int)SendMessage(hRemoveListCtrl, LB_GETITEMDATA,(WPARAM)iItemNumber, 0);
SendMessage(hRemoveListCtrl, LB_DELETESTRING,(WPARAM)iItemNumber, 0);
RemoveNotification(iRemoveID);
break;
case IDOK:
EndDialog(hDlg, LOWORD(wParam));
break;
// this is called if the user clicks OK(the HREF is cmd:10)
case 10:
wsprintf(pszID, TEXT("%i"),(int)lParam);
hRemoveListCtrl = GetDlgItem(hDlg, IDC_REMOVELIST);
iItemNumber = SendMessage(hRemoveListCtrl, LB_FINDSTRINGEXACT,(WPARAM)-1,(LPARAM)(LPCSTR)pszID);
SendMessage(hRemoveListCtrl, LB_DELETESTRING,(WPARAM)iItemNumber, 0);
RemoveNotification((int)lParam);
// must post message since notificaiton waits for procedure to end before closing bubble
// and adding a messagebox would cause it to wait forever
PostMessage(hDlg, WM_MESSAGEBOX, 0, 0);
break;
default:
break;
}
break;
}
}
return FALSE;
}
// this is a dialog procedure for the custom dialog
LRESULT CALLBACK CustomOptions(
HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM lParam
)
{
SHINITDLGINFO shidi;
HWND hPriorityListCtrl;
HWND hCheckBox = NULL;
int iCurrentItem = 0;
int iItemNumber = 0;
switch (message)
{
case WM_INITDIALOG:
// Create a Done button and size it.
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
g_dwCustomFlags = NULL;
// get the combo box handle and add the priority items to it
hPriorityListCtrl = GetDlgItem(hDlg, IDC_PRIORITYLIST);
iCurrentItem = SendMessage(hPriorityListCtrl, CB_ADDSTRING, NULL,(LPARAM)(LPCTSTR)IDS_SHNP_INFORM);
SendMessage(hPriorityListCtrl, CB_SETITEMDATA,(WPARAM)iCurrentItem,(LPARAM)(DWORD)(SHNP)SHNP_INFORM);
iCurrentItem = SendMessage(hPriorityListCtrl, CB_ADDSTRING, NULL,(LPARAM)(LPCTSTR)IDS_SHNP_ICONIC);
SendMessage(hPriorityListCtrl, CB_SETITEMDATA,(WPARAM)iCurrentItem,(LPARAM)(DWORD)(SHNP)SHNP_ICONIC);
// set the inform item as the default
SendMessage(hPriorityListCtrl, CB_SETCURSEL, 0, 0);
// fill out the defualt time of 10 seconds in the time edit box
SetDlgItemText(hDlg, IDC_SECONDS, IDS_DEFUALT_CUSTOM_TIME);
// fill out the title
SetDlgItemText(hDlg, IDC_TITLESOURCE, IDS_CUSTOM_TITLE);
// fill out the HTML body
SetDlgItemText(hDlg, IDC_HTMLSOURCE, IDS_CUSTOM_HTML_SAMPLE);
break;
case WM_COMMAND:
if (LOWORD(wParam)== IDOK)
{
// collect all of what the user entered
// get seconds
GetDlgItemText(hDlg, IDC_SECONDS, g_szCustomSecs, MAX_STRINGLEN);
g_iConvertedTime = _ttoi(g_szCustomSecs);
// check for invalid time
if (g_iConvertedTime == 0)
{
MessageBox(NULL, TEXT("Please enter a correct time value."), TEXT("Custom Problem"), NULL);
return FALSE;
}
else
{
// get the title
GetDlgItemText(hDlg, IDC_TITLESOURCE, g_szCustomTitle, MAX_STRINGLEN);
// get the HTML body
GetDlgItemText(hDlg, IDC_HTMLSOURCE, g_szCustomHTMLSampleText, MAX_STRINGLEN);
// get what priority the user selected
// Get the Selected Priority for the Notification
hPriorityListCtrl = GetDlgItem(hDlg, IDC_PRIORITYLIST);
iItemNumber = SendMessage(hPriorityListCtrl, CB_GETCURSEL, 0, 0);
g_shnpNotifyType =(SHNP)SendMessage(hPriorityListCtrl, CB_GETITEMDATA,(WPARAM)iItemNumber, 0);
// get checkbox selections
hCheckBox = GetDlgItem(hDlg, IDC_SHNF_STRAIGHTTOTRAY);
if (SendMessage(hCheckBox, BM_GETCHECK, 0, 0)== BST_CHECKED)
{
g_dwCustomFlags = g_dwCustomFlags | SHNF_STRAIGHTTOTRAY;
}
hCheckBox = GetDlgItem(hDlg, IDC_SHNF_CRITICAL);
if (SendMessage(hCheckBox, BM_GETCHECK, 0, 0)== BST_CHECKED)
{
g_dwCustomFlags = g_dwCustomFlags | SHNF_CRITICAL;
}
hCheckBox = GetDlgItem(hDlg, IDC_SHNF_FORCEMESSAGE);
if (SendMessage(hCheckBox, BM_GETCHECK, 0, 0)== BST_CHECKED)
{
g_dwCustomFlags = g_dwCustomFlags | SHNF_FORCEMESSAGE;
}
EndDialog(hDlg, LOWORD(wParam));
PostMessage(g_hDlg, WM_COMMAND, IDC_ADD, NULL);
return TRUE;
}
}
break;
}
return FALSE;
}
//Add a node to the linked list(MFC Linked List)
SHNOTIFICATIONDATA* CreateAndAddNotification()
{
SHNOTIFICATIONDATA* pshndTemp =(SHNOTIFICATIONDATA*)malloc( sizeof(SHNOTIFICATIONDATA));
if (pshndTemp)
{
g_pList->AddTail((void*)pshndTemp);
}
return pshndTemp;
}
// remove a node with the speficied dwID
BOOL RemoveNotification(
DWORD dwID
)
{
BOOL bFound = FALSE;
int iIndex = 0;
POSITION tempPosition;
SHNOTIFICATIONDATA* pshndTemp;
while (!bFound &&(iIndex < g_pList->GetCount()))
{
tempPosition = g_pList->FindIndex(iIndex);
pshndTemp =(SHNOTIFICATIONDATA*)g_pList->GetAt(tempPosition);
if (pshndTemp->dwID == dwID)
{
bFound = TRUE;
SHNotificationRemove(&guidNotifyApp, dwID);
free(pshndTemp);
g_pList->RemoveAt(tempPosition);
}
else
{
iIndex++;
}
}
return bFound;
}
// function removed all nodes in the list
// called when the programme exits
void RemoveNotificationAll()
{
SHNOTIFICATIONDATA* pshndToDelete;
POSITION tempPosition;
int iListSize = g_pList->GetCount();
for (int i = 0; i < iListSize; i++)
{
tempPosition = g_pList->GetHeadPosition();
pshndToDelete =(SHNOTIFICATIONDATA*)g_pList->GetAt(tempPosition);
SHNotificationRemove(&guidNotifyApp, pshndToDelete->dwID);
free(pshndToDelete);
g_pList->RemoveHead();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -