关于CreateFont的疑问

六道佩恩 2019-08-08 02:09:41
第4个参数cOrientation表示旋转角度,可测试没效果呀,用SetTextAlign指定基线对齐的方式也没看到效果。
对于倒数第5 到 倒数第2 这4个参数也不解,测试出来也没看到效果,看不懂官方的说明,百度的结果也大多都是照搬的
求解
...全文
146 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2019-08-09
  • 打赏
  • 举报
回复
引用 6 楼 六道佩恩 的回复:
[quote=引用 3 楼 赵4老师 的回复:] CreateFont The CreateFont function creates a logical font that has specific characteristics. The logical font can subsequently be selected as the font for any device.
赵老师,官方文档已经看过的,但是并不懂它描述的什么[/quote] 那就逐行调试一下官方例子代码加深理解喽。
Intel0011 2019-08-08
  • 打赏
  • 举报
回复
引用 楼主 六道佩恩 的回复:
第4个参数cOrientation表示旋转角度,可测试没效果呀,用SetTextAlign指定基线对齐的方式也没看到效果。 对于倒数第5 到 倒数第2 这4个参数也不解,测试出来也没看到效果,看不懂官方的说明,百度的结果也大多都是照搬的 求解
我猜你可能没使用SelectObject将字体选人hdc 至于倒数第5 到 倒数第2 这4个参数,没关注过,一般只用默认值
#define GUI
//*
#define UNICODE
#define _UNICODE
//*/
#include <Windows.h>
#include <tchar.h>
#include <stdio.h>

#pragma comment(lib, "gdi32")
#pragma comment(lib, "user32")

#pragma comment(linker, "/subsystem:windows")

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR szCmdLine, int iCmdShow)
{
   static TCHAR szAppName[] = TEXT("HelloWin");
   HWND         hwnd;
   MSG          msg;
   WNDCLASS     wndclass;
      
   RtlZeroMemory(&wndclass, sizeof(wndclass));
   wndclass.style         = CS_HREDRAW | CS_VREDRAW;
   wndclass.lpfnWndProc   = WndProc;
   wndclass.hInstance     = hInstance;
   wndclass.hIcon         = LoadIcon(NULL, TEXT("#32512"));
   wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
   wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
   wndclass.lpszMenuName  = NULL;
   wndclass.lpszClassName = szAppName;

   if (!RegisterClass(&wndclass))
   {
      MessageBox(NULL, TEXT("This program requires Windows NT series!"), szAppName, MB_ICONERROR);
      return -1;
   }
     
   hwnd = CreateWindowEx(WS_EX_APPWINDOW,         // A tool window does not appear in the task bar or in the window that appears when the user presses ALT+TAB.
                         szAppName,                  // window class name
                         TEXT("The Hello Program"),  // window caption
                         WS_OVERLAPPEDWINDOW,        // window style
                         CW_USEDEFAULT,              // initial x position
                         CW_USEDEFAULT,              // initial y position
                         820,//CW_USEDEFAULT,              // initial x size
                         620,//CW_USEDEFAULT,              // initial y size
                         NULL,
                         NULL,                       // window menu handle
                         hInstance,                  // program instance handle
                         NULL);                      // creation parameters

   ShowWindow(hwnd, SW_SHOW);
   UpdateWindow(hwnd);  
   
   {
      BOOL bRet;
      while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
      {
         if (bRet == -1)
         {
            MessageBox(NULL, TEXT("GetMessage Error."), TEXT("Message"), MB_ICONERROR);
            return -1;
         }
         else
         {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
         }
      }
   }

   return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   HDC         hdc;
   PAINTSTRUCT ps;
   HFONT       hFont;
   static TCHAR szString [] = TEXT("   Rotation");
   static int  cxClient, cyClient;
      
   switch (message)
   {
      case WM_SIZE:
         cxClient = LOWORD(lParam);
         cyClient = HIWORD(lParam);
         return 0;
      case WM_PAINT:
         hdc = BeginPaint(hwnd, &ps);
         hFont = CreateFont(60,                    //字体的高度
                            30,                    //字体的宽度
                            300,                   //字体显示的角度
                            0,                     //字体的角度
                            FW_NORMAL,             //字体的磅数
                            TRUE,                  //斜体字体
                            TRUE,                  //带下划线的字体
                            TRUE,                  //带删除线的字体
                            CHINESEBIG5_CHARSET,   //所需的字符集
                            OUT_CHARACTER_PRECIS,  //输出的精度
                            CLIP_CHARACTER_PRECIS, //裁减的精度 
                            DEFAULT_QUALITY,       //逻辑字体与输出设备的实际字体之间的精度
                            FF_MODERN,             //字体间距和字体集
                            _T("Times New Roman")  //字体名称
                           );
         SelectObject(hdc, hFont);
         TextOut(hdc, cxClient / 2, cyClient / 2, szString, lstrlen(szString));
         DeleteObject(SelectObject(hdc, GetStockObject(SYSTEM_FONT)));
         EndPaint(hwnd, &ps);
         return 0;
      case WM_DESTROY:
         PostQuitMessage(0);
         return 0;
   }
   return DefWindowProc(hwnd, message, wParam, lParam);
}
赵4老师 2019-08-08
  • 打赏
  • 举报
