Font size
-
Hi everybody. I have noticed that some controls in Visual C++ allow to change their font size. Others don´t allow it, and it takes it from the size you set on the Dialog properties. To change that, I have created my own font with the CFont class like this: ************************************ CFont m_fuente; LOGFONT lf; m_fuente.CreateStockObject(DEFAULT_GUI_FONT); m_fuente.GetLogFont(&lf); strcpy(lf.lfFaceName,"MS Sans Serif"); lf.lfWeight =700; lf.lfHeigth =16; m_fuente.DeleteObject(); m_fuente.CreateFontIndirect(&lf); **************************************** My question is about the size. Using lf.lfHeigth = 20 will not make words bigger, it will just make the space around the word bigger (check it in a combo box, for example, increasing the lfheigth of a combo box would make the space between words bigger. Does anybody know how to fix this? Thank you!!!
Time to come clean... Vive y deja vivir / Live and let live Javier
-
Hi everybody. I have noticed that some controls in Visual C++ allow to change their font size. Others don´t allow it, and it takes it from the size you set on the Dialog properties. To change that, I have created my own font with the CFont class like this: ************************************ CFont m_fuente; LOGFONT lf; m_fuente.CreateStockObject(DEFAULT_GUI_FONT); m_fuente.GetLogFont(&lf); strcpy(lf.lfFaceName,"MS Sans Serif"); lf.lfWeight =700; lf.lfHeigth =16; m_fuente.DeleteObject(); m_fuente.CreateFontIndirect(&lf); **************************************** My question is about the size. Using lf.lfHeigth = 20 will not make words bigger, it will just make the space around the word bigger (check it in a combo box, for example, increasing the lfheigth of a combo box would make the space between words bigger. Does anybody know how to fix this? Thank you!!!
Time to come clean... Vive y deja vivir / Live and let live Javier
-
See the
nHeight
explanation here [^]. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
I guess it is all about that line that I do not understand ;P nHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72); Can you explain me what it means? Thanks!
Time to come clean... Vive y deja vivir / Live and let live Javier
-
I guess it is all about that line that I do not understand ;P nHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72); Can you explain me what it means? Thanks!
Time to come clean... Vive y deja vivir / Live and let live Javier
This code is for convert of points to logical device coordinates.
WhiteSky
-
This code is for convert of points to logical device coordinates.
WhiteSky
O_o Aha... So how do I say that I want the font size to be 20, for example? ;P
Time to come clean... Vive y deja vivir / Live and let live Javier
-
I guess it is all about that line that I do not understand ;P nHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72); Can you explain me what it means? Thanks!
Time to come clean... Vive y deja vivir / Live and let live Javier
garfield185 wrote:
I guess it is all about that line that I do not understand
You also have to be aware that the system matches your request again available fonts.
garfield185 wrote:
nHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72); Can you explain me what it means?
OK. It simply states that
nHeight
isn't the pixel height of the font, but it is related with it by the factorGetDeviceCaps(hDC, LOGPIXELSY)/72
that is system-dependant. On my Laptop the factor is1.33
meaning that I have to specifynHeight=27
(let's forget for the minus sign) to obtain a 20-point sized font (andnHeight=21
to obtain the 16-point one). On your system maybe the difference between the requested font heights it's so small that the same font is choosen. Hope that helps. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
O_o Aha... So how do I say that I want the font size to be 20, for example? ;P
Time to come clean... Vive y deja vivir / Live and let live Javier
garfield185 wrote:
So how do I say that I want the font size to be 20, for example?
you have to set
nHeight
as follows:nHeight = -MulDiv(20, GetDeviceCaps(hDC, LOGPIXELSY), 72);
:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
garfield185 wrote:
I guess it is all about that line that I do not understand
You also have to be aware that the system matches your request again available fonts.
garfield185 wrote:
nHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72); Can you explain me what it means?
OK. It simply states that
nHeight
isn't the pixel height of the font, but it is related with it by the factorGetDeviceCaps(hDC, LOGPIXELSY)/72
that is system-dependant. On my Laptop the factor is1.33
meaning that I have to specifynHeight=27
(let's forget for the minus sign) to obtain a 20-point sized font (andnHeight=21
to obtain the 16-point one). On your system maybe the difference between the requested font heights it's so small that the same font is choosen. Hope that helps. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
Excuse my no-knowledge... No it says that "hDC" is not declared... What data does the function GetDeviceCaps need? Moreover, I guess LOGPIXELSY is a constant that I must define... :omg:
Time to come clean... Vive y deja vivir / Live and let live Javier
-
Excuse my no-knowledge... No it says that "hDC" is not declared... What data does the function GetDeviceCaps need? Moreover, I guess LOGPIXELSY is a constant that I must define... :omg:
Time to come clean... Vive y deja vivir / Live and let live Javier
hDC
must be a valid handle of a device context (HDC). Using MFC you can pass the HDC of the current window (provided the code belongs to a window class)nHeight = -MulDiv(20, GetDeviceCaps(GetDC()->m_hDC, LOGPIXELSY), 72);
you can also use the screen HDC for the pourpose:
nHeight = -MulDiv(20, GetDeviceCaps(::GetDC(NULL), LOGPIXELSY), 72);
garfield185 wrote:
I guess LOGPIXELSY is a constant that I must define
No you must NOT define it, since it is already defined inside
windows.h
header file. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
hDC
must be a valid handle of a device context (HDC). Using MFC you can pass the HDC of the current window (provided the code belongs to a window class)nHeight = -MulDiv(20, GetDeviceCaps(GetDC()->m_hDC, LOGPIXELSY), 72);
you can also use the screen HDC for the pourpose:
nHeight = -MulDiv(20, GetDeviceCaps(::GetDC(NULL), LOGPIXELSY), 72);
garfield185 wrote:
I guess LOGPIXELSY is a constant that I must define
No you must NOT define it, since it is already defined inside
windows.h
header file. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
Fine. No errors. Anyway the size does no change. Am I missing something? Here is all the written code. ************************ CFont m_fuente; LOGFONT lf; m_fuente.CreateStockObject(DEFAULT_GUI_FONT); m_fuente.GetLogFont(&lf); strcpy(lf.lfFaceName,"MS Sans Serif"); lf.lfHeight = -MulDiv(50, GetDeviceCaps(GetDC()->m_hDC, LOGPIXELSY), 72); lf.lfWeight =700; m_fuente.DeleteObject(); m_fuente.CreateFontIndirect(&lf); m_label.SetFont(&m_fuente); ****************************** Should it be like this?
Time to come clean... Vive y deja vivir / Live and let live Javier
-
Excuse my no-knowledge... No it says that "hDC" is not declared... What data does the function GetDeviceCaps need? Moreover, I guess LOGPIXELSY is a constant that I must define... :omg:
Time to come clean... Vive y deja vivir / Live and let live Javier
garfield185 wrote:
What data does the function GetDeviceCaps need?
See here.
garfield185 wrote:
Moreover, I guess LOGPIXELSY is a constant that I must define...
No.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
garfield185 wrote:
What data does the function GetDeviceCaps need?
See here.
garfield185 wrote:
Moreover, I guess LOGPIXELSY is a constant that I must define...
No.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
Pallini told me about that. I get no errors. What I say is that the code I wrote on the post before does not change the size of the text...
Time to come clean... Vive y deja vivir / Live and let live Javier
-
Fine. No errors. Anyway the size does no change. Am I missing something? Here is all the written code. ************************ CFont m_fuente; LOGFONT lf; m_fuente.CreateStockObject(DEFAULT_GUI_FONT); m_fuente.GetLogFont(&lf); strcpy(lf.lfFaceName,"MS Sans Serif"); lf.lfHeight = -MulDiv(50, GetDeviceCaps(GetDC()->m_hDC, LOGPIXELSY), 72); lf.lfWeight =700; m_fuente.DeleteObject(); m_fuente.CreateFontIndirect(&lf); m_label.SetFont(&m_fuente); ****************************** Should it be like this?
Time to come clean... Vive y deja vivir / Live and let live Javier
The only problem I saw in your code was the declaration of
CFont m_fuente;
since
m_fuente
has to be a member of the Window class (otherwise it will be destroyed...) I declared CFont as a member of myCDialog
class and your code is working fine (I see a label with very, very big characters :-D). :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
The only problem I saw in your code was the declaration of
CFont m_fuente;
since
m_fuente
has to be a member of the Window class (otherwise it will be destroyed...) I declared CFont as a member of myCDialog
class and your code is working fine (I see a label with very, very big characters :-D). :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
YEAH!!!! You are the best!!!! Thanks a lot!! I was creatin m_fuente on each function. I didn´t know it had to be a member of the class... Thank you very much!!
Time to come clean... Vive y deja vivir / Live and let live Javier