下载
项目地址: https://github.com/mohabouje/WinToast 源码就两个文件: wintoastlib.h 和 wintoastlib.cpp github进不去的话,可以使用vckpg安装. 或者 百度网盘:https://pan.baidu.com/s/1bT6gBG742cL89pitl0m-IQ
效果
当然还有更多功能, 添加按钮,响应用户操作(例如关闭,点击等)
示例
#include<string>
#include<wintoast/wintoastlib.h>
class MyToastHandler:public WinToastLib::IWinToastHandler{
public:
void toastActivated()const {
std::cout << "The user clicked in this toast" << std::endl;
exit(0);
}
void toastActivated(int actionIndex)const {
std::cout << "The user clicked on action #" << actionIndex << std::endl;
exit(16 + actionIndex);
}
void toastDismissed(WinToastDismissalReason state) const {
switch (state) {
case UserCanceled:
std::cout << "The user dismissed this toast" << std::endl;
exit(1);
break;
case TimedOut:
std::cout << "The toast has timed out" << std::endl;
exit(2);
break;
case ApplicationHidden:
std::cout << "The application hid the toast using ToastNotifier.hide()" << std::endl;
exit(3);
break;
default:
std::cout << "Toast not activated" << std::endl;
exit(4);
break;
}
}
void toastFailed() const {
std::wcout << L"Error showing current toast" << std::endl;
exit(5);
}
};
static void ShowNotification(std::wstring& appName, std::wstring& firstLine, std::wstring& secondLine) {
std::wstring appUserModelID = L"Fucker's APP'ID";
WinToastLib::WinToast::instance()->setAppName(appName);
WinToastLib::WinToast::instance()->setAppUserModelId(appUserModelID);
WinToastLib::WinToastTemplate toast(WinToastLib::WinToastTemplate::Text02);
toast.setTextField(firstLine, WinToastLib::WinToastTemplate::FirstLine);
toast.setExpiration(false);
if (WinToastLib::WinToast::instance()->initialize()) {
WinToastLib::WinToast::instance()->showToast(toast, new MyToastHandler());
Sleep(10000);
}
}
|