The following whether the use of text input functions so static control, the font is tacit, compared to beautiful, we can create more and more cool font.
The creation font uses the CreateFont function, and its prototype is:
Hfont createfont (int cheight,//font logical height int cwidth,//font logical width int cescapement,///Specify shift vector absolute x axis deflection angle int corientation,//Specify character Baseline absolute x axis deflection angle int cweight,//Set Font weight horizontal DWORD bitalic,//Can enable italic DWORD Bunderline,//Can enable underscore DWORD bstrikeout,//Can enable strikethrough DWORD Icharset,//Specify Character Set DWORD ioutprecision,//Input precision DWORD iclipprecision,//Trim precision DWORD iquality,//Input quality DWORD ipitchandfamily,/ /font family LPCSTR pszfacename//font name);
The following 14 parameters complete remember simply impossible can, the following is a complex clarification, the other "tiger" can be.
1) Parameters Cwidth and Cheight weekday negative, and the height is twice times the width, such as-18 and 9, you can specify 13.5 | (h+w)/2| The font of the pound.
2) about the font thickness level cweight, you can use the Fw_ to wrap up the macro definition, general take fw_normal (400), the value of this parameter requirement is [0,1000].
3) for parameters bitalic, Bunderline, bstrikeout, use TRUE or FALSE to pass the value directly.
4) about the character set Icharset, ordinary can be directly used default_charset let piecemeal active disposal.
Note: The font is also a GDI object, after the use of the Wm_destroy thereafter to delete.
After the creation of the font is not immediately used, but also the need to manually trigger Wm_setfont audio, so that Windows will later set the font we created.
Send audio using the SendMessage function, which allows us to automatically send a variety of audio to the window when needed, the prototype is:
LRESULT SendMessage (HWND hwnd,//Send the destination window handle of the message UINT MSG,//will be sent audio WPARAM WPARAM,//Additional audio 1 LPARAM LPARAM//additional audio 2);
These parameters are very similar to the WNDPROC function. Yes, the SendMessage is sent by the window process to dispose of.
To set the font's audio is wm_setfont, simply wParam the handle to the incoming CreateFont to the additional parameter (the requirement transitions to the WParam type). Take a look at the following example:
Window Process lresult callback wndproc ( HWND hWnd, UINT message, WPARAM Wparam, lparam lparam) { paintstruct ps; hdc hdc; static hfont hfont; //declares a logical font handle as a static variable static hwnd labexample; //at the beginning, we declare it as a static variable switch ( Message) { case wm_create: //Creates a logical font hfont = createfont ( -15/* height */, -7.5 /* Width */, 0/* do not need to tube */, 0/* do not have to tube */, 400 /* Normal This value is set to 400*/, false/* without italic */, false/* not underlined */, false/* without strikethrough */, default_charset, //Here we use the tacit character set, and other constants that start with _CHARSET are available out_ character_precis, clip_character_precis, //This line of parameter does not have to tube default_quality, //tacit input quality ff_ dontcare, //do not specify font family */ l "Microsoft Jas Black" //font name ); //Create a static TextBox control labExample = CreateWindow ( l "Static", //the class name of the static text box l "Hello, welcome away C speech Chinese web" , //control text ws_child /* child window */ | ws_visible /* Display */ | ws_border /* with border */, 60 /*x coordinates */, 60/*y coordinates */, 150/* width */, 100/when created * Height */, hwnd/* parent window handle */, (HMENU) 1, //Specify a unique identifier for the control hinst, //later instance handle null); // Sets the control font sendmessage ( labexample, //to set the font's handle wm_setfont, //audio (audio type) (WPARAM) hfont, //font handle null //empty value ); break; case wm_paint: hdc = BeginPaint (hwnd, &ps); // todo: add scribble code here ... endpaint (HWND, &PS); break; case wm_destroy: //Please do the aftercare task deleteobject (Hfont);//delete the created font postquitmessage (0); break; default: return defwindowproc (Hwnd, message, wparam, lparam); } return 0; }
operational consequences:
650) this.width=650; "src=" Http://c.biancheng.net/cpp/uploads/allimg/150729/1-150H9141K5W1.png "style=" border:0 Px;color:rgb (51,51,51); font-family: ' Microsoft Jas Black ', ' Microsoft Yahei ', Arial, Helvetica, sans-serif;font-size:14px; line-height:21px;white-space:normal;width:320px;height:253px, "/>
This article is from the "11999764" blog, please be sure to keep this source http://12009764.blog.51cto.com/11999764/1843796
Windows CreateFont: Create your own fonts