CHARFORMAT cf;
memset(&cf, 0, sizeof(CHARFORMAT));
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_SIZE;
cf.yHeight = 320; // This is in TWIPS!
SendMessage(hEdit, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
[\CODE]
There are no errors in the code. The problem is that Rich Edit controls use twips (a twip is 1/1440th of an inch). I need to convert normal point size (for example, size 10, Courier New is what I use in VS 2005 for coding) to twips. is there an easy way to do this?
I actually like the concept of twips (screen units, rather than pixel units - it's better for portability across any screen resolution). But unfortunately the font picker dialog doesn't use them. And most people don't either.
Oh, and the point size is not known at compile time (unlike in the example).
Rich edit controls - change the font size? (Win32, C++)
I'm trying to figure out how to set the size of the text in a rich edit control. Here's what I'm using:
Don't know if this helps:
Relationship Between Inches, Picas, Points, Pitch, and Twips (http://support.microsoft.com/kb/76388)
Relationship Between Inches, Picas, Points, Pitch, and Twips (http://support.microsoft.com/kb/76388)
From some of my code:
void CDruinkEdit::SetFont(const std::string& strFont, int nSize){ // Copy data m_strFont = strFont; m_nFontSize = nSize; // Setup char format CHARFORMAT cfFormat; memset(&cfFormat, 0, sizeof(cfFormat)); cfFormat.cbSize = sizeof(cfFormat); cfFormat.dwMask = CFM_CHARSET | CFM_FACE | CFM_SIZE; cfFormat.bCharSet = ANSI_CHARSET; cfFormat.bPitchAndFamily = FIXED_PITCH | FF_DONTCARE; cfFormat.yHeight = (nSize*1440)/72; strcpy(cfFormat.szFaceName, strFont.c_str()); // Set char format and goto end of text CHARRANGE cr; cr.cpMin = INT_MAX; cr.cpMax = INT_MAX; SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cfFormat); SendMessage(m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);}
Thanks Evil Steve, it seems to work ok.
But I think that assumes my monitor DPI is 1/72", right? What if the DPI is higher?
I suppose I would need to find a way to get the monitor's DPI...is there an API call somewhere?
Edit: The link you gave me, NisseBosseLasse, says that a twip is 1/20th of a point. That seems to work too, prolly because 1440/72 is 20. Thnx both of you.
But I think that assumes my monitor DPI is 1/72", right? What if the DPI is higher?
I suppose I would need to find a way to get the monitor's DPI...is there an API call somewhere?
Edit: The link you gave me, NisseBosseLasse, says that a twip is 1/20th of a point. That seems to work too, prolly because 1440/72 is 20. Thnx both of you.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement