diff --git a/README.md b/README.md index 0d060bc..d3033b9 100644 --- a/README.md +++ b/README.md @@ -107,8 +107,7 @@ Microsoft style guidelines recommend representing profile pictures with a circul WinToastTemplate templ = WinToastTemplate(WinToastTemplate::ImageAndText02); templ.setTextField(L"Matt sent you a friend request", WinToastTemplate::FirstLine); templ.setTextField(L"Hey, wanna dress up as wizards and ride around on hoverboards?", WinToastTemplate::SecondLine); -templ.setImagePath(L"C:/example.png"); -templ.setHintCrop(WinToastTemplate::Circle); +templ.setImagePath(L"C:/example.png", WinToastTemplate::CropHint::Circle); ``` !["Toast with hero image"](assets/images/hint-crop.png) diff --git a/examples/Simple-Explained-console-example/Project1.vcxproj b/examples/Simple-Explained-console-example/Project1.vcxproj new file mode 100644 index 0000000..4730985 --- /dev/null +++ b/examples/Simple-Explained-console-example/Project1.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {3101ec78-73cc-4e75-8694-775ac5265c76} + Project1 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/examples/Simple-Explained-console-example/Project1.vcxproj.filters b/examples/Simple-Explained-console-example/Project1.vcxproj.filters new file mode 100644 index 0000000..a12df58 --- /dev/null +++ b/examples/Simple-Explained-console-example/Project1.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/examples/Simple-Explained-console-example/Project1.vcxproj.user b/examples/Simple-Explained-console-example/Project1.vcxproj.user new file mode 100644 index 0000000..966b4ff --- /dev/null +++ b/examples/Simple-Explained-console-example/Project1.vcxproj.user @@ -0,0 +1,6 @@ + + + + true + + \ No newline at end of file diff --git a/examples/Simple-Explained-console-example/src/main.cpp b/examples/Simple-Explained-console-example/src/main.cpp new file mode 100644 index 0000000..863887b --- /dev/null +++ b/examples/Simple-Explained-console-example/src/main.cpp @@ -0,0 +1,194 @@ +#include "wintoastlib.h" +#include +#include + +using namespace WinToastLib; + + +/* Explaine + This used to Handle events that occure on users behaves +*/ +class CustomHandler : public IWinToastHandler { +public: + + // When user clicks the notification + void toastActivated() const { + std::wcout << L"The user clicked in this toast" << std::endl; + exit(0); + } + + // When user clicks the button in notiification + void toastActivated(int actionIndex) const { + std::wcout << L"The user clicked on action #" << actionIndex << std::endl; + exit(16 + actionIndex); + } + + // When user closes the notification + void toastDismissed(WinToastDismissalReason state) const { + switch (state) { + case UserCanceled: + std::wcout << L"The user dismissed this toast" << std::endl; + exit(1); + break; + case TimedOut: + std::wcout << L"The toast has timed out" << std::endl; + exit(2); + break; + case ApplicationHidden: + std::wcout << L"The application hid the toast using ToastNotifier.hide()" << std::endl; + exit(3); + break; + default: + std::wcout << L"Toast not activated" << std::endl; + exit(4); + break; + } + } + + // When error occure + void toastFailed() const { + std::wcout << L"Error showing current toast" << std::endl; + exit(5); + } +}; + +// ###################################################################################### + + +/* Explaine + Here we return code foreach case, to can do any handiling in the future based on the returning code +*/ +enum Results { + ToastClicked, // user clicked on the toast + ToastDismissed, // user dismissed the toast + ToastTimeOut, // toast timed out + ToastHided, // application hid the toast + ToastNotActivated, // toast was not activated + ToastFailed, // toast failed + SystemNotSupported, // system does not support toasts + UnhandledOption, // unhandled option + MultipleTextNotSupported, // multiple texts were provided + InitializationFailure, // toast notification manager initialization failure + ToastNotLaunched // toast could not be launched +}; + + +// ###################################################################################### + + +int basicModel() { + + /* Explaine + Here we put all data to our notification properties + */ + std::wstring appName = L"This is Model 1"; + std::wstring appUserModelID = L"Example 1"; + std::wstring text1 = L"This is a Test notification"; + std::wstring text2 = L"Hellow forom C++ I'm the potato who ate the cotato"; + std::wstring text3 = L"Meow"; + std::wstring imagePath = L"C:/Users/pc/Downloads/New FCI Hashira/FCIH/FCAIHHPNgLogo.png"; + std::wstring bannerPath = L"C:/Users/pc/Downloads/New FCI Hashira/Registeration opens (4).png"; + std::wstring audioPath = L"C:/Users/pc/Downloads/videoplayback.m4a"; + std::wstring attribute = L"Via SMS"; + std::vector actions; + INT64 expiration = 70000; + + actions.push_back(L"Cancel"); + actions.push_back(L"Mute"); + actions.push_back(L"Answer"); + + + // ###################################################################################### + + + /* Explaine + Here we Set the notification settings for the instance + */ + + WinToastTemplate::AudioOption audioOption = WinToastTemplate::AudioOption::Loop; // set how notification audio should behave + + /* here we can choose the scenario */ + //WinToastTemplate::Scenario scenarioOption = WinToastTemplate::Scenario::Default; // for calls + //WinToastTemplate::Scenario scenarioOption = WinToastTemplate::Scenario::Alarm; // for alarms + //WinToastTemplate::Scenario scenarioOption = WinToastTemplate::Scenario::Reminder; // for Reminder + WinToastTemplate::Scenario scenarioOption = WinToastTemplate::Scenario::IncomingCall; + + /* here we can choose the image crop options */ + //WinToastTemplate::CropHint cropOption = WinToastTemplate::CropHint::Circle; // circle 50%; + WinToastTemplate::CropHint cropOption = WinToastTemplate::CropHint::Square; // square + + + WinToast::instance()->setAppName(appName); // adding the instance name + WinToast::instance()->setAppUserModelId(appUserModelID); // adding the instance id + + + if (!WinToast::instance()->initialize()) { // Initialize toast instance, and if error happened return error + std::wcerr << L"Error, your system in not compatible!" << std::endl; + return Results::InitializationFailure; // if failed will return failure code + } + + + // ###################################################################################### + + + /* Explaine + Initialize template from the same instance, this templte is used onece thin killed + */ + + WinToastTemplate templ( WinToastTemplate::ImageAndText04); // decide our template type + templ.setTextField(text1, WinToastTemplate::FirstLine); + templ.setTextField(text2, WinToastTemplate::SecondLine); + templ.setTextField(text3, WinToastTemplate::ThirdLine); + + + // audio options are sounds differ based on Scenario + templ.setAudioOption(audioOption); + + + // image + templ.setImagePath(imagePath); // to set image as icon no crop + templ.setImagePath(imagePath, cropOption); // to set how image will be cropped + + // banner + templ.setHeroImagePath(bannerPath); // to set image as banner + templ.setHeroImagePath(bannerPath, true); + templ.setAttributionText(attribute); + + + templ.setExpiration(expiration); + templ.setScenario(scenarioOption); + + for (auto const& action : actions) { + templ.addAction(action); + } + + + // ###################################################################################### + + + // Try to send the instance, If failed it will return the Failing Code + if (WinToast::instance()->showToast(templ, new CustomHandler()) < 0) { + std::wcerr << L"Could not launch your toast notification!"; + return Results::ToastFailed; + } + + // Give the handler a chance for 7 seconds and in expiration, then the notifcation is killed + Sleep((DWORD)expiration + 1500); + + return 2; +} + + +int model1() { + return 0; +} +int model2() { + return 0; +} + + + +int wmain(int argc, LPWSTR* argv) { + basicModel(); + exit(2); // same as reutrn 2 +} \ No newline at end of file