Skip to content

Commit 1581a13

Browse files
authored
Merge pull request #32 from mohabouje/develop
Develop
2 parents 11e99e4 + f9a86f3 commit 1581a13

File tree

6 files changed

+305
-99
lines changed

6 files changed

+305
-99
lines changed

README.md

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ WinToast is a lightly library written in C++ which brings a complete integration
1717
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.
1818

1919
1. [Toast Templates](#id1)
20-
2. [Event Handler](#id2)
21-
3. [Expiration Time](#id3)
22-
4. [Modern Features](#id4)
23-
5. [Example of usage](#id5)
20+
2. [Event Handler](#id3)
21+
3. [Expiration Time](#id4)
22+
4. [Modern Features](#id5)
23+
5. [Error Handling](#id2)
24+
6. [Windows 10 Configuration](#id7)
25+
7. [Example of usage](#id6)
26+
2427

2528
<div id='id1' />
2629

@@ -47,7 +50,10 @@ templ.setImagePath(L"C:/example.png");
4750
templ.setTextField(L"title", WinToastTemplate::FirstLine);
4851
templ.setTextField(L"subtitle", WinToastTemplate::SecondLine);
4952
```
50-
<div id='id2' />
53+
54+
*The user can use the default system sound or specify a sound to play when a toast notification is displayed. Same behavior for the toast notification image, by default Windows try to use the app icon.*
55+
56+
<div id='id3' />
5157

5258
## Event Handler
5359

@@ -72,7 +78,7 @@ class WinToastHandlerExample : public IWinToastHandler {
7278
void toastFailed() const;
7379
};
7480
```
75-
<div id='id3' />
81+
<div id='id4' />
7682
7783
## Expiration Time
7884
@@ -81,7 +87,7 @@ Set the time after which a toast notification is no longer considered current or
8187
> For Windows 8.x app, this property also causes the toast notification to be removed from the
8288
> Action Center once the specified data and time is reached.
8389
84-
<div id='id4' />
90+
<div id='id5' />
8591
8692
## Modern features - Windows 10
8793
@@ -104,6 +110,10 @@ WinToast::instance()->showToast(templ, handler)
104110

105111
!["Toast with some actions"](https://lh3.googleusercontent.com/uJE_H0aBisOZ-9GynEWgA7Hha8tHEI-i0aHrFuOFDBsPSD-IJ-qEN0Y7XY4VI5hp_5MQ9xjWbFcm)
106112
- **Attribution text**: you can add/remove the attribution text, by default is empty. Use `WinToastTemplate::setAttributionText` to modify it.
113+
- **Duration**: The amount of time the toast should display. This attribute can have one of the following values:
114+
- *System*: default system configuration.
115+
- *Short*: default system short time configuration.
116+
- *Long*: default system long time configuration.
107117
- **Audio Properties**: you can modify the different behaviors of the sound:
108118
- *Default*: plays the audio file just one time.
109119
- *Silent*: turn off the sound.
@@ -115,7 +125,42 @@ WinToast::instance()->showToast(templ, handler)
115125
116126
***By default, WinToast checks if your systems support the features, ignoring the not supported ones.***
117127

118-
<div id='id5' />
128+
<div id='id2' />
129+
130+
## Error Handling
131+
There are several reasons WinToast can fail that's why the library notifies caller about fail reason. Those are the code for each failure:
132+
133+
| WinToastError | Error Code | Error message |
134+
|--|--|--|
135+
| NoError | 0x00 | No error. The process was executed correctly |
136+
| NotInitialized | 0x01 | The library has not been initialized |
137+
| SystemNotSupported | 0x02 | The OS does not support WinToast |
138+
| ShellLinkNotCreated | 0x03 | The library was not able to create a Shell Link for the app |
139+
| InvalidAppUserModelID | 0x04 | The AUMI is not a valid one |
140+
| InvalidParameters | 0x05 | The parameters used to configure the library are not valid normally because an invalid AUMI or App Name |
141+
| NotDisplayed | 0x06 | The toast was created correctly but WinToast was not able to display the toast |
142+
| UnknownError | 0x07 | Unknown error |
143+
144+
A common example of usage is to check while initializing the library or showing a toast notification the possible failure code:
145+
146+
```cpp
147+
WinToast::WinToastError error;
148+
const bool succedded = WinToast::instance()->initialize(&error);
149+
if (!succedded) {
150+
std::wcout << L"Error, could not initialize the lib. Error number: "
151+
<< error << std::endl;
152+
}
153+
...
154+
// Configure the template
155+
...
156+
const bool launched = WinToast::instance()->showToast(templ, handler, &error);
157+
if (!launched) {
158+
std::wcout << L"Error: Could not launch your toast notification. Error: "
159+
<< error << std::endl;
160+
}
161+
```
162+
163+
<div id='id6' />
119164
120165
## Example of Usage
121166
@@ -166,8 +211,15 @@ if (!WinToast::instance()->showToast(templ, handler)) {
166211
std::wcout << L"Error: Could not launch your toast notification!" << std::endl;
167212
}
168213
```
214+
<div id='id7' />
215+
216+
## Windows 10 - Toast Configuration
217+
218+
Windows allows the configuration of the default behavior of a toast notification. This can be done in the *Ease of Access* configuration by modifying the *Other options* tab.
169219
220+
The system configuration help you to define how long you want notifications to appear for (5 seconds to 5 minutes) as turning on visual notifications for sound.
170221
222+
![Ease of Access configuration](https://camo.githubusercontent.com/56c8edd1a7a4a43be07ba211d9d828478fdbad39/68747470733a2f2f7777772e686f77746f6765656b2e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031362f30332f656173655f6f665f6163636573732e706e67)
171223
172224
173225

example/console-example/WinToast Console Example.sln

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26228.9
4+
VisualStudioVersion = 15.0.27130.2027
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinToast Console Example", "WinToast Console Example.vcxproj", "{7C5AC60D-8668-47B6-9D05-FB363F854065}"
77
EndProject
@@ -13,8 +13,8 @@ Global
1313
Release|x86 = Release|x86
1414
EndGlobalSection
1515
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16-
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Debug|x64.ActiveCfg = Debug|x64
17-
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Debug|x64.Build.0 = Debug|x64
16+
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Debug|x64.ActiveCfg = Debug|Win32
17+
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Debug|x64.Build.0 = Debug|Win32
1818
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Debug|x86.ActiveCfg = Debug|Win32
1919
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Debug|x86.Build.0 = Debug|Win32
2020
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Release|x64.ActiveCfg = Release|x64
@@ -25,4 +25,7 @@ Global
2525
GlobalSection(SolutionProperties) = preSolution
2626
HideSolutionNode = FALSE
2727
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {ABA98BF8-B665-455B-A51E-B36DD616139C}
30+
EndGlobalSection
2831
EndGlobal

example/console-example/WinToast Console Example.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
<VCProjectVersion>15.0</VCProjectVersion>
2323
<ProjectGuid>{7C5AC60D-8668-47B6-9D05-FB363F854065}</ProjectGuid>
2424
<Keyword>Win32Proj</Keyword>
25-
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
25+
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
2626
</PropertyGroup>
2727
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2828
<PropertyGroup Label="Configuration">
2929
<ConfigurationType>Application</ConfigurationType>
3030
<UseDebugLibraries>true</UseDebugLibraries>
31-
<PlatformToolset>v140</PlatformToolset>
31+
<PlatformToolset>v141</PlatformToolset>
3232
</PropertyGroup>
3333
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
3434
<ImportGroup Label="ExtensionSettings">

example/console-example/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int wmain(int argc, LPWSTR *argv)
108108

109109

110110
bool onlyCreateShortcut = false;
111-
WinToastTemplate::AudioOption audioOption = WinToastTemplate::Default;
111+
WinToastTemplate::AudioOption audioOption = WinToastTemplate::AudioOption::Default;
112112

113113
int i;
114114
for (i = 1; i < argc; i++)

0 commit comments

Comments
 (0)