{"id":105467,"date":"2021-07-21T07:00:00","date_gmt":"2021-07-21T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=105467"},"modified":"2021-07-21T06:11:56","modified_gmt":"2021-07-21T13:11:56","slug":"20210721-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20210721-00\/?p=105467","title":{"rendered":"I know I can change the color of the DC pen, but what about the other attributes?"},"content":{"rendered":"<p>Some time ago, I called out <a title=\"What is the DC brush good for?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050420-28\/?p=35843\"> the usefulness of the DC pen and DC brush<\/a>: They always exist, each DC gets one, and you can change their colors dynamically. They are handy when you have some operation that requires a brush or pen, and you don&#8217;t really want to create one, use it for the operation, and then destroy it.<\/p>\n<p>In a way, the DC pen and DC brush let you pretend that there are no brushes or pens at all, just colors. If there&#8217;s an operation that requires a brush, you can pretend that it takes a color: Set the DC brush to that color, and then perform the operation with the DC brush.<\/p>\n<pre>HBRUSH g_dcBrush = (HBRUSH)GetStockObject(DC_BRUSH);\r\n\r\nint FillRect(HDC hdc, const RECT* rect, COLORREF color)\r\n{\r\n color = SetDCBrushColor(hdc, color);\r\n auto result = FillRect(hdc, rect, g_dcBrush);\r\n SetDCBrushColor(hdc, color);\r\n}\r\n<\/pre>\n<p>The DC brush is a solid color brush.<\/p>\n<p>The DC pen is a solid pen of width zero, which means that it draws one device pixel. All other properties are at their defaults (round join, endcap round).<\/p>\n<p>The only thing you can change about the DC brush and DC pen are their colors. The other attributes are locked. If you need a pen or brush with attributes different from the ones provided by the DC pen or brush, you&#8217;ll have to create your own brush. Sorry.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>They&#8217;re locked in, sorry.<\/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-105467","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>They&#8217;re locked in, sorry.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105467","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=105467"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105467\/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=105467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=105467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=105467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}