{"id":34763,"date":"2005-08-01T10:00:11","date_gmt":"2005-08-01T10:00:11","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2005\/08\/01\/rendering-standard-windows-elements\/"},"modified":"2005-08-01T10:00:11","modified_gmt":"2005-08-01T10:00:11","slug":"rendering-standard-windows-elements","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050801-11\/?p=34763","title":{"rendered":"Rendering standard Windows elements"},"content":{"rendered":"<p><P>\n<A HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/gdi\/pantdraw_4b3g.asp\">\nThe <CODE>DrawFrameControl<\/CODE> function<\/A>\nallows you to render standard Windows elements in your custom controls.\nLet&#8217;s start by simply rendering a selected radio button.\nStart with our\n<A>\nnew scratch program<\/A>\nand make this very simple change:\n<\/P>\n<PRE>\nclass RootWindow : public Window\n{\n &#8230;\nprotected:\n <FONT COLOR=\"blue\">void PaintContent(PAINTSTRUCT *pps);<\/FONT>\n &#8230;\n};<\/p>\n<p>void RootWindow::PaintContent(PAINTSTRUCT *pps)\n{\n <FONT COLOR=\"blue\">RECT rc = { 0, 0, 32, 32 };\n DrawFrameControl(pps-&gt;hdc, &amp;rc, DFC_BUTTON,\n                  DFCS_BUTTONRADIO | DFCS_CHECKED);<\/FONT>\n}\n<\/PRE>\n<P>\nWhen you run the program, you&#8217;ll see a little radio\nbutton in the corner.\nWoo-hoo.\n<\/P>\n<P>\nYou might also notice that it&#8217;s an unthemed radio button.\nTo get a themed radio button, you need to use the theme-drawing functions\ndefined in the <CODE>uxtheme.h<\/CODE> header file.\nLet&#8217;s make the following further changes:\n<\/P>\n<PRE>\nclass RootWindow : public Window\n{\n &#8230;\nprotected:\n <FONT COLOR=\"blue\">void OpenTheme() { m_htheme = OpenThemeData(m_hwnd, L&#8221;Button&#8221;); }\n void CloseTheme()\n {\n  if (m_htheme) { CloseThemeData(m_htheme); m_htheme = NULL; }\n }\n RootWindow() : m_htheme(NULL) { }\n ~RootWindow() { CloseTheme(); }<\/FONT>\n &#8230;\n};<\/p>\n<p>LRESULT RootWindow::OnCreate()\n{\n <FONT COLOR=\"blue\">OpenTheme();<\/FONT>\n return 0;\n}<\/p>\n<p>void RootWindow::PaintContent(PAINTSTRUCT *pps)\n{\n RECT rc = { 0, 0, 32, 32 };\n <FONT COLOR=\"blue\">if (m_htheme) {\n  DrawThemeBackground(m_htheme, pps-&gt;hdc,\n                      BP_RADIOBUTTON, RBS_CHECKEDNORMAL,\n                      &amp;rc, NULL);\n } else {<\/FONT>\n  DrawFrameControl(pps-&gt;hdc, &amp;rc, DFC_BUTTON,\n                   DFCS_BUTTONRADIO | DFCS_CHECKED);\n <FONT COLOR=\"blue\">}<\/FONT>\n}<\/p>\n<p>LRESULT RootWindow::HandleMessage(&#8230;)\n{\n &#8230;\n  <FONT COLOR=\"blue\">case WM_THEMECHANGED:\n   CloseTheme();\n   OpenTheme();\n   break;<\/FONT>\n &#8230;\n}\n<\/PRE>\n<P>\nThis new version attempts to open the &#8220;Button&#8221; theme for the window\nwhen the window is created.\nIf themes are not enabled, then this call will fail.\nWhen it comes time to draw, we see whether we have a theme\navailable.\nIf so, then we use\n<A HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/shellcc\/platform\/commctls\/userex\/functions\/drawthemebackground.asp\">\nthe <CODE>DrawThemeBackground<\/CODE> function<\/A> to draw it;\notherwise, we draw it the unthemed way.\nOf course, we close the theme handle at destruction,\nand we also refresh the theme handle if the user changes the theme.\n<\/P>\n<P>\nIf you run this new program with themes enabled,\nthen you will get the pretty themed radio button\ninstead of the old-fashioned unthemed radio button.\n<\/P>\n<P>\nNext time, we&#8217;ll look at the trickier menu bitmaps.\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The DrawFrameControl function allows you to render standard Windows elements in your custom controls. Let&#8217;s start by simply rendering a selected radio button. Start with our new scratch program and make this very simple change: class RootWindow : public Window { &#8230; protected: void PaintContent(PAINTSTRUCT *pps); &#8230; }; void RootWindow::PaintContent(PAINTSTRUCT *pps) { RECT rc = [&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-34763","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The DrawFrameControl function allows you to render standard Windows elements in your custom controls. Let&#8217;s start by simply rendering a selected radio button. Start with our new scratch program and make this very simple change: class RootWindow : public Window { &#8230; protected: void PaintContent(PAINTSTRUCT *pps); &#8230; }; void RootWindow::PaintContent(PAINTSTRUCT *pps) { RECT rc = [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/34763","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=34763"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/34763\/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=34763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=34763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=34763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}