最近写了一个小程序,当用户点击最小化按钮的时候,在任务栏上显示一个小图标。类似MSN Mobile。开始的时候看了好多实现。最终还是看了MSN,找到了结果。
下面是我的实现代码,其实很简单的。在MFC中实际上只需响应一个函数,然后把下面的代码拷贝过去就可以了。
SHNOTIFICATIONDATA sn = {0};
sn.cbStruct = sizeof(sn);
sn.dwID = 1;
//SHNP_ICONIC
sn.npPriority = SHNP_ICONIC;
sn.csDuration = 5;
sn.hicon = LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_MESSAGE));
sn.clsid = CLSID_SHNAPI_ICON;
sn.grfFlags = 0;
sn.pszTitle = TEXT("LearnerAgent");
sn.pszHTML = TEXT("<html><body></body></html>");
sn.rgskn[0].pszTitle = TEXT("Dismiss");
sn.rgskn[0].skc.wpCmd = 100;
sn.pszTodaySK = TEXT("!BC");
sn.pszHTML = TEXT("<html><body><form method=\"POST\" action=><p>The main window was minilized. <font color=\"#0000FF\"><b>minilized</b></font>.</p><p align=right><input type=button name='cmd:10' value='OK'> <input type=button name='cmd:2' value='Show'></p></body></html>");
sn.npPriority = SHNP_INFORM;
SHNotificationUpdate(SHNUM_PRIORITY, &sn);
SHNotificationUpdate(SHNUM_HTML,&sn);
SHNotificationAdd(&sn);