Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
620a601
Move remaining linker pragmas into CMakeLists file
KitsuneAlex Jul 24, 2025
6a8ab66
Consistently use enum class instead of C-enums, ensure int32_t as def…
KitsuneAlex Jul 25, 2025
bdad5b1
Remove redundant noop FAR modifiers on function pointers
KitsuneAlex Jul 25, 2025
c1ff224
Move top-level using namespace directives in API header into WinToast…
KitsuneAlex Jul 25, 2025
d546c22
Remove redundant static casts
KitsuneAlex Jul 25, 2025
767ceea
Check for WIN32_LEAN_AND_MEAN in API header and define it if not alre…
KitsuneAlex Jul 25, 2025
d324ffc
Sort all includes and move ones only relevant to the implementation i…
KitsuneAlex Jul 25, 2025
5b3632c
Bump C++ standard to 17 for string_view and improved constexpr as tha…
KitsuneAlex Jul 25, 2025
ff08957
Rewrite defaultExecutablePath, defaultShellLinksDirectory and default…
KitsuneAlex Jul 26, 2025
8852def
Introduce WinToast::ThreadingMode enum
KitsuneAlex Jul 26, 2025
51995f5
Refactor out Windows specific includes into Platform.h, refactor out …
KitsuneAlex Jul 26, 2025
dce26db
Use file(GLOB_RECURSE) to find headers and sources automatically
KitsuneAlex Jul 26, 2025
a6d1c50
Update LICENSE.txt, add copyright profile for CLion
KitsuneAlex Jul 26, 2025
4b0c712
Update copyright header in source files
KitsuneAlex Jul 26, 2025
9b8838b
Update examples
KitsuneAlex Jul 26, 2025
a99fa5e
Refactor out WinToastTemplate into its own header file
KitsuneAlex Jul 26, 2025
abe849c
Move COM initialiazation to initialize() function, use APARTMENT_THRE…
KitsuneAlex Jul 28, 2025
ee9ba51
Add back static modifier on instance
KitsuneAlex Aug 1, 2025
0ebe459
Use multithreaded initialization
KitsuneAlex Aug 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,3 @@ enc_temp_folder/
build/
cmake-build-*
CMakeLists.txt.user

# CLion
.idea/
7 changes: 7 additions & 0 deletions .idea/copyright/WinToast.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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)

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")
Comment on lines +11 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Globs for source files are discouraged. See CMake docs:

We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know when to ask CMake to regenerate.

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)
Expand Down
4 changes: 2 additions & 2 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (C) 2016-2023 WinToast v1.3.0 - Mohammed Boujemaoui <mohabouje@gmail.com>
Copyright (C) 2016-2025 WinToast - Mohammed Boujemaoui <mohabouje@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -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.
19 changes: 10 additions & 9 deletions examples/console-example/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "wintoastlib.h"

#include <string>
#include <windows.h>
#include <iostream>

using namespace WinToastLib;

Expand All @@ -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;
Expand Down Expand Up @@ -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<int32_t>(result) : 0;
}

if (text.empty()) {
Expand All @@ -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);
Expand Down
35 changes: 19 additions & 16 deletions examples/qt-gui-example/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "wintoastlib.h"
#include "wintoastlib.h"

#include <QDebug>
#include <qfiledialog.h>
#include <qmessagebox.h>
Expand All @@ -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);
Expand Down Expand Up @@ -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:
Expand All @@ -96,13 +99,13 @@ class CustomHandler : public IWinToastHandler {
};

void MainWindow::on_showToast_clicked() {
auto const type = static_cast<WinToastTemplate::WinToastTemplateType>(ui->toastType->currentData().toInt());
auto const type = static_cast<WinToastTemplate::Type>(ui->toastType->currentData().toInt());
WinToastTemplate templ = WinToastTemplate(type);
templ.setImagePath(ui->imagePath->text().toStdWString(), static_cast<WinToastTemplate::CropHint>(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<WinToastTemplate::AudioSystemFile>(ui->audioSystemFile->currentData().toInt()));
templ.setAudioOption(static_cast<WinToastTemplate::AudioOption>(ui->audioMode->currentData().toInt()));
Expand Down
49 changes: 49 additions & 0 deletions include/IWinToastHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// MIT License
//
// Copyright (C) 2016-2025 WinToast - Mohammed Boujemaoui <mohabouje@gmail.com>
//
// 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 <cstdint>

#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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All new files are missing final newlines.

43 changes: 43 additions & 0 deletions include/Platform.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of this file is too generic. Ideally, WinToast headers would be in a wintoast/ subdirectory. That would be possible if we make breaking changes anyway.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// MIT License
//
// Copyright (C) 2016-2025 WinToast - Mohammed Boujemaoui <mohabouje@gmail.com>
//
// 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 <Windows.h>
#include <wrl/event.h>
#include <windows.ui.notifications.h>
#include <roapi.h>

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;
}
Comment on lines +30 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, if one includes WinToast, they shouldn't need to include Windows libraries.


#endif //PLATFORM_H
Loading
Loading