<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="https://syndication.webwiz.net/rss_namespace/">
 <channel>
  <title>Codejock Developer Community : Bug with XTFuncChangeWindowFont</title>
  <link>http://forum.codejock.com/</link>
  <description><![CDATA[This is an XML content feed of; Codejock Developer Community : Toolkit Pro : Bug with XTFuncChangeWindowFont]]></description>
  <copyright>Copyright (c) 2006-2013 Web Wiz Forums - All Rights Reserved.</copyright>
  <pubDate>Sun, 05 Apr 2026 19:02:27 +0000</pubDate>
  <lastBuildDate>Tue, 03 Oct 2006 11:15:24 +0000</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 12.04</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>forum.codejock.com/RSS_post_feed.asp?TID=5204</WebWizForums:feedURL>
  <image>
   <title><![CDATA[Codejock Developer Community]]></title>
   <url>http://forum.codejock.com/forum_images/codejock-logo.gif</url>
   <link>http://forum.codejock.com/</link>
  </image>
  <item>
   <title><![CDATA[Bug with XTFuncChangeWindowFont : I just noticed that you have a...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=5204&amp;PID=16266&amp;title=bug-with-xtfuncchangewindowfont#16266</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=2321">JohnCrenshaw</a><br /><strong>Subject:</strong> 5204<br /><strong>Posted:</strong> 03 October 2006 at 11:15am<br /><br />I just noticed that you have a function to change the font in a screen. Since I had to do something like this myself recently I looked at your implementation.<DIV>&nbsp;</DIV><DIV>There is a bug in the function resulting from Microsoft's failure to document anything right. I know because I had an identical bug in my own implementation for over a year before I found out what was wrong.</DIV><DIV>&nbsp;</DIV><DIV>You start the function (as I did) by grabbing the TEXTMETRIC for the old and new fonts. Then when you are converting you use (tmNew.tmAveCharWidth / tmOld.tmAveCharWidth) as your normalization ratio. This is the problem. In windows Dialog units ARE calculated using the average character width HOWEVER, the REAL average character width is used, not the "AveCharWidth" in the text metric (which is actually just the width of 'x')</DIV><DIV>&nbsp;</DIV><DIV>Believe it or not, this does make a significant difference, both functionally and cosmeticly.&nbsp;Here is a snippet from my code that made all the difference in fixing this:</DIV><DIV>&nbsp;</DIV><DIV><table width="99%"><tr><td><pre class="BBcode"></DIV><DIV><FONT size=1><P></FONT><FONT color=#008000 size=1>// grab old and new text metrics</P></FONT><FONT size=1><P></FONT><FONT color=#010001 size=1>TEXTMETRIC</FONT><FONT size=1> </FONT><FONT color=#010001 size=1>tmOld</FONT><FONT size=1>;</P><P></FONT><FONT color=#010001 size=1>TEXTMETRIC</FONT><FONT size=1> </FONT><FONT color=#010001 size=1>tmNew</FONT><FONT size=1>;</P><P></FONT><FONT color=#010001 size=1>CDC</FONT><FONT size=1> * </FONT><FONT color=#010001 size=1>pDC</FONT><FONT size=1> = </FONT><FONT color=#010001 size=1>pWnd</FONT><FONT size=1>-&gt;</FONT><FONT color=#010001 size=1>GetDC</FONT><FONT size=1>();</P><P></FONT><FONT color=#010001 size=1>CFont</FONT><FONT size=1>* </FONT><FONT color=#010001 size=1>pSavedFont</FONT><FONT size=1> = </FONT><FONT color=#010001 size=1>pDC</FONT><FONT size=1>-&gt;</FONT><FONT color=#010001 size=1>SelectObject</FONT><FONT size=1>(</FONT><FONT color=#010001 size=1>pWnd</FONT><FONT size=1>-&gt;</FONT><FONT color=#010001 size=1>GetFont</FONT><FONT size=1>());</P><P></FONT><FONT color=#010001 size=1>pDC</FONT><FONT size=1>-&gt;</FONT><FONT color=#010001 size=1>GetTextMetrics</FONT><FONT size=1>(&amp;</FONT><FONT color=#010001 size=1>tmOld</FONT><FONT size=1>);</P><P></FONT><FONT color=#010001 size=1>SIZE</FONT><FONT size=1> </FONT><FONT color=#010001 size=1>size</FONT><FONT size=1>;</P><P></FONT><FONT color=#010001 size=1>size</FONT><FONT size=1> = </FONT><FONT color=#010001 size=1>pDC</FONT><FONT size=1>-&gt;</FONT><FONT color=#010001 size=1>GetTextExtent</FONT><FONT size=1>(</FONT><FONT color=#010001 size=1>_T</FONT><FONT size=1>(</FONT><FONT color=#a31515 size=1>"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"</FONT><FONT size=1>),52);</P><P></FONT><FONT color=#008000 size=1>// tmAveCharWidth is actually an approximation based on getting the width of "x". The system</P></FONT><FONT size=1><P></FONT><FONT color=#008000 size=1>// doesn't use these approximations at the low level when it converts between dialog units</P></FONT><FONT size=1><P></FONT><FONT color=#008000 size=1>// and pixels. To do this conversion properly we have to calculate the actual average.</P></FONT><FONT size=1><P></FONT><FONT color=#010001 size=1>tmOld</FONT><FONT size=1>.</FONT><FONT color=#010001 size=1>tmAveCharWidth</FONT><FONT size=1> = (</FONT><FONT color=#010001 size=1>size</FONT><FONT size=1>.</FONT><FONT color=#010001 size=1>cx</FONT><FONT size=1>/26+1)/2;</P><P></FONT><FONT color=#010001 size=1>pDC</FONT><FONT size=1>-&gt;</FONT><FONT color=#010001 size=1>SelectObject</FONT><FONT size=1>(</FONT><FONT color=#010001 size=1>pFont</FONT><FONT size=1>);</P><P></FONT><FONT color=#010001 size=1>pDC</FONT><FONT size=1>-&gt;</FONT><FONT color=#010001 size=1>GetTextMetrics</FONT><FONT size=1>(&amp;</FONT><FONT color=#010001 size=1>tmNew</FONT><FONT size=1>);</P><P></FONT><FONT color=#010001 size=1>size</FONT><FONT size=1> = </FONT><FONT color=#010001 size=1>pDC</FONT><FONT size=1>-&gt;</FONT><FONT color=#010001 size=1>GetTextExtent</FONT><FONT size=1>(</FONT><FONT color=#010001 size=1>_T</FONT><FONT size=1>(</FONT><FONT color=#a31515 size=1>"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"</FONT><FONT size=1>),52);</P><P></FONT><FONT color=#008000 size=1>// tmAveCharWidth is actually an approximation based on getting the width of "x". The system</P></FONT><FONT size=1><P></FONT><FONT color=#008000 size=1>// doesn't use these approximations at the low level when it converts between dialog units</P></FONT><FONT size=1><P></FONT><FONT color=#008000 size=1>// and pixels. To do this conversion properly we have to calculate the actual average.</P></FONT><FONT size=1><P></FONT><FONT color=#010001 size=1>tmNew</FONT><FONT size=1>.</FONT><FONT color=#010001 size=1>tmAveCharWidth</FONT><FONT size=1> = (</FONT><FONT color=#010001 size=1>size</FONT><FONT size=1>.</FONT><FONT color=#010001 size=1>cx</FONT><FONT size=1>/26+1)/2;</P></FONT></pre></td></tr></table></DIV><DIV>&nbsp;</DIV>]]>
   </description>
   <pubDate>Tue, 03 Oct 2006 11:15:24 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=5204&amp;PID=16266&amp;title=bug-with-xtfuncchangewindowfont#16266</guid>
  </item> 
 </channel>
</rss>