{"id":19773,"date":"2008-12-19T10:00:00","date_gmt":"2008-12-19T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/12\/19\/what-is-the-mysterious-fourth-message-box-button\/"},"modified":"2008-12-19T10:00:00","modified_gmt":"2008-12-19T10:00:00","slug":"what-is-the-mysterious-fourth-message-box-button","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20081219-00\/?p=19773","title":{"rendered":"What is the mysterious fourth message box button?"},"content":{"rendered":"<p><P>\nWhen you call the <CODE>MessageBox<\/CODE> function,\nyou pass flags specifying which of a fixed set of button\npatterns you want (for example, Yes\/No and OK\/Cancel)\nand which button you want to be the default\n(<CODE>MB_DEFBUTTON1<\/CODE> through <CODE>MB_DEFBUTTON4<\/CODE>.)\n<\/P>\n<P>\nWait a second.\nWhat&#8217;s with this\n<CODE>MB_DEFBUTTON4<\/CODE>?\nNone of the button patterns are four-button patterns.\nThe highest number of buttons you can specify is three:\nAbort\/Retry\/Ignore.\nHow can you set a nonexistent button to be the default?\n<\/P>\n<P>\nLet&#8217;s do some header file spelunking.\nThe flag for this magical fourth button is defined here:\n<\/P>\n<PRE>\n#define MB_DEFBUTTON1               0x00000000L\n#define MB_DEFBUTTON2               0x00000100L\n#define MB_DEFBUTTON3               0x00000200L\n#if(WINVER &gt;= 0x0400)\n#define MB_DEFBUTTON4               0x00000300L\n#endif \/* WINVER &gt;= 0x0400 *\/\n<\/PRE>\n<P>\nAha, the magic fourth button was added in\n<CODE>WINVER<\/CODE>&nbsp;4.0.\nTherefore, whatever the fourth button is, it was introduced\nwhen <CODE>WINVER == 0x0400<\/CODE>.\nLet&#8217;s see what other message box flags were introduced then:\n<\/P>\n<PRE>\n#define MB_OK                       0x00000000L\n#define MB_OKCANCEL                 0x00000001L\n#define MB_ABORTRETRYIGNORE         0x00000002L\n#define MB_YESNOCANCEL              0x00000003L\n#define MB_YESNO                    0x00000004L\n#define MB_RETRYCANCEL              0x00000005L\n#if(WINVER &gt;= 0x0500)\n#define MB_CANCELTRYCONTINUE        0x00000006L\n#endif \/* WINVER &gt;= 0x0500 *\/<\/p>\n<p>#define MB_ICONHAND                 0x00000010L\n#define MB_ICONQUESTION             0x00000020L\n#define MB_ICONEXCLAMATION          0x00000030L\n#define MB_ICONASTERISK             0x00000040L<\/p>\n<p><FONT COLOR=\"blue\">#if(WINVER &gt;= 0x0400)\n#define MB_USERICON                 0x00000080L\n#define MB_ICONWARNING              MB_ICONEXCLAMATION\n#define MB_ICONERROR                MB_ICONHAND\n#endif \/* WINVER &gt;= 0x0400 *\/<\/FONT><\/p>\n<p>#define MB_ICONINFORMATION          MB_ICONASTERISK\n#define MB_ICONSTOP                 MB_ICONHAND<\/p>\n<p>#define MB_DEFBUTTON1               0x00000000L\n#define MB_DEFBUTTON2               0x00000100L\n#define MB_DEFBUTTON3               0x00000200L\n<FONT COLOR=\"blue\">#if(WINVER &gt;= 0x0400)\n#define MB_DEFBUTTON4               0x00000300L\n#endif \/* WINVER &gt;= 0x0400 *\/<\/FONT><\/p>\n<p>#define MB_APPLMODAL                0x00000000L\n#define MB_SYSTEMMODAL              0x00001000L\n#define MB_TASKMODAL                0x00002000L\n<FONT COLOR=\"blue\">#if(WINVER &gt;= 0x0400)\n#define MB_HELP                     0x00004000L \/\/ Help Button\n#endif \/* WINVER &gt;= 0x0400 *\/<\/FONT><\/p>\n<p>#define MB_NOFOCUS                  0x00008000L\n#define MB_SETFOREGROUND            0x00010000L\n#define MB_DEFAULT_DESKTOP_ONLY     0x00020000L<\/p>\n<p><FONT COLOR=\"blue\">#if(WINVER &gt;= 0x0400)\n#define MB_TOPMOST                  0x00040000L\n#define MB_RIGHT                    0x00080000L\n#define MB_RTLREADING               0x00100000L\n#endif \/* WINVER &gt;= 0x0400 *\/<\/FONT><\/p>\n<p>#ifdef _WIN32_WINNT\n<FONT COLOR=\"blue\">#if (_WIN32_WINNT &gt;= 0x0400)\n#define MB_SERVICE_NOTIFICATION          0x00200000L<\/FONT>\n#else\n#define MB_SERVICE_NOTIFICATION          0x00040000L\n#endif\n#define MB_SERVICE_NOTIFICATION_NT3X     0x00040000L\n#endif\n<\/PRE>\n<P>\nWe can discount the flags like <CODE>MB_ICONWARNING<\/CODE>\nwhich are just alternate names for existing flags,\nas well as <CODE>MB_SERVICE_NOTIFICATION<\/CODE> which\nalready existed but with a different value.\nThis leaves the following:\n<\/P>\n<PRE>\n#define MB_USERICON                 0x00000080L\n#define MB_HELP                     0x00004000L \/\/ Help Button\n#define MB_TOPMOST                  0x00040000L\n#define MB_RIGHT                    0x00080000L\n#define MB_RTLREADING               0x00100000L\n<\/PRE>\n<P>\nOf these flags, <CODE>MB_USERICON<\/CODE> affects the icon,\nand <CODE>MB_TOPMOST<\/CODE>, <CODE>MB_RIGHT<\/CODE> and\n<CODE>MB_RTLREADING<\/CODE> affect the dialog box&#8217;s position and layout;\nnone of them affect the buttons.\nBut wait, there&#8217;s <CODE>MB_HELP<\/CODE>.\nAh, that flag &#8220;adds a <B>Help<\/B> button to the message box.&#8221;\nThat&#8217;s our magical fourth button!\nLet&#8217;s celebrate by showing a four-button message box with the\ndefault set to the fourth button:\n<\/P>\n<PRE>\n#include &lt;windows.h&gt;<\/p>\n<p>int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,\n                   LPSTR lpCmdLine, int nShowCmd)\n{\n  return MessageBox(NULL, TEXT(&#8220;Four buttons!&#8221;), TEXT(&#8220;Title&#8221;),\n            MB_ABORTRETRYIGNORE | MB_HELP | MB_DEFBUTTON4);\n}\n<\/PRE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you call the MessageBox function, you pass flags specifying which of a fixed set of button patterns you want (for example, Yes\/No and OK\/Cancel) and which button you want to be the default (MB_DEFBUTTON1 through MB_DEFBUTTON4.) Wait a second. What&#8217;s with this MB_DEFBUTTON4? None of the button patterns are four-button patterns. The highest number [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-19773","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>When you call the MessageBox function, you pass flags specifying which of a fixed set of button patterns you want (for example, Yes\/No and OK\/Cancel) and which button you want to be the default (MB_DEFBUTTON1 through MB_DEFBUTTON4.) Wait a second. What&#8217;s with this MB_DEFBUTTON4? None of the button patterns are four-button patterns. The highest number [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/19773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=19773"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/19773\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=19773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=19773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=19773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}