diff --git a/.gitignore b/.gitignore
index 77487a9..242984e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,6 +42,3 @@ enc_temp_folder/
build/
cmake-build-*
CMakeLists.txt.user
-
-# CLion
-.idea/
diff --git a/.idea/copyright/WinToast.xml b/.idea/copyright/WinToast.xml
new file mode 100644
index 0000000..d16d728
--- /dev/null
+++ b/.idea/copyright/WinToast.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml
new file mode 100644
index 0000000..17ab555
--- /dev/null
+++ b/.idea/copyright/profiles_settings.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 35b5888..80c25c1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.4...3.27)
-project(wintoastlib VERSION 1.3.2 LANGUAGES CXX)
-set(CMAKE_CXX_STANDARD 11)
+project(wintoastlib VERSION 2.0.0 LANGUAGES CXX)
+set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
@@ -8,11 +8,11 @@ option(WINTOASTLIB_BUILD_EXAMPLES "Compile the examples" ON)
option(WINTOASTLIB_QT_ENABLED "Enable Qt support to build the GUI examples" OFF)
set(WINTOASTLIB_LIBNAME WinToast)
-set(WINTOASTLIB_HEADERS ${CMAKE_CURRENT_LIST_DIR}/include/wintoastlib.h)
-set(WINTOASTLIB_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/wintoastlib.cpp)
+file(GLOB_RECURSE WINTOASTLIB_HEADERS "${CMAKE_CURRENT_LIST_DIR}/include/*.h")
+file(GLOB_RECURSE WINTOASTLIB_SOURCES "${CMAKE_CURRENT_LIST_DIR}/src/*.cpp")
add_library(${WINTOASTLIB_LIBNAME} STATIC ${WINTOASTLIB_HEADERS} ${WINTOASTLIB_SOURCES})
target_include_directories(${WINTOASTLIB_LIBNAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
-target_link_libraries(${WINTOASTLIB_LIBNAME} psapi)
+target_link_libraries(${WINTOASTLIB_LIBNAME} psapi shlwapi user32)
if (${WINTOASTLIB_BUILD_EXAMPLES})
add_subdirectory(examples)
diff --git a/LICENSE.txt b/LICENSE.txt
index 0182078..7784ae9 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,6 +1,6 @@
MIT License
-Copyright (C) 2016-2023 WinToast v1.3.0 - Mohammed Boujemaoui
+Copyright (C) 2016-2025 WinToast - Mohammed Boujemaoui
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
+SOFTWARE.
\ No newline at end of file
diff --git a/examples/console-example/main.cpp b/examples/console-example/main.cpp
index 1dbdaed..692a41c 100644
--- a/examples/console-example/main.cpp
+++ b/examples/console-example/main.cpp
@@ -1,6 +1,7 @@
#include "wintoastlib.h"
+
#include
-#include
+#include
using namespace WinToastLib;
@@ -21,17 +22,17 @@ class CustomHandler : public IWinToastHandler {
exit(0);
}
- void toastDismissed(WinToastDismissalReason state) const {
+ void toastDismissed(DismissalReason state) const {
switch (state) {
- case UserCanceled:
+ case DismissalReason::UserCanceled:
std::wcout << L"The user dismissed this toast" << std::endl;
exit(1);
break;
- case TimedOut:
+ case DismissalReason::TimedOut:
std::wcout << L"The toast has timed out" << std::endl;
exit(2);
break;
- case ApplicationHidden:
+ case DismissalReason::ApplicationHidden:
std::wcout << L"The application hid the toast using ToastNotifier.hide()" << std::endl;
exit(3);
break;
@@ -153,8 +154,8 @@ int wmain(int argc, LPWSTR* argv) {
std::wcerr << L"--only-create-shortcut does not accept images/text/actions/expiration" << std::endl;
return 9;
}
- enum WinToast::ShortcutResult result = WinToast::instance()->createShortcut();
- return result ? 16 + result : 0;
+ WinToast::ShortcutResult result = WinToast::instance()->createShortcut();
+ return result != WinToast::ShortcutResult::SHORTCUT_UNCHANGED ? 16 + static_cast(result) : 0;
}
if (text.empty()) {
@@ -166,8 +167,8 @@ int wmain(int argc, LPWSTR* argv) {
return Results::InitializationFailure;
}
- WinToastTemplate templ(!imagePath.empty() ? WinToastTemplate::ImageAndText02 : WinToastTemplate::Text02);
- templ.setTextField(text, WinToastTemplate::FirstLine);
+ WinToastTemplate templ(!imagePath.empty() ? WinToastTemplate::Type::ImageAndText02 : WinToastTemplate::Type::Text02);
+ templ.setTextField(text, WinToastTemplate::TextField::FirstLine);
templ.setAudioOption(audioOption);
templ.setAttributionText(attribute);
templ.setImagePath(imagePath);
diff --git a/examples/qt-gui-example/mainwindow.cpp b/examples/qt-gui-example/mainwindow.cpp
index 58495b2..10a9c16 100644
--- a/examples/qt-gui-example/mainwindow.cpp
+++ b/examples/qt-gui-example/mainwindow.cpp
@@ -1,5 +1,8 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
+#include "wintoastlib.h"
+#include "wintoastlib.h"
+
#include
#include
#include
@@ -11,14 +14,14 @@ using namespace WinToastLib;
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
- ui->toastType->addItem("ImageAndText01", WinToastTemplate::ImageAndText01);
- ui->toastType->addItem("ImageAndText02", WinToastTemplate::ImageAndText02);
- ui->toastType->addItem("ImageAndText03", WinToastTemplate::ImageAndText03);
- ui->toastType->addItem("ImageAndText04", WinToastTemplate::ImageAndText04);
- ui->toastType->addItem("Text01", WinToastTemplate::Text01);
- ui->toastType->addItem("Text02", WinToastTemplate::Text02);
- ui->toastType->addItem("Text03", WinToastTemplate::Text03);
- ui->toastType->addItem("Text04", WinToastTemplate::Text04);
+ ui->toastType->addItem("ImageAndText01", WinToastTemplate::Type::ImageAndText01);
+ ui->toastType->addItem("ImageAndText02", WinToastTemplate::Type::ImageAndText02);
+ ui->toastType->addItem("ImageAndText03", WinToastTemplate::Type::ImageAndText03);
+ ui->toastType->addItem("ImageAndText04", WinToastTemplate::Type::ImageAndText04);
+ ui->toastType->addItem("Text01", WinToastTemplate::Type::Text01);
+ ui->toastType->addItem("Text02", WinToastTemplate::Type::Text02);
+ ui->toastType->addItem("Text03", WinToastTemplate::Type::Text03);
+ ui->toastType->addItem("Text04", WinToastTemplate::Type::Text04);
ui->audioMode->addItem("Default", WinToastTemplate::AudioOption::Default);
ui->audioMode->addItem("Loop", WinToastTemplate::AudioOption::Loop);
@@ -77,15 +80,15 @@ class CustomHandler : public IWinToastHandler {
std::wcout << L"Error showing current toast" << std::endl;
}
- void toastDismissed(WinToastDismissalReason state) const {
+ void toastDismissed(DismissalReason state) const {
switch (state) {
- case UserCanceled:
+ case DismissalReason::UserCanceled:
std::wcout << L"The user dismissed this toast" << std::endl;
break;
- case ApplicationHidden:
+ case DismissalReason::ApplicationHidden:
std::wcout << L"The application hid the toast using ToastNotifier.hide()" << std::endl;
break;
- case TimedOut:
+ case DismissalReason::TimedOut:
std::wcout << L"The toast has timed out" << std::endl;
break;
default:
@@ -96,13 +99,13 @@ class CustomHandler : public IWinToastHandler {
};
void MainWindow::on_showToast_clicked() {
- auto const type = static_cast(ui->toastType->currentData().toInt());
+ auto const type = static_cast(ui->toastType->currentData().toInt());
WinToastTemplate templ = WinToastTemplate(type);
templ.setImagePath(ui->imagePath->text().toStdWString(), static_cast(ui->cropHint->currentData().toInt()));
templ.setHeroImagePath(ui->heroPath->text().toStdWString(), ui->inlineHeroImage->isChecked());
- templ.setTextField(ui->firstLine->text().toStdWString(), WinToastTemplate::FirstLine);
- templ.setTextField(ui->secondLine->text().toStdWString(), WinToastTemplate::SecondLine);
- templ.setTextField(ui->thirdLine->text().toStdWString(), WinToastTemplate::ThirdLine);
+ templ.setTextField(ui->firstLine->text().toStdWString(), WinToastTemplate::TextField::FirstLine);
+ templ.setTextField(ui->secondLine->text().toStdWString(), WinToastTemplate::TextField::SecondLine);
+ templ.setTextField(ui->thirdLine->text().toStdWString(), WinToastTemplate::TextField::ThirdLine);
templ.setExpiration(ui->spinBox->value() * 1000);
templ.setAudioPath(static_cast(ui->audioSystemFile->currentData().toInt()));
templ.setAudioOption(static_cast(ui->audioMode->currentData().toInt()));
diff --git a/include/IWinToastHandler.h b/include/IWinToastHandler.h
new file mode 100644
index 0000000..4971024
--- /dev/null
+++ b/include/IWinToastHandler.h
@@ -0,0 +1,49 @@
+// MIT License
+//
+// Copyright (C) 2016-2025 WinToast - Mohammed Boujemaoui
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+
+#ifndef IWINTOASTHANDLER_H
+#define IWINTOASTHANDLER_H
+
+#include
+
+#include "Platform.h"
+
+namespace WinToastLib {
+ using namespace ABI::Windows::UI::Notifications;
+
+ struct IWinToastHandler {
+ enum class DismissalReason : int32_t {
+ UserCanceled = ToastDismissalReason_UserCanceled,
+ ApplicationHidden = ToastDismissalReason_ApplicationHidden,
+ TimedOut = ToastDismissalReason_TimedOut
+ };
+
+ virtual ~IWinToastHandler() = default;
+ virtual void toastActivated() const = 0;
+ virtual void toastActivated(int actionIndex) const = 0;
+ virtual void toastActivated(std::wstring response) const = 0;
+ virtual void toastDismissed(DismissalReason state) const = 0;
+ virtual void toastFailed() const = 0;
+ };
+}
+
+#endif //IWINTOASTHANDLER_H
\ No newline at end of file
diff --git a/include/Platform.h b/include/Platform.h
new file mode 100644
index 0000000..259143c
--- /dev/null
+++ b/include/Platform.h
@@ -0,0 +1,43 @@
+// MIT License
+//
+// Copyright (C) 2016-2025 WinToast - Mohammed Boujemaoui
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+
+#ifndef PLATFORM_H
+#define PLATFORM_H
+
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif //WIN32_LEAN_AND_MEAN
+
+#include
+#include
+#include
+#include
+
+namespace WinToastLib {
+ using namespace Microsoft::WRL;
+ using namespace ABI::Windows::Data::Xml::Dom;
+ using namespace ABI::Windows::Foundation;
+ using namespace ABI::Windows::UI::Notifications;
+ using namespace Windows::Foundation;
+}
+
+#endif //PLATFORM_H
\ No newline at end of file
diff --git a/include/WinToastTemplate.h b/include/WinToastTemplate.h
new file mode 100644
index 0000000..ad3f8fc
--- /dev/null
+++ b/include/WinToastTemplate.h
@@ -0,0 +1,143 @@
+// MIT License
+//
+// Copyright (C) 2016-2025 WinToast - Mohammed Boujemaoui
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+
+#ifndef WINTOASTTEMPLATE_H
+#define WINTOASTTEMPLATE_H
+
+#include
+#include
+#include
+
+#include "Platform.h"
+
+namespace WinToastLib {
+ struct WinToastTemplate final {
+ enum class Scenario : int32_t { Default, Alarm, IncomingCall, Reminder };
+ enum class Duration : int32_t { System, Short, Long };
+ enum class AudioOption : int32_t { Default, Silent, Loop };
+ enum class TextField : int32_t { FirstLine, SecondLine, ThirdLine };
+
+ enum class Type : int32_t {
+ ImageAndText01 = ToastTemplateType_ToastImageAndText01,
+ ImageAndText02 = ToastTemplateType_ToastImageAndText02,
+ ImageAndText03 = ToastTemplateType_ToastImageAndText03,
+ ImageAndText04 = ToastTemplateType_ToastImageAndText04,
+ Text01 = ToastTemplateType_ToastText01,
+ Text02 = ToastTemplateType_ToastText02,
+ Text03 = ToastTemplateType_ToastText03,
+ Text04 = ToastTemplateType_ToastText04
+ };
+
+ enum class AudioSystemFile : int32_t {
+ DefaultSound,
+ IM,
+ Mail,
+ Reminder,
+ SMS,
+ Alarm,
+ Alarm2,
+ Alarm3,
+ Alarm4,
+ Alarm5,
+ Alarm6,
+ Alarm7,
+ Alarm8,
+ Alarm9,
+ Alarm10,
+ Call,
+ Call1,
+ Call2,
+ Call3,
+ Call4,
+ Call5,
+ Call6,
+ Call7,
+ Call8,
+ Call9,
+ Call10,
+ };
+
+ enum class CropHint : int32_t {
+ Square,
+ Circle,
+ };
+
+ WinToastTemplate(_In_ Type type = Type::ImageAndText02);
+ ~WinToastTemplate();
+
+ void setFirstLine(_In_ std::wstring const& text);
+ void setSecondLine(_In_ std::wstring const& text);
+ void setThirdLine(_In_ std::wstring const& text);
+ void setTextField(_In_ std::wstring const& txt, _In_ TextField pos);
+ void setAttributionText(_In_ std::wstring const& attributionText);
+ void setImagePath(_In_ std::wstring const& imgPath, _In_ CropHint cropHint = CropHint::Square);
+ void setHeroImagePath(_In_ std::wstring const& imgPath, _In_ bool inlineImage = false);
+ void setAudioPath(_In_ AudioSystemFile audio);
+ void setAudioPath(_In_ std::wstring const& audioPath);
+ void setAudioOption(_In_ AudioOption audioOption);
+ void setDuration(_In_ Duration duration);
+ void setExpiration(_In_ INT64 millisecondsFromNow);
+ void setScenario(_In_ Scenario scenario);
+ void addAction(_In_ std::wstring const& label);
+ void addInput();
+
+ std::size_t textFieldsCount() const;
+ std::size_t actionsCount() const;
+ bool hasImage() const;
+ bool hasHeroImage() const;
+ std::vector const& textFields() const;
+ std::wstring const& textField(_In_ TextField pos) const;
+ std::wstring const& actionLabel(_In_ std::size_t pos) const;
+ std::wstring const& imagePath() const;
+ std::wstring const& heroImagePath() const;
+ std::wstring const& audioPath() const;
+ std::wstring const& attributionText() const;
+ std::wstring const& scenario() const;
+ INT64 expiration() const;
+ Type type() const;
+ AudioOption audioOption() const;
+ Duration duration() const;
+ bool isToastGeneric() const;
+ bool isInlineHeroImage() const;
+ bool isCropHintCircle() const;
+ bool isInput() const;
+
+ private:
+ bool _hasInput{false};
+
+ std::vector _textFields{};
+ std::vector _actions{};
+ std::wstring _imagePath{};
+ std::wstring _heroImagePath{};
+ bool _inlineHeroImage{false};
+ std::wstring _audioPath{};
+ std::wstring _attributionText{};
+ std::wstring _scenario{L"Default"};
+ INT64 _expiration{0};
+ AudioOption _audioOption{AudioOption::Default};
+ Type _type{Type::Text01};
+ Duration _duration{Duration::System};
+ CropHint _cropHint{CropHint::Square};
+ };
+}
+
+#endif //WINTOASTTEMPLATE_H
\ No newline at end of file
diff --git a/include/wintoastlib.h b/include/wintoastlib.h
index aa7a88a..909a485 100644
--- a/include/wintoastlib.h
+++ b/include/wintoastlib.h
@@ -1,189 +1,42 @@
-/**
- * MIT License
- *
- * Copyright (C) 2016-2025 WinToast v1.3.2 - Mohammed Boujemaoui
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
+// MIT License
+//
+// Copyright (C) 2016-2025 WinToast - Mohammed Boujemaoui
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
#ifndef WINTOASTLIB_H
#define WINTOASTLIB_H
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
#include