GCourtney7
GCourtney7

Reputation: 81

Making a simple message box using C++/WinRT

I'm having trouble making a simple message dialog in C++/WinRT. Something as simple as "You clicked this: press ok to continue" nothing fancy. In the standard Windows API you can simply write MessageBox() and new popup will show up where you can click ok, and you can do somthing similiar in C++/CX with auto messageDialog = ref new Windows::UI::Popups::MessageDialog("You clicked on the button!"); messageDialog->ShowAsync();

I've tried using IMessageDialog and ContentDialog classes with no success and can't seem to find a single example out there on how to do it without getting into writing Xaml code which for my perticular project seems unnecisary for something as simple as a message box. Maybe I'm just not setting them up right? But then again there are no examples on how to set it up in the first place (in C++). What am I missing? Thanks!

Upvotes: 2

Views: 2108

Answers (1)

GCourtney7
GCourtney7

Reputation: 81

I was able to form a simple message dialog using this:

winrt::hstring Title = L"Hello";
winrt::hstring Content = L"Some cool content!";
winrt::Windows::UI::Popups::MessageDialog dialog(Content, Title);
dialog.ShowAsync();

Make sure to also include <winrt/Windows.UI.Core.h> so you can get access to the UI library. And here is the result: enter image description here

Upvotes: 2

Related Questions