C++ WIN10通知库:WinToast

项目地址:https://github.com/mohabouje/WinToast

效果图

非常简单,把.h 和.cpp文件加到工程中即可。

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);
    }

};

int main()
{
    std::wstring appUserModelID = L"TEST PROJECT APP'ID";
    WinToastLib::WinToast::instance()->setAppName(L"TEST PROJECT");
    WinToastLib::WinToast::instance()->setAppUserModelId(appUserModelID);
    WinToastLib::WinToastTemplate toast(WinToastLib::WinToastTemplate::ImageAndText02);
    toast.setTextField(L"美女找你聊天", WinToastLib::WinToastTemplate::FirstLine);
    toast.setTextField(L"说得好像真的一样", WinToastLib::WinToastTemplate::SecondLine);
    toast.setImagePath(L"C:\\vsProjects\\tta.jpg");

    toast.setExpiration(false);
    if (WinToastLib::WinToast::instance()->initialize()) {
        WinToastLib::WinToast::instance()->showToast(toast, new MyToastHandler());
    }
    return 0;
}

你可能感兴趣的:(C++ WIN10通知库:WinToast)