{"id":15059947,"url":"https://github.com/adam-gladstone/dialogservice","last_synced_at":"2026-01-02T12:31:42.597Z","repository":{"id":223132583,"uuid":"758571302","full_name":"Adam-Gladstone/DialogService","owner":"Adam-Gladstone","description":"A Windows Runtime Component that wraps calling a MessageDialog","archived":false,"fork":false,"pushed_at":"2024-02-18T13:48:32.000Z","size":482,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T04:12:50.082Z","etag":null,"topics":["cpp","cpp20","windows","windows-desktop","windows-desktop-application","windows-sdk","winrt","winui3","xaml"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Adam-Gladstone.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-16T15:54:07.000Z","updated_at":"2024-02-19T09:32:33.000Z","dependencies_parsed_at":"2024-02-18T14:45:44.336Z","dependency_job_id":"b1526588-237b-434f-9750-fa9f91d97b29","html_url":"https://github.com/Adam-Gladstone/DialogService","commit_stats":null,"previous_names":["adam-gladstone/dialogservice"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adam-Gladstone%2FDialogService","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adam-Gladstone%2FDialogService/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adam-Gladstone%2FDialogService/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adam-Gladstone%2FDialogService/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Adam-Gladstone","download_url":"https://codeload.github.com/Adam-Gladstone/DialogService/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243681084,"owners_count":20330155,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","cpp20","windows","windows-desktop","windows-desktop-application","windows-sdk","winrt","winui3","xaml"],"created_at":"2024-09-24T22:50:21.081Z","updated_at":"2026-01-02T12:31:42.566Z","avatar_url":"https://github.com/Adam-Gladstone.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca name=\"readme-top\"\u003e\u003c/a\u003e\n\n\u003c!-- PROJECT LOGO --\u003e\n\u003cbr /\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/Adam-Gladstone/DialogService\"\u003e\n    \u003cimg src=\"Images/icons8-edit-property-80.png\" alt=\"logo\" width=\"80\" height=\"80\"\u003e\n  \u003c/a\u003e\n\n  \u003ch3 align=\"center\"\u003eDialogService\u003c/h3\u003e\n\n  \u003cp align=\"center\"\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/Adam-Gladstone/DialogService\"\u003e\u003cstrong\u003eExplore the docs »\u003c/strong\u003e\u003c/a\u003e\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/Adam-Gladstone/DialogService/issues\"\u003eReport Bug\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/Adam-Gladstone/DialogService/issues\"\u003eRequest Feature\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n\u003c!-- TABLE OF CONTENTS --\u003e\n\u003cdetails\u003e\n  \u003csummary\u003eTable of Contents\u003c/summary\u003e\n  \u003col\u003e\n    \u003cli\u003e\n      \u003ca href=\"#about-the-project\"\u003eAbout The Project\u003c/a\u003e\n      \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#built-with\"\u003eBuilt With\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/li\u003e\n    \u003cli\u003e\n      \u003ca href=\"#getting-started\"\u003eGetting Started\u003c/a\u003e\n      \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#prerequisites\"\u003ePrerequisites\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#roadmap\"\u003eRoadmap\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#contact\"\u003eContact\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#acknowledgments\"\u003eAcknowledgments\u003c/a\u003e\u003c/li\u003e\n  \u003c/ol\u003e\n\u003c/details\u003e\n\n\u003c!-- ABOUT THE PROJECT --\u003e\n## About The Project\nIn a previous WinUI 3 project ([WordleWinUI](https://github.com/Adam-Gladstone/Wordle)) I wanted a simple dialog box to display a message to the user. I was rather hoping for an equivalent to the Windows Forms (C#) MessageBox, which is easy to code:\n\n```\n  string message = \"Are you sure you want to do that, Dave?\";\n  string caption = \"Message Box Test\";\n  DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);\n  if (result == System.Windows.Forms.DialogResult.Yes) {\n      // Open the airlock ...\n  }\n```\n\nAnd it produces a functional MessageBox:\n\n![Windows Forms MessageBox](Images/WindowsFormsMessageBox.png)\n\nThis doesn't seem to exist in WinUI 3 (The [MessageDialog class](https://learn.microsoft.com/en-us/uwp/api/windows.ui.popups.messagedialog?view=winrt-22621) seems to be deprecated in WinUI). So I thought it would be a nice idea to develop a reusable widget that worked similarly to the Windows Forms Message Box. Furthermore, I was inspired by [XamlBrewer](https://xamlbrewer.wordpress.com/2022/03/09/a-dialog-service-for-winui-3/). This sounded very similar to what I wanted and I thought it might be a good idea to port this to C++/WinRT as a reusable component. In the end, I simplified the DialogService to a single API call:\n\n![WinUI MessageBox](Images/WinUIMessageBox.png)\n\nThe client code is not much more involved than the C# code above:\n\n```\n    hstring title = App::Window().Title();\n\n    auto result = co_await DialogServiceWRC::ModalView::MessageDialogAsync(\n        winrt::box_value\u003cWindows::Foundation::IInspectable\u003e(*this),\n        title,\n        L\"Are you sure you want to do that, Dave?\",\n        DialogServiceWRC::MessageBoxButtonType::YesNo,\n        DialogServiceWRC::MessageBoxIconType::Question);\n\n    auto dialogResult = winrt::unbox_value\u003cMicrosoft::UI::Xaml::Controls::ContentDialogResult\u003e(result);\n\n    if (dialogResult == Microsoft::UI::Xaml::Controls::ContentDialogResult::Primary) {\n      // Open the airlock ...      \n    }\n\n```\n\n### Project structure\nThere are three projects in the DialogService.sln solution file:\n  * __DialogServiceWRC__ - this is a C++ Windows Runtime Component. \n  * __DialogServiceProjection__ - this is a .NET project to generate the interop ('projection') and package it as a NuGet package.\n  * __DialogServiceWinUI__. - this is a standard WinUI 3.0 C++/WinRT Windows Desktop Application that consumes the component.\n\n#### __DialogServiceWRC__\nThe __DialogServiceWRC__ defines a simple API in ModalView.idl for calling the MessageDialog:\n\n```\n  static Windows.Foundation.IAsyncOperation\u003cIInspectable\u003e\n    MessageDialogAsync(\n      IInspectable value,\n      String title,\n      String message,\n      MessageBoxButtonType buttons,\n      MessageBoxIconType icon\n    );\n\n```\nThis API is mostly a simple wrapper around the WinUI 3 ContentDialog control (https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.contentdialog?view=windows-app-sdk-1.4). However, I wanted to be able to set the buttons and the icons. \nThis involved creating some Xaml controls on-the-fly, and adding this to the ContentDialog Content property.\nIn a previous application (WordleWinUI), the dialog service was part of the main application. The MessageDialogAsync call wrapped a call to the ContentDialog plus some custom XAML to display the MessageBox with the icons. \n\nHowever, there were two issues when moving this code to be part of a reusable Windows Runtime Component:\n1) The MIDL compiler complained about not knowing the types of `ContentDialogResult` (this is a simple enum `int32`, and which we could work around by creating our own type), and more importantly the `FrameworkElement` which is essential for determining the `XamlRoot`. The header file with the correctly generated types was present. For some reason the MIDL compiler couldn't see it. The solution adopted was to pass both these types as `IInspectable` and **box** and **unbox** them as required. So calling the API requires boxing and unboxing values.\n\n2) A more serious problem arose when I added the XAML page markup to represent the 'inner' message box of the content dialog. Again the MIDL compiler failed with an unhelpful error message. After various failed attempts, the workaround I adopted was to define the MessageBox content entirely in C++/WinRT code. Luckily there was no need for this to be a separate `runtimeclass` as the content is just passed to the ContentDialog container. There was not much markup and all the binding (the icon resource and the message text) could be handled in code. Phew. \n\n#### __DialogServiceWinUI__\nThe __DialogServiceWinUI__ consumes the __DialogServiceWRC__. This involves generating the NuGet package (using the projection project), then adding a project reference to this solution and including the generated header file in pch.h: `#include \u003cwinrt/DialogServiceWRC.h\u003e`. \n\nThe __DialogServiceWinUI__ exercises the MessageDialog functionality with a simple button in the Content page.\n\n![WinUI MessageBox](Images/WinUIMessageBox2.png)\n\nThe __DialogServiceWinUI__ also demonstrates a number of additional features\n- support for light/dark mode via a toggle button on the menu.\n- navigation view with 2 pages and a settings page. This provides a simple extensible framework\n- support for application wide and user settings via a simple runtimeclass.\n- resizing the app window\n- setting the application icon for the main window\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n### Built With\n\n* Visual Studio 2022\n* C++20\n* C++/WinRT\n* WinUI 3.0\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- GETTING STARTED --\u003e\n## Getting Started\n\nThe project can be downloaded from the GitHub repository in the usual way.\n\n### Prerequisites\n\n\n### Installation\n\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- USAGE EXAMPLES --\u003e\n## Usage\n\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- ROADMAP --\u003e\n## Roadmap\n\nSee the [open issues](https://github.com/Adam-Gladstone/DialogService/issues) for a full list of proposed features (and known issues).\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- LICENSE --\u003e\n## License\n\nDistributed under the GPL-3.0 License. See `LICENSE.md` for more information.\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- CONTACT --\u003e\n## Contact\n\nAdam Gladstone - (https://www.linkedin.com/in/adam-gladstone-b6458b156/)\n\nProject Link: [https://github.com/Adam-Gladstone/DialogService](https://github.com/Adam-Gladstone/DialogService)\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- ACKNOWLEDGMENTS --\u003e\n## Acknowledgments\n\nHelpful resources\n\n* [Choose an Open Source License](https://choosealicense.com)\n* [Img Shields](https://shields.io)\n* [GitHub Pages](https://pages.github.com)\n* [Font Awesome](https://fontawesome.com)\n* [React Icons](https://react-icons.github.io/react-icons/search)\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- PROJECT SHIELDS --\u003e\n\n[![Issues][issues-shield]][issues-url]\n[![GPL-3 License][license-shield]][license-url]\n[![LinkedIn][linkedin-shield]][linkedin-url]\n\n\u003c!-- MARKDOWN LINKS \u0026 IMAGES --\u003e\n\u003c!-- https://www.markdownguide.org/basic-syntax/#reference-style-links --\u003e\n\n[issues-shield]: https://img.shields.io/github/issues/Adam-Gladstone/DialogService.svg?style=for-the-badge\n[issues-url]: https://github.com/Adam-Gladstone/DialogService/issues\n\n[license-shield]: https://img.shields.io/github/license/Adam-Gladstone/DialogService.svg?style=for-the-badge\n[license-url]: https://github.com/Adam-Gladstone/DialogService/LICENSE.md\n\n[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge\u0026logo=linkedin\u0026colorB=555\n[linkedin-url]: https://www.linkedin.com/in/adam-gladstone-b6458b156/\n\n[product-screenshot]: Images/Screenshot.PNG\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadam-gladstone%2Fdialogservice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadam-gladstone%2Fdialogservice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadam-gladstone%2Fdialogservice/lists"}