{"id":14473,"date":"2010-03-29T07:00:00","date_gmt":"2010-03-29T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/03\/29\/what-happens-to-the-control-names-in-the-ide-when-my-program-is-running\/"},"modified":"2010-03-29T07:00:00","modified_gmt":"2010-03-29T07:00:00","slug":"what-happens-to-the-control-names-in-the-ide-when-my-program-is-running","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20100329-00\/?p=14473","title":{"rendered":"What happens to the control names in the IDE when my program is running?"},"content":{"rendered":"<p>nick_journals demonstrates <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/pages\/407234.aspx#1120782\"> some confusion<\/a> about names in source code and their relationship to runtime behavior.<\/p>\n<blockquote class=\"q\"><p>  A topic I am particularly interested in is the naming of controls, how it works&#8230; <\/p>\n<p> Every control gets a name from a developer&#8230;via the IDE (e.g btnOK) <\/p>\n<p> When using this function: GetWindowLong(handle,GWL_ID) it doesn&#8217;t return the name itself but mostly a number or nothing. <\/p>\n<p> What is GWL_ID, the documentation isn&#8217;t very clear on this. <\/p>\n<p> How does this whole system work, what are these numbers and where are the &#8216;real&#8217; names? <\/p>\n<\/blockquote>\n<p> I&#8217;m going to answer the questions most technical first. That way you can stop reading when you understand the topic.\n The <code>GWL_ID<\/code> window long (or, more precisely, the <code>GWLP_ID<\/code> window pointer-sized long) returns the value you passed to the <code>CreateWindowEx<\/code> function as the child window identifier (<a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2010\/03\/15\/9978691.aspx\">overloaded as the <code>hMenu<\/code> parameter<\/a>). The call to <code>CreateWindowEx<\/code> might have happened explicitly in your code, or it may have been the result of a call to <code>CreateWindowEx<\/code> made on your behalf by another component, <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2005\/03\/31\/404108.aspx\"> such as the dialog manager<\/a>, which takes the control identifier from the dialog template. (Note that only child windows have child window identifiers. Top-level windows don&#8217;t have child window identifiers.) And if you passed zero as the child window identifier, then when you ask for the <code>GWLP_ID<\/code>, you&#8217;ll get zero back.\n The name that appears in your source code is just a name you decided to use to talk about the control. It&#8217;s just a convenience for yourself, so instead of saying &#8220;Control number&nbsp;103&#8221; all over the place, you can say &#8220;Control number&nbsp;<code>IDC_ADD<\/code>&#8220;. And sometimes even that is too much typing, so you shorten it to &#8220;control <code>btnAdd<\/code>.&#8221; The window manager doesn&#8217;t know what cute shortcut names you&#8217;ve created for your child windows; the window manager still calls it control number&nbsp;103. By analogy, the phone company doesn&#8217;t know which numbers you&#8217;ve programmed into your speed dial. That&#8217;s just something you set up in your phone to make dialing more convenient.\n In other words, the &#8220;real name&#8221; is really just a fake name you created to make things easier to talk about. The actual &#8220;real name&#8221; is the child window identifier. When you look in the telephone book for Bob, you&#8217;ll see Bob&#8217;s phone number, not his speed-dial number on your phone.\n This is the same thing that happens to your variables after the code has been compiled. At runtime, your variable names don&#8217;t exist any more. They were just convenient mnemonic names you gave to computational values. The compiler uses those convenient names to determine what you&#8217;re talking about when you assign a variable or a fetch a variable&#8217;s value, but once that&#8217;s done, it has no need for the name any more.\n In other words, the name in your source code is just something you did to make things easier to write. The compiler&#8217;s job is to change your line <code>x = y;<\/code> into <code>mov eax, [ebp-05ch]; mov [00437180h], eax<\/code>, at which point the names <code>x<\/code> and <code>y<\/code> are no longer needed and are discarded. (Actually, it&#8217;s saved off in a separate file for the debugger to use, so that when you ask the debugger to show the value of the variable <code>x<\/code>, it knows to look in <code>00437180h<\/code>, but that happens outside of the execution environment.)<\/p>\n<p> It&#8217;s like asking, &#8220;What happens to the phrase <i>1 cup sugar<\/i> when I eat my cookies?&#8221; The phrase <i>1 cup sugar<\/i> was part of the instructions for making the cookies. Once you finish following the recipe, the instructions aren&#8217;t needed any more. Or at least not for the process of enjoying cookies. (You might still want to hang onto them to debug your recipe!) <\/p>\n","protected":false},"excerpt":{"rendered":"<p>nick_journals demonstrates some confusion about names in source code and their relationship to runtime behavior. A topic I am particularly interested in is the naming of controls, how it works&#8230; Every control gets a name from a developer&#8230;via the IDE (e.g btnOK) When using this function: GetWindowLong(handle,GWL_ID) it doesn&#8217;t return the name itself but mostly [&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-14473","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>nick_journals demonstrates some confusion about names in source code and their relationship to runtime behavior. A topic I am particularly interested in is the naming of controls, how it works&#8230; Every control gets a name from a developer&#8230;via the IDE (e.g btnOK) When using this function: GetWindowLong(handle,GWL_ID) it doesn&#8217;t return the name itself but mostly [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/14473","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=14473"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/14473\/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=14473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=14473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=14473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}