I am trying to set the font used to print within my application using the Windows API. I am using Microsoft Visual C++ Version 4.
I am using the following code to select and create a font:
HFONT GetFont(HDC hDC)
/* Initialize members of the CHOOSEFONT structure. */
cf.lStructSize = sizeof(CHOOSEFONT);
cf.hwndOwner = (HWND)NULL;
cf.hDC = hDC;
cf.lpLogFont = &lf;
cf.iPointSize = 0;
cf.Flags = CF_SCREENFONTS;
cf.rgbColors = RGB(0,0,0);
cf.lCustData = 0L;
cf.lpfnHook = (LPCFHOOKPROC)NULL;
cf.lpTemplateName = (LPSTR)NULL;
cf.hInstance = (HINSTANCE) NULL;
cf.lpszStyle = (LPSTR)NULL;
cf.nFontType = SCREEN_FONTTYPE;
cf.nSizeMin = 0;
cf.nSizeMax = 0;
/* Display the CHOOSEFONT common-dialog box. */
/* Create a logical font based on the user's */
/* selection and return a handle identifying */
/* that font. */
hfont = CreateFontIndirect(cf.lpLogFont);
which I have taken direct from the online Help. This seems to set the correct style but the point size is incorrect. If I select Arial 10 point when prompted, the resulatant print appears to be more like Arial 13 point. Arial 8 point is more like 10 point and so on for all sizes. I have printed from my app and from Microsoft Word to the same printer to compare fonts and all fonts from my application are larger than anticipated. This applies for all fonts, not just the Arial style. I have also tried different printers but achieve the same result.
Using this line:
lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
(again from the online help) and setting the lfHeight member of the struct used above produces HUGE fonts. I made sure the mapping mode was set to MM_TEXT for this but still did not resolve the problem.
Is there another way I shluld be setting fonts in order to get the correct size that the user expects?
Please Note: We are not using MFC in our application which is why I am going direct to the API.
Any help would be greatly appreciated.
Thanks in advance