{"id":6263,"date":"2012-10-24T07:00:00","date_gmt":"2012-10-24T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2012\/10\/24\/you-cant-use-the-wm_user-message-in-a-dialog-box\/"},"modified":"2012-10-24T07:00:00","modified_gmt":"2012-10-24T07:00:00","slug":"you-cant-use-the-wm_user-message-in-a-dialog-box","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20121024-00\/?p=6263","title":{"rendered":"You can&#039;t use the WM_USER message in a dialog box"},"content":{"rendered":"<p>\nToday, I&#8217;m not actually going to say anything new.\nI&#8217;m just going to collate information I&#8217;ve already written\nunder a better title to improve search engine optimization.\n<\/p>\n<p>\nA customer reported that they did the following but found\nthat it didn&#8217;t work:\n<\/p>\n<pre>\n#define MDM_SETITEMCOUNT WM_USER\nINT_PTR CALLBACK MyDlgProc(HWND hdlg, UINT wm, WPARAM wParam, LPARAM lParam)\n{\n  switch (wm) {\n  ...\n  case MDM_SETITEMCOUNT:\n    SetDlgItemInt(hwnd, IDC_ITEMCOUNT, (UINT)wParam, FALSE);\n    return TRUE;\n  ...\n  }\n  return FALSE;\n}\n<\/pre>\n<p>\n&#8220;I send the <code>MDM_SET&shy;ITEM&shy;COUNT<\/code> message\nto my dialog, but the value doesn&#8217;t stick.\nAt random times, the value resets back to zero.&#8221;\n<\/p>\n<p>\nAs we saw some time ago,\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/12\/02\/55914.aspx\">\nwindow messages in the <code>WM_USER<\/code> range belong to the\nwindow class<\/a>.\nIn the case of a dialog box, the window class is the dialog class,\nand the owner of the class is the window manager itself.\nAn application which tries to use the\n<code>WM_USER<\/code> message is using window messages it does not own.\n<\/p>\n<p>\nIt so happens that the dialog manager already defined the\n<code>WM_USER<\/code> message:\n<\/p>\n<pre>\n#define DM_GETDEFID         (WM_USER+0)\n<\/pre>\n<p>\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2006\/09\/25\/770536.aspx\">\nWe saw this problem some time ago<\/a>\nwhen we tried to find a message we could use for custom use\nin a dialog box.\n<\/p>\n<p>\nWhat the customer is seeing is that whenever the dialog manager\nsends a <code>DM_GET&shy;DEF&shy;ID<\/code> message to the dialog box\nto get the default control ID,\nthe <code>MyDlgProc<\/code> function mistakenly thinks that it&#8217;s\na\n<code>MDM_SET&shy;ITEM&shy;COUNT<\/code> message and\nsets the item count to whatever happens to be in the\n<code>wParam<\/code> (which happens to be zero).\nOn top of that, it claims to have handled the message,\nwhich means that the current value of\n<code>DWL_MSG&shy;RESULT<\/code> is returned to the sender\n(probably zero),\nso the dialog manager thinks that there is no default ID on the dialog.\n<\/p>\n<p>\nThe solution,\nas noted in that same article, is to use <code>WM_APP<\/code>\ninstead of <code>WM_USER<\/code>.\nBecause you don&#8217;t have permission to define messages in the\n<code>WM_USER<\/code> range if you aren&#8217;t the owner of the window class.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, I&#8217;m not actually going to say anything new. I&#8217;m just going to collate information I&#8217;ve already written under a better title to improve search engine optimization. A customer reported that they did the following but found that it didn&#8217;t work: #define MDM_SETITEMCOUNT WM_USER INT_PTR CALLBACK MyDlgProc(HWND hdlg, UINT wm, WPARAM wParam, LPARAM lParam) { [&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-6263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Today, I&#8217;m not actually going to say anything new. I&#8217;m just going to collate information I&#8217;ve already written under a better title to improve search engine optimization. A customer reported that they did the following but found that it didn&#8217;t work: #define MDM_SETITEMCOUNT WM_USER INT_PTR CALLBACK MyDlgProc(HWND hdlg, UINT wm, WPARAM wParam, LPARAM lParam) { [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/6263","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=6263"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/6263\/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=6263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=6263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=6263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}