{"id":32443,"date":"2006-02-01T10:00:00","date_gmt":"2006-02-01T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2006\/02\/01\/the-per-class-window-styles-and-things-really-are-per-class\/"},"modified":"2006-02-01T10:00:00","modified_gmt":"2006-02-01T10:00:00","slug":"the-per-class-window-styles-and-things-really-are-per-class","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20060201-00\/?p=32443","title":{"rendered":"The per-class window styles and things really are per-class"},"content":{"rendered":"<p>\nEarlier, I discussed\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2003\/12\/03\/55927.aspx\">\nwhich window style bits belong to whom<\/a>.\nOne detail of this that I neglected to emphasize is that\nsince the\nlower 16 bits of the window style are defined by the class,\nyou can&#8217;t just take styles from one class and apply them to another.\nFor example, you can&#8217;t create a button control and pass the\n<code>SS_ENDELLIPSIS<\/code> style expecting to have the text\nrendered with end ellipses.\nBecause when you think you&#8217;re passing <code>SS_ENDELLIPSIS<\/code>,\nyou&#8217;re really passing <code>BS_NOTIFY<\/code>:\n<\/p>\n<pre>\n#define SS_ENDELLIPSIS      0x00004000L\n#define BS_NOTIFY           0x00004000L\n<\/pre>\n<p>\nThe button control sees your 0x00004000L and treats it as\n<code>BS_NOTIFY<\/code>.\n<\/p>\n<p>\nRemember that at the end of the day, window styles and\nwindow messages are just numbers.\nIf you use a per-class window style or window message,\nyou&#8217;d better be passing it to the class that defined it.\n<\/p>\n<p>\nThis also applies to window extra bytes.\nThe value returned by\n<code>GetWindowLongPtr(hwnd, DWLP_DLGPROC)<\/code>\nis meaningful only if <code>hwnd<\/code> is a dialog box.\nI&#8217;ve seen code by a major commercial software manufacturer\nthat just runs around fiddling with the <code>DWLP_DLGPROC<\/code>\nof every window on the desktop on the assumption that\n&#8220;Why of course it&#8217;s a dialog box, why do you ask?&#8221;\nWell, except that\n<code>DWLP_DLGPROC<\/code> has the numerical value of 4\n(or 8 on Win64).\nPositive window byte indices are class-defined.\nAsking for <code>DWLP_DLGPROC<\/code> of a random window\nwill give you the dialog procedure if that window is a dialog box,\nbut it&#8217;ll return some other internal data if the window isn&#8217;t.\nFortunately, most window classes don&#8217;t ask for more than\n<code>sizeof(void*)<\/code> extra bytes, so the\nrequest for <code>DWLP_DLGPROC<\/code> just fails with an\ninvalid parameter error.\nBut if there happened to be a window belonging to a class with\na larger number of extra bytes,\nthat window will be in for quite a surprise when that rogue\nprogram comes in and starts messing with those extra bytes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Earlier, I discussed which window style bits belong to whom. One detail of this that I neglected to emphasize is that since the lower 16 bits of the window style are defined by the class, you can&#8217;t just take styles from one class and apply them to another. For example, you can&#8217;t create a button [&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-32443","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Earlier, I discussed which window style bits belong to whom. One detail of this that I neglected to emphasize is that since the lower 16 bits of the window style are defined by the class, you can&#8217;t just take styles from one class and apply them to another. For example, you can&#8217;t create a button [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/32443","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=32443"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/32443\/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=32443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=32443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=32443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}