回复
六道佩恩 2019-08-08
  • 打赏
  • 举报
回复
引用 3 楼 赵4老师 的回复:
CreateFont The CreateFont function creates a logical font that has specific characteristics. The logical font can subsequently be selected as the font for any device.
赵老师,官方文档已经看过的,但是并不懂它描述的什么
六道佩恩 2019-08-08
  • 打赏
  • 举报
回复
引用 2 楼 Intel0011 的回复:
我猜你可能没使用SelectObject将字体选人hdc 至于倒数第5 到 倒数第2 这4个参数,没关注过,一般只用默认值
肯定有用SelectObject呀,不然我咋不说其他那些参数看不到效果 我知道一般用默认值,但即便不用默认值也没看到什么不同。。。
赵4老师 2019-08-08
  • 打赏
  • 举报
回复
FontView: Font Usage Click to open or copy the files for the FontView sample. The FontView sample demonstrates several programming aspects. As a stand-alone application, it allows you to experiment with the various parameters of the CreateFont function, as well as examine the fonts and metrics returned by the call. Building SDK Samples This sample uses the following keywords: _moveto; abs; circleblt; cos; createdlgproc; createfont; createsolidbrush; defined; deleteobject; destroywindow; dialogbox; dialogboxparam; enddialog; enumdlgproc; exttextout; fabs; freeprocinstance; getdc; getdlgitemtext; getfocus; getmenu; getstockobject; getsubmenu; getsyscolor; getsystemmenu; getwindowlong; getwindowtext; lstrcmp; lstrcpy; lstrlen; makeprocinstance; max; messagebeep; metricsdlgproc; min; moveto; movetoex; radian; releasedc; selectobject; sendmessage; setbkcolor; setdlgitemtext; settextcolor; setwindowtext; simpledlgproc; sin; updatepositions; warning; windowfrompoint; winmain
赵4老师 2019-08-08
  • 打赏
  • 举报
回复
CreateFont The CreateFont function creates a logical font that has specific characteristics. The logical font can subsequently be selected as the font for any device. HFONT CreateFont( int nHeight, // logical height of font int nWidth, // logical average character width int nEscapement, // angle of escapement int nOrientation, // base-line orientation angle int fnWeight, // font weight DWORD fdwItalic, // italic attribute flag DWORD fdwUnderline, // underline attribute flag DWORD fdwStrikeOut, // strikeout attribute flag DWORD fdwCharSet, // character set identifier DWORD fdwOutputPrecision, // output precision DWORD fdwClipPrecision, // clipping precision DWORD fdwQuality, // output quality DWORD fdwPitchAndFamily, // pitch and family LPCTSTR lpszFace // pointer to typeface name string ); Parameters nHeight Specifies the height, in logical units, of the font's character cell or character. The character height value (also known as the em height) is the character cell height value minus the internal-leading value. The font mapper interprets the value specified in nHeight in the following manner: Value Meaning > 0 The font mapper transforms this value into device units and matches it against the cell height of the available fonts. 0 The font mapper uses a default height value when it searches for a match. < 0 The font mapper transforms this value into device units and matches its absolute value against the character height of the available fonts. For all height comparisons, the font mapper looks for the largest font that does not exceed the requested size. This mapping occurs when the font is used for the first time. For the MM_TEXT mapping mode, you can use the following formula to specify a height for a font with a specified point size: nHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72); nWidth Specifies the average width, in logical units, of characters in the requested font. If this value is zero, the font mapper chooses a "closest match" value. The "closest match" value is determined by comparing the absolute values of the difference between the current device's aspect ratio and the digitized aspect ratio of available fonts. nEscapement Specifies the angle, in tenths of degrees, between the escapement vector and the x-axis of the device. The escapement vector is parallel to the base line of a row of text. Windows NT: When the graphics mode is set to GM_ADVANCED, you can specify the escapement angle of the string independently of the orientation angle of the string's characters. When the graphics mode is set to GM_COMPATIBLE, nEscapement specifies both the escapement and orientation. You should set nEscapement and nOrientation to the same value. Windows 95: The nEscapement parameter specifies both the escapement and orientation. You should set nEscapement and nOrientation to the same value. nOrientation Specifies the angle, in tenths of degrees, between each character's base line and the x-axis of the device. fnWeight Specifies the weight of the font in the range 0 through 1000. For example, 400 is normal and 700 is bold. If this value is zero, a default weight is used. The following values are defined for convenience: Value Weight FW_DONTCARE 0 FW_THIN 100 FW_EXTRALIGHT 200 FW_ULTRALIGHT 200 FW_LIGHT 300 FW_NORMAL 400 FW_REGULAR 400 FW_MEDIUM 500 FW_SEMIBOLD 600 FW_DEMIBOLD 600 FW_BOLD 700 FW_EXTRABOLD 800 FW_ULTRABOLD 800 FW_HEAVY 900 FW_BLACK 900 fdwItalic Specifies an italic font if set to TRUE. fdwUnderline Specifies an underlined font if set to TRUE. fdwStrikeOut Specifies a strikeout font if set to TRUE. fdwCharSet Specifies the character set. The following values are predefined: ANSI_CHARSET BALTIC_CHARSET CHINESEBIG5_CHARSET DEFAULT_CHARSET EASTEUROPE_CHARSET GB2312_CHARSET GREEK_CHARSET HANGUL_CHARSET MAC_CHARSET OEM_CHARSET RUSSIAN_CHARSET SHIFTJIS_CHARSET SYMBOL_CHARSET TURKISH_CHARSET Korean Windows: JOHAB_CHARSET Middle-Eastern Windows: HEBREW_CHARSET ARABIC_CHARSET Thai Windows: THAI_CHARSET The OEM_CHARSET value specifies a character set that is operating-system dependent. You can use the DEFAULT_CHARSET value to allow the name and size of a font to fully describe the logical font. If the specified font name does not exist, a font from any character set can be substituted for the specified font, so you should use DEFAULT_CHARSET sparingly to avoid unexpected results. Fonts with other character sets may exist in the operating system. If an application uses a font with an unknown character set, it should not attempt to translate or interpret strings that are rendered with that font. This parameter is important in the font mapping process. To ensure consistent results, specify a specific character set. If you specify a typeface name in the lpszFace parameter, make sure that the fdwCharSet value matches the character set of the typeface specified in lpszFace. fdwOutputPrecision Specifies the output precision. The output precision defines how closely the output must match the requested font's height, width, character orientation, escapement, pitch, and font type. It can be one of the following values: Value Meaning OUT_CHARACTER_PRECIS Not used. OUT_DEFAULT_PRECIS Specifies the default font mapper behavior. OUT_DEVICE_PRECIS Instructs the font mapper to choose a Device font when the system contains multiple fonts with the same name. OUT_OUTLINE_PRECIS Windows NT: This value instructs the font mapper to choose from TrueType and other outline-based fonts. OUT_RASTER_PRECIS Instructs the font mapper to choose a raster font when the system contains multiple fonts with the same name. OUT_STRING_PRECIS This value is not used by the font mapper, but it is returned when raster fonts are enumerated. OUT_STROKE_PRECIS Windows NT: This value is not used by the font mapper, but it is returned when TrueType, other outline-based fonts, and vector fonts are enumerated. Windows 95: This value is used to map vector fonts, and is returned when TrueType or vector fonts are enumerated. OUT_TT_ONLY_PRECIS Instructs the font mapper to choose from only TrueType fonts. If there are no TrueType fonts installed in the system, the font mapper returns to default behavior. OUT_TT_PRECIS Instructs the font mapper to choose a TrueType font when the system contains multiple fonts with the same name. Applications can use the OUT_DEVICE_PRECIS, OUT_RASTER_PRECIS, and OUT_TT_PRECIS values to control how the font mapper chooses a font when the operating system contains more than one font with a specified name. For example, if an operating system contains a font named Symbol in raster and TrueType form, specifying OUT_TT_PRECIS forces the font mapper to choose the TrueType version. Specifying OUT_TT_ONLY_PRECIS forces the font mapper to choose a TrueType font, even if it must substitute a TrueType font of another name. fdwClipPrecision Specifies the clipping precision. The clipping precision defines how to clip characters that are partially outside the clipping region. It can be one or more of the following values: Value Meaning CLIP_DEFAULT_PRECIS Specifies default clipping behavior. CLIP_CHARACTER_PRECIS Not used. CLIP_STROKE_PRECIS Not used by the font mapper, but is returned when raster, vector, or TrueType fonts are enumerated. Windows NT: For compatibility, this value is always returned when enumerating fonts. CLIP_MASK Not used. CLIP_EMBEDDED You must specify this flag to use an embedded read-only font. CLIP_LH_ANGLES When this value is used, the rotation for all fonts depends on whether the orientation of the coordinate system is left-handed or right-handed. If not used, device fonts always rotate counterclockwise, but the rotation of other fonts is dependent on the orientation of the coordinate system. For more information about the orientation of coordinate systems, see the description of the nOrientation parameter CLIP_TT_ALWAYS Not used. fdwQuality Specifies the output quality. The output quality defines how carefully GDI must attempt to match the logical-font attributes to those of an actual physical font. It can be one of the following values: Value Meaning DEFAULT_QUALITY Appearance of the font does not matter. DRAFT_QUALITY Appearance of the font is less important than when the PROOF_QUALITY value is used. For GDI raster fonts, scaling is enabled, which means that more font sizes are available, but the quality may be lower. Bold, italic, underline, and strikeout fonts are synthesized if necessary. PROOF_QUALITY Character quality of the font is more important than exact matching of the logical-font attributes. For GDI raster fonts, scaling is disabled and the font closest in size is chosen. Although the chosen font size may not be mapped exactly when PROOF_QUALITY is used, the quality of the font is high and there is no distortion of appearance. Bold, italic, underline, and strikeout fonts are synthesized if necessary. fdwPitchAndFamily Specifies the pitch and family of the font. The two low-order bits specify the pitch of the font and can be one of the following values: DEFAULT_PITCH FIXED_PITCH VARIABLE_PITCH The four high-order bits specify the font family and can be one of the following values: Value Description FF_DECORATIVE Novelty fonts. Old English is an example. FF_DONTCARE Don't care or don't know. FF_MODERN Fonts with constant stroke width, with or without serifs. Pica, Elite, and Courier New® are examples. FF_ROMAN Fonts with variable stroke width and with serifs. MS® Serif is an example. FF_SCRIPT Fonts designed to look like handwriting. Script and Cursive are examples. FF_SWISS Fonts with variable stroke width and without serifs. MS Sans Serif is an example. An application can specify a value for the fdwPitchAndFamily parameter by using the B

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