{"id":111,"date":"2010-04-22T15:00:08","date_gmt":"2010-04-22T09:30:08","guid":{"rendered":"http:\/\/techtwaddle.net\/?p=111"},"modified":"2011-01-26T15:00:30","modified_gmt":"2011-01-26T09:30:30","slug":"applications-how-to-create-a-custom-dialog-box-for-windows-mobile-6-native","status":"publish","type":"post","link":"https:\/\/techtwaddle.co.in\/blog\/2010\/04\/22\/applications-how-to-create-a-custom-dialog-box-for-windows-mobile-6-native\/","title":{"rendered":"Applications: How to create a custom dialog box for Windows Mobile 6 (native)"},"content":{"rendered":"<p align=\"justify\">Ashraf, <a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/en-US\/windowsmobiledev\/thread\/de6df5d5-9a01-44e5-af3e-4b7b5079b4ec?prof=required\">on the MSDN forum<\/a>, asks,<\/p>\n<p align=\"justify\">&ldquo;<em>Is there a way to make a default choice for the messagebox that happens after a period of time if the user doesn&#8217;t choose (Clicked ) Yes or No buttons.<\/em>&rdquo;<\/p>\n<p align=\"justify\">To elaborate, the requirement is to show a message box to the user with certain options to select, and if the user does not respond within a predefined time limit (say 8 seconds) then the message box must dismiss itself and select a default option. Now such a functionality is not available with the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa926303.aspx\">MessageBox()<\/a> api, you will have to write your own custom dialog box.<\/p>\n<p align=\"justify\">Surely, creating a dialog box is quite a simple task using the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa924506.aspx\">DialogBox()<\/a> api, and we have been creating <a href=\"http:\/\/geekswithblogs.net\/TechTwaddle\/archive\/2009\/05\/26\/applications-creating-a-simple-ui-application-from-scratch-process-viewer-again.aspx\">full screen dialog boxes<\/a> all the while. So how will this custom message box be any different? It&rsquo;s not much different from a regular dialog box except for a few changes in its properties. First, it has a title bar but no buttons on the title bar (no &lsquo;x&rsquo; or &lsquo;ok&rsquo; button on the title bar), it doesn&rsquo;t occupy full screen and it contains the controls that you put into it, thus justifying the title &lsquo;custom&rsquo;.<\/p>\n<p align=\"justify\">So in this post we create a custom dialog box with two buttons, &lsquo;Black&rsquo; and &lsquo;White&rsquo;. The user is given 8 seconds to select one of those colours, if the user doesn&rsquo;t make a selection in 8 seconds, the default option &lsquo;Black&rsquo; is selected. Before going into the implementation here is a video of how the dialog box works;<\/p>\n<div class=\"wlWriterEditableSmartContent\" id=\"scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:1c7cd639-3591-4d2f-a7ff-71337d36b7d6\" style=\"margin: 0px; padding: 0px; display: inline; float: none;\">\n<div style=\"margin: 0px; padding: 0px; display: inline;\" id=\"64c79fca-0217-4bbf-acda-8b15af3d2a2a\">\n<div><a target=\"_new\" href=\"http:\/\/www.youtube.com\/watch?v=C_yFblAoUJ4&amp;feature=youtube_gdata\"><img decoding=\"async\" alt=\"\" onload=\"var downlevelDiv = document.getElementById('64c79fca-0217-4bbf-acda-8b15af3d2a2a'); downlevelDiv.innerHTML = &quot;&lt;div&gt;&lt;object width=\\&quot;425\\&quot; height=\\&quot;355\\&quot;&gt;&lt;param name=\\&quot;movie\\&quot; value=\\&quot;http:\/\/www.youtube.com\/v\/C_yFblAoUJ4&amp;hl=en\\&quot;&gt;&lt;\\\/param&gt;&lt;embed src=\\&quot;http:\/\/www.youtube.com\/v\/C_yFblAoUJ4&amp;hl=en\\&quot; type=\\&quot;application\/x-shockwave-flash\\&quot; width=\\&quot;425\\&quot; height=\\&quot;355\\&quot;&gt;&lt;\\\/embed&gt;&lt;\\\/object&gt;&lt;\\\/div&gt;&quot;;\" galleryimg=\"no\" style=\"border-style: none;\" src=\"http:\/\/geekswithblogs.net\/images\/geekswithblogs_net\/TechTwaddle\/WindowsLiveWriter\/ApplicationsHowtocreateacustomdialogboxf_10517\/video066abe66770c.jpg\" \/><\/a><\/div>\n<\/div>\n<div style=\"clear: both; font-size: 0.8em;\">Custom dialog box<\/div>\n<\/div>\n<p align=\"justify\">\nTo start off, add a new dialog resource into your application, size it appropriately and add whatever controls you need to the dialog. In my case, I added two static text labels and two buttons, as below;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"501\" height=\"203\" border=\"0\" src=\"http:\/\/geekswithblogs.net\/images\/geekswithblogs_net\/TechTwaddle\/WindowsLiveWriter\/ApplicationsHowtocreateacustomdialogboxf_10517\/CustomDialog_rsrc_3.jpg\" alt=\"CustomDialog_rsrc\" title=\"CustomDialog_rsrc\" style=\"border: 0px none; display: inline;\" \/><\/p>\n<p align=\"justify\">Now we need to write up the window procedure for this dialog, here is the complete function;<\/p>\n<p><font color=\"#000080\">BOOL CALLBACK CustomDialogProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)     <br \/>\n{      <br \/>\n&nbsp;&nbsp;&nbsp; int wmID, wmEvent;      <br \/>\n&nbsp;&nbsp;&nbsp; PAINTSTRUCT ps;      <br \/>\n&nbsp;&nbsp;&nbsp; HDC hdc; <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp; static int timeCount = 0; <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp; switch(uMessage)     <br \/>\n&nbsp;&nbsp;&nbsp; {      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case WM_INITDIALOG:      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SHINITDLGINFO shidi; <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memset(&amp;shidi, 0, sizeof(shidi)); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shidi.dwMask = SHIDIM_FLAGS;     <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: rgb(51, 153, 102);\">\/\/shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;      <\/span><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shidi.dwFlags = SHIDIF_SIPDOWN | SHIDIF_EMPTYMENU;      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shidi.hDlg = hDlg;      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SHInitDialog(&amp;shidi); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SHDoneButton(hDlg, SHDB_HIDE); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timeCount = 0; <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TIME_REMAINING), L&quot;Time remaining: 8 second(s)&quot;);     <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetTimer(hDlg, MY_TIMER, 1000, NULL); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }     <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return TRUE; <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case WM_COMMAND:     <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wmID = LOWORD(wParam);      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wmEvent = HIWORD(wParam); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch(wmID)     <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case IDC_BUTTON_BLACK:      <br \/>\n<\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; KillTimer(hDlg, MY_TIMER);   <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EndDialog(hDlg, IDC_BUTTON_BLACK);    <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;    <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case IDC_BUTTON_WHITE:    <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; KillTimer(hDlg, MY_TIMER);    <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EndDialog(hDlg, IDC_BUTTON_WHITE);    <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;    <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }    <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }    <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break; <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case WM_TIMER:     <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (wParam == MY_TIMER)      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WCHAR wszText[128];      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memset(&amp;wszText, 0, sizeof(wszText)); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timeCount++; <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: rgb(51, 153, 102);\">\/\/8 seconds are over, dismiss the dialog, select def value     <\/span><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (timeCount &gt;= 8)      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; KillTimer(hDlg, MY_TIMER);      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EndDialog(hDlg, IDC_BUTTON_BLACK_DEF);      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wsprintf(wszText, L&quot;Time remaining: %d second(s)&quot;, 8-timeCount); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TIME_REMAINING), wszText);     <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UpdateWindow(GetDlgItem(hDlg, IDC_STATIC_TIME_REMAINING));      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }     <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case WM_PAINT:      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hdc = BeginPaint(hDlg, &amp;ps); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EndPaint(hDlg, &amp;ps);     <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break; <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp; } <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp; return FALSE;     <br \/>\n}<\/font><\/p>\n<p align=\"justify\">The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb158579.aspx\">MSDN documentation<\/a> mentions that you need to specify the flag <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb158579.aspx\">WS_NONAVDONEBUTTON<\/a>, but I got an error saying that the value could not be found, so we can ignore this for now. Next up, while calling <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ee501722.aspx\">SHInitDialog()<\/a> for your custom dialog, make sure that you don&rsquo;t specify SHDIF_DONEBUTTON in the dwFlags member of the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ee504339.aspx\">SHINITDIALOG<\/a> structure, this flag makes the &lsquo;ok&rsquo; button appear on the dialog title bar. Finally, we need to call <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa930127.aspx\">SHDoneButton()<\/a> with SHDB_HIDE flag to, well, hide the Done button. The &lsquo;Done&rsquo; button is the same as the &lsquo;ok&rsquo; button, so this step might seem redundant, and the dialog works fine without calling SHDoneButton() too, but it&rsquo;s better to stick with the documentation (; So you can see that we have followed all these steps above, under <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa453871.aspx\">WM_INITDIALOG<\/a>. We also setup a few things like a variable to keep track of the time, and setting off a one second timer.<\/p>\n<p align=\"justify\">Every time the timer fires, we receive a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa932703.aspx\">WM_TIMER<\/a> message. We then update the static label displaying the amount of time left to the user. If 8 seconds go by without the user selecting any option, we kill the timer and end the dialog with IDC_BUTTON_BLACK_DEF. This is just a #define&rsquo;d integer value, make sure it&rsquo;s unique. You&rsquo;ll see why this is important. If the user makes a selection, either Black or White, we kill the timer and end the dialog with the corresponding selection the user made, that is, either IDC_BUTTON_BLACK or IDC_BUTTON_WHITE.<\/p>\n<p align=\"justify\">Ok, so now our custom dialog is ready to be used. I invoke the custom dialog from a menu entry in the main window as below,<\/p>\n<p><font color=\"#000080\">case IDM_MENU_CUSTOMDLG:     <br \/>\n&nbsp;&nbsp;&nbsp; {      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ret = DialogBox(g_hInst, MAKEINTRESOURCE(IDD_CUSTOM_DIALOG), hWnd, CustomDialogProc); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch(ret)     <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case IDC_BUTTON_BLACK_DEF:      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetWindowText(g_hStaticSelection, L&quot;You Selected: Black (default)&quot;);      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case IDC_BUTTON_BLACK:      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetWindowText(g_hStaticSelection, L&quot;You Selected: Black&quot;);      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break; <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case IDC_BUTTON_WHITE:     <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetWindowText(g_hStaticSelection, L&quot;You Selected: White&quot;);      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UpdateWindow(g_hStaticSelection);     <br \/>\n&nbsp;&nbsp;&nbsp; }      <br \/>\n&nbsp;&nbsp;&nbsp; break; <\/font><\/p>\n<p align=\"justify\">So you see why ending the dialog with the corresponding value was important, that&rsquo;s what the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa924506.aspx\">DialogBox()<\/a> api returns with. And in the main window I update a static text label to show which option was selected.<\/p>\n<p align=\"justify\">I cranked this out in about an hour, and unfortunately don&rsquo;t have time for a managed C# version. That will have to be another post, if I manage to get it working that is (;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ashraf, on the MSDN forum, asks, &ldquo;Is there a way to make a default choice for the messagebox that happens after a period of time if the user doesn&#8217;t choose (Clicked ) Yes or No buttons.&rdquo; To elaborate, the requirement is to show a message box to the user with certain options to select, and &hellip; <a href=\"https:\/\/techtwaddle.co.in\/blog\/2010\/04\/22\/applications-how-to-create-a-custom-dialog-box-for-windows-mobile-6-native\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Applications: How to create a custom dialog box for Windows Mobile 6 (native)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1ktFF-1N","_links":{"self":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/111"}],"collection":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":1,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"predecessor-version":[{"id":112,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions\/112"}],"wp:attachment":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}