{"id":1043,"date":"2014-05-08T07:00:00","date_gmt":"2014-05-08T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/05\/08\/how-can-you-use-both-versions-5-and-6-of-the-common-controls-within-the-same-module\/"},"modified":"2014-05-08T07:00:00","modified_gmt":"2014-05-08T07:00:00","slug":"how-can-you-use-both-versions-5-and-6-of-the-common-controls-within-the-same-module","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20140508-00\/?p=1043","title":{"rendered":"How can you use both versions 5 and 6 of the common controls within the same module?"},"content":{"rendered":"<p>\nCommenter Medinoc was baffled by the statement that\nthe decision to use the visual-styles-enabled version of the\ncommon controls library is done on a window-by-window basis.\n&#8220;<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/05\/26\/10168421.aspx#10169554\">\nIsn&#8217;t it rather on a per-module basis,\ndepending on each module&#8217;s manifest<\/a>?\nIf it is indeed on a per-window basis, how does one choose?&#8221;\n<\/p>\n<p>\nWhether a particular call to\n<code>Create&shy;Window<\/code> (or one of its moral equivalents)\ngets the classic version of the control or the visual-styles-enabled\nversion of the control depends on which activation context is active\nat the point of the call.\nIf an activation context with version 6 of the common controls is active,\nthen you get the control from version 6 of the common controls.\nOtherwise, you get the classic control.\n<\/p>\n<p>\nIf you use the\n<code>ISOLATION_AWARE_ENABLED<\/code> macro,\nthen including <code>commctrl.h<\/code> turns on a bunch of\nmacros that take all your calls to\n<code>Create&shy;Window<\/code> and related functions,\nand converts them into something like this:\n<\/p>\n<pre>\nHWND CreateWindow_wrapped(... parameters ...)\n{\n HWND hwnd = nullptr;\n ULONG_PTR ulCookie;\n if (ActivateActCtx(ModuleContext, &amp;ulCookie)) {\n  hwnd = CreateWindow(... parameters ...);\n DeactivateActCtx(0, ulCookie);\n }\n return hwnd;\n}\n<\/pre>\n<p>\nwhere <code>Module&shy;Context<\/code> is a global variable\nthat holds the activation context you specified in your manifest.\n<\/p>\n<p>\nIn other words, any time your code tries to create a window,\nthe wrapper macros\nactivate your v6 manifest,\ncreate the window,\nthen deactivate the manifest.\n<\/p>\n<p>\nRemember that nobody walks the stack looking to see who the caller is.\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/01\/01\/47042.aspx\">\nThe return address is not reliable<\/a>.\n(And checking the return address doesn&#8217;t help for dynamically-generated\ncode anyway.)\nThe way to know which activation context is active is for somebody\nto actually come out and set it.\n<\/p>\n<p>\nBack to the question:\nThe way you choose whether you want a classic or a visual-styles-enabled\nversion of a control is by deciding whether or not to have the\nv6 manifest active when you call\n<code>Create&shy;Window<\/code>.\n<\/p>\n<p>\nA common mistake is that people will call a function that requires\na v6 manifest, such as <code>Task&shy;Dialog<\/code>,\nbut they will forget to activate the v6 manifest before calling.\nThe result is that they call into version 6 of the common controls,\nbut when the common controls library tries to create its task dialog,\n<i>it fails<\/i> because the v5 context is active,\nand the v5 context does not have a task dialog control.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Commenter Medinoc was baffled by the statement that the decision to use the visual-styles-enabled version of the common controls library is done on a window-by-window basis. &#8220; Isn&#8217;t it rather on a per-module basis, depending on each module&#8217;s manifest? If it is indeed on a per-window basis, how does one choose?&#8221; Whether a particular call [&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-1043","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Commenter Medinoc was baffled by the statement that the decision to use the visual-styles-enabled version of the common controls library is done on a window-by-window basis. &#8220; Isn&#8217;t it rather on a per-module basis, depending on each module&#8217;s manifest? If it is indeed on a per-window basis, how does one choose?&#8221; Whether a particular call [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1043","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=1043"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1043\/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=1043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=1043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=1043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}