{"id":13893,"date":"2010-05-28T07:00:00","date_gmt":"2010-05-28T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/05\/28\/every-window-with-the-ws_sysmenu-style-has-a-system-menu-but-its-not-there-until-it-needs-to-be\/"},"modified":"2010-05-28T07:00:00","modified_gmt":"2010-05-28T07:00:00","slug":"every-window-with-the-ws_sysmenu-style-has-a-system-menu-but-its-not-there-until-it-needs-to-be","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20100528-00\/?p=13893","title":{"rendered":"Every window with the WS_SYSMENU style has a system menu, but it&#039;s not there until it needs to be"},"content":{"rendered":"<p>I mentioned last time that <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/05\/27\/10016004.aspx\"> there&#8217;s an optimization in the treatment of the system menu<\/a> which significantly reduces the number of menus in the system.\n When a window has the <code>WS_SYSMENU<\/code> window style, it has a system menu, but until somebody calls <code>Get&shy;System&shy;Menu<\/code> on that window, nobody knows what its menu handle is. Until that point, the window manager doesn&#8217;t actually have to commit to creating a menu for the window; it can just pretend that the window has one. (This technique goes by the fancy name <i>lazy initialization<\/i>.)\n The window manager creates a global default system menu which contains the standard system menu items. If somebody presses Alt+Space or otherwise calls up the system menu for a window that has never had <code>Get&shy;System&shy;Menu<\/code> called on it, the window manager just uses the global default system menu, since it knows that nobody has customized the menu. (You can&#8217;t customize a menu you don&#8217;t have the handle to!) Since most people never customize their system menu, this optimization avoids cluttering the desktop heap with identical copies of the same menu. This was a particularly important optimization back in the 16-bit days, when all window manager objects had to fit into a single 64KB heap (known as <i>System Resources<\/i>).\n If you are really sneaky, you can catch a glimpse of the elusive <i>global default system menu<\/i> as it whizzes by: As with any other popup menu, the handle to the menu being displayed is passed to your window&#8217;s <code>WM_INIT&shy;MENU&shy;POPUP<\/code>, and if your program has never called <code>Get&shy;System&shy;Menu<\/code>, the handle that you will see is the global default system menu. Mind you, you can&#8217;t do much to this menu, since the window manager blocks any attempt to modify it. (Otherwise, your program&#8217;s menu modification would have an unintended effect on the menus of other programs!)<\/p>\n<p> Therefore, if your program is in the habit of modifying its system menu in its <code>WM_INIT&shy;MENU&shy;POPUP<\/code> handler, you should stick a dummy call to <code>Get&shy;System&shy;Menu<\/code> in your <code>WM_CREATE<\/code> handler to force your system menu to change from a pretend system menu to a real one. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I mentioned last time that there&#8217;s an optimization in the treatment of the system menu which significantly reduces the number of menus in the system. When a window has the WS_SYSMENU window style, it has a system menu, but until somebody calls Get&shy;System&shy;Menu on that window, nobody knows what its menu handle is. Until that [&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-13893","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>I mentioned last time that there&#8217;s an optimization in the treatment of the system menu which significantly reduces the number of menus in the system. When a window has the WS_SYSMENU window style, it has a system menu, but until somebody calls Get&shy;System&shy;Menu on that window, nobody knows what its menu handle is. Until that [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/13893","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=13893"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/13893\/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=13893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=13893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=13893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}