C++ WIN10通知庫:WinToast

項(xiàng)目地址:https://github.com/mohabouje/WinToast

效果圖

非常簡(jiǎn)單,把.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;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容