Git Product home page Git Product logo

malja / wintoast Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mohabouje/wintoast

0.0 1.0 0.0 18.07 MB

WinToast is a lightly library written in C++ which brings a complete integration of the modern toast notifications of Windows 8 & Windows 10. Toast notifications allows your app to inform the users about relevant information and timely events that they should see and take action upon inside your app, such as a new instant message, a new friend request, breaking news, or a calendar event.

License: MIT License

C++ 98.88% QMake 1.12%

wintoast's Introduction

releases issues license built

GitHub forks GitHub stars GitHub watchers


WinToast

WinToast is a lightly library written in C++ which brings a complete integration of the modern toast notifications of Windows 8 & Windows 10.

Toast notifications allows your app to inform the users about relevant information and timely events that they should see and take action upon inside your app, such as a new instant message, a new friend request, breaking news, or a calendar event.

WinToast integrates all standard templates availables in the ToastTemplateType enumeration.

Template Description Example
ImageAndText01 A large image and a single string wrapped across three lines of text. enter image description here
ImageAndText02 A large image, one string of bold text on the first line, one string of regular text wrapped across the second and third lines. 12
ImageAndText03 A large image, one string of bold text wrapped across the first two lines, one string of regular text on the third line. enter image description here
ImageAndText04 A large image, one string of bold text on the first line, one string of regular text on the second line, one string of regular text on the third line. enter image description here
Text01 Single string wrapped across three lines of text. enter image description here
Text02 One string of bold text on the first line, one string of regular text wrapped across the second and third lines. enter image description here
Text03 One string of bold text wrapped across the first two lines, one string of regular text on the third line. enter image description here
Text04 One string of bold text on the first line, one string of regular text on the second line, one string of regular text on the third line. enter image description here

Usage

First step, Import the header file wintoastlib.h to your project. You should check if your Windows Version is supported by the library.

using namespace WinToastLib;
....
if (!WinToast::isCompatible()) {
    std::wcout << L"Error, your system in not supported!" << std::endl;
}

For an easy usage, you can just use the available singleton instance and start to configure your App User Model Id, this can be done by using the existing helper:

using namespace WinToastLib;
....
WinToast::instance()->setAppName(L"WinToastExample");
const auto aumi = WinToast::configureAUMI(L"mohabouje", L"wintoast", L"wintoastexample", L"20161006");
WinToast::instance()->setAppUserModelId(aumi);
	

Now is time to initialize all the dependencies and check if WinToas has been initialized successfully before starting using it:

if (!WinToast::instance()->initialize()) {
  std::wcout << L"Error, could not initialize the lib!" << std::endl;
}

To manage the different user actions, you can implement your own handler, subclassing the interface IWinToastHandler:

class WinToastHandlerExample : public IWinToastHandler {
 public:
	WinToastHandlerExample(); 
	// Public interfaces
	void toastActivated() const;
	void toastDismissed(WinToastDismissalReason state) const;
	void toastFailed() const;
 };

To notify any event just configure your own toast template and launch it:

WinToastHandlerExample* handler = new WinToastHandlerExample;
WinToastTemplate templ = WinToastTemplate(WinToastTemplate::ImageAndText02);
templ.setImagePath(L"C:/example.png");
templ.setTextField(L"title", WinToastTemplate::FirstLine);
templ.setTextField(L"subtitle", WinToastTemplate::SecondLine);

if (!WinToast::instance()->showToast(templ, handler)) {
    std::wcout << L"Error: Could not launch your toast notification!" << std::endl;
}

Modern features - Windows 10

If your system support the new modern features (Version > Windows 8.1) available in Windows 10, you can add some interesting fields as:

  • Actions: you can add your own actions, this fact allow you to interact with user in a different way:
WinToastTemplate templ = WinToastTemplate(WinToastTemplate::Text02);
templ.setTextField(L"Do you think this feature is cool?", WinToastTemplate::FirstLine);
templ.setTextField(L"Ofc,it is!", WinToastTemplate::SecondLine);

std::vector<std::wstring> actions;
actions.push_back(L"Yes");
actions.push_back(L"No");
for (auto const &action : actions)	
    templ.addAction(action);
WinToast::instance()->showToast(templ, handler) 

"Toast with some actions"

  • Attribution text: you can add/remove the attribution text, by default is empty. Use WinToastTemplate::setAttributionText to modify it.
  • Audio Properties: you can modify the different behaviors of the sound:
    • Default: plays the audio file just one time.
    • Silent: turn off the sound.
    • Loop: plays the given sound in a loop during the toast existence.

WinToast allows the modification of the default audio file. Add the given file in to your projects resources (must be ms-appx:// or ms-appdata:// path) and define it by calling: WinToastTemplate::setAudioPath

By default, WinToast checks if your systems support the features, ignoring the not supported ones.

wintoast's People

Contributors

albertvaka avatar christiangalla avatar dscho avatar kainjow avatar kambala-decapitator avatar mohabouje avatar phillab avatar sraboy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.