{"id":107962,"date":"2023-03-23T07:00:00","date_gmt":"2023-03-23T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=107962"},"modified":"2023-03-23T09:42:06","modified_gmt":"2023-03-23T16:42:06","slug":"20230323-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20230323-00\/?p=107962","title":{"rendered":"How unique must the <CODE>uIdSubclass<\/CODE> parameter be when I call <CODE>Set&shy;Window&shy;Subclass<\/CODE>?"},"content":{"rendered":"<p>The <code>Set\u00adWindow\u00adSubclass<\/code> function manages window subclassing in a safer way. When you use it to subclass a window, you provide four pieces of information:<\/p>\n<ul>\n<li>The window you want to subclass,<\/li>\n<li>The function you want to subclass it with,<\/li>\n<li>A <code>uIdSubclass<\/code> that is passed to the subclass function,<\/li>\n<li>A <code>dwRefData<\/code> that is passed to the subclass function.<\/li>\n<\/ul>\n<p>You get to pick two values to pass to the subclass function. What&#8217;s the difference?<\/p>\n<p>A unique instance of a subclass managed by the <code>Set\u00adWindow\u00adSubclass<\/code> function is identified by a triplet of the window handle, the subclass function, and the subclass ID (<code>uIdSubclass<\/code>). The reference data (<code>dwRefData<\/code>) is not part of the identity. It&#8217;s some extra data that the <code>Set\u00adWindow\u00adSubclass<\/code> function remembers and passes back to your subclass function, but the <code>Set\u00adWindow\u00adSubclass<\/code> doesn&#8217;t pay any attention to the value.<\/p>\n<p>The <code>Set\u00adWindow\u00adSubclass<\/code> function <i>does<\/i> pay attention to the <code>uIdSubclass<\/code>. If you call <code>Set\u00adWindow\u00adSubclass<\/code> function twice on the same window with the same function and the same <code>uIdSubclass<\/code>, then the second one overwrites the first. (You can do this if you want to change the <code>dwRefData<\/code>.)<\/p>\n<p>The <code>uIdSubclass<\/code> is handy if you intend to subclass the same window multiple times with the same function. For example, the Tooltip control has an option to subclass the window to which the tooltip is attached. If you ask for this, then the Tooltip control calls <code>Set\u00adWindow\u00adSubclass<\/code> function with the attached window, an internal subclass function, and uses the handle of the Tooltip control itself as the <code>uIdSubclass<\/code>. That way, it&#8217;s possible for two Tooltip controls to be attached to the same window without interfering with each other.<\/p>\n<p>In these sorts of cases, where you may have multiple instances all subclassing the same window, the <code>uIdSubclass<\/code> is typically some value that is unique to each instance (such as a pointer or handle).<\/p>\n<p>Most of the time, though, you&#8217;re not writing a reusable component that can be applied multiple times to the same window. You&#8217;re just doing a one-shot subclass of a window with a specific function, and you have no intention of subclassing the window twice. In that case, the <code>uIdSubclass<\/code> value is not interesting, as long as you are consistent in which value you use.<\/p>\n<p>Most people just pass zero.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Each one identifies an instance of the subclass for the window.<\/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-107962","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Each one identifies an instance of the subclass for the window.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/107962","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=107962"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/107962\/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=107962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=107962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=107962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}