Programming Windows Programming Guide-> Chapter 6 example Program 3

Source: Internet
Author: User
Tags textout

/*_##################################### #######################################
_##
### Programming Windows Programming Design Guide-> Chapter 6 example Program 3
_ ## Author: xwlee
_ ## Time: 2007.06.21
### Chang'an University
_ ## Development condition: win2003 SERVER + vc6.0
_##
_ ## Program 6-3 ‑font
### Upload font. c file
_ ## This program displays all information about the eight different keyboard messages sent by windows to the window message processing program in the customer Zone
_ ## The program is only for verification
_##
_##
### Define font. c -- stock font objects
_ ## (C) Charles Petzold, 1998
_##
_####################################### ###################################*/
# Include <windows. h>

Lresult callback wndproc (hwnd, uint, wparam, lparam );

Int winapi winmain (hinstance, hinstance hprevinstance,
Pstr szcmdline, int icmdshow)
{
Static tchar szappname [] = text ("symbol font ");
Hwnd;
MSG;
Wndclass;

Wndclass. Style = cs_hredraw | cs_vredraw;
Wndclass. lpfnwndproc = wndproc;
Wndclass. cbclsextra = 0;
Wndclass. cbwndextra = 0;
Wndclass. hinstance = hinstance;
Wndclass. hicon = loadicon (null, idi_application );
Wndclass. hcursor = loadcursor (null, idc_arrow );
Wndclass. hbrbackground = (hbrush) getstockobject (white_brush );
Wndclass. lpszmenuname = NULL;
Wndclass. lpszclassname = szappname;

If (! Registerclass (& wndclass ))
{
MessageBox (null, text ("program requires Windows NT! "),
Szappname, mb_iconerror );
Return 0;
}

Hwnd = createwindow (szappname, text ("stock fonts "),
Ws_overlappedwindow | ws_vscroll,
Cw_usedefault, cw_usedefault,
Cw_usedefault, cw_usedefault,
Null, null, hinstance, null );

Showwindow (hwnd, icmdshow );
Updatewindow (hwnd );
While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
Return msg. wparam;
}

Lresult callback wndproc (hwnd, uint message, wparam, lparam)
{
Static struct
{
Int idstockfont;
Tchar * szstockfont;
}
Stockfont [] = {oem_fixed_font, "oem_fixed_font ",
Ansi_fixed_font, "ansi_fixed_font ",
Ansi_var_font, "ansi_var_font ",
System_font, "system_font ",
Device_default_font, "device_default_font ",
System_fixed_font, "system_fixed_font ",
Default_gui_font, "default_gui_font "};
 

Static int ifont, cfonts = sizeof stockfont/sizeof stockfont [0];
HDC;
Int I, X, Y, cxgrid, cygrid;
Paintstruct pS;
Tchar szfacename [lf_facesize], szbuffer [lf_facesize + 64];
Textmetric TM;

Switch (Message)
{
Case wm_create:
Setscrollrange (hwnd, sb_vert, 0, cfonts-1, true );
Return 0;

Case wm_displaychange:
Invalidaterect (hwnd, null, true );
Return 0;

Case wm_vscroll:
Switch (loword (wparam ))
{
Case sb_top: ifont = 0; break;
Case sb_bottom: ifont = cfonts-1; break;
Case sb_lineup:
Case sb_pageup: ifont-= 1; break;
Case sb_linedown:
Case sb_pagedown: ifont + = 1; break;
Case sb_thumbposition: ifont = hiword (wparam); break;
}

Ifont = max (0, min (cfonts-1, ifont ));
Setscrollpos (hwnd, sb_vert, ifont, true );
Invalidaterect (hwnd, null, true );
Return 0;

Case wm_keydown:
Switch (wparam)
{
Case vk_home: sendmessage (hwnd, wm_vscroll, sb_top, 0); break;
Case vk_end: sendmessage (hwnd, wm_vscroll, sb_bottom, 0); break;
Case vk_prior:
Case vk_left:
Case vk_up: sendmessage (hwnd, wm_vscroll, sb_lineup, 0); break;
Case vk_next:
Case vk_right:
Case vk_down: sendmessage (hwnd, wm_vscroll, sb_pagedown, 0); break;
}
Return 0;

Case wm_paint:
HDC = beginpaint (hwnd, & PS );

SelectObject (HDC, getstockobject (stockfont [ifont]. idstockfont ));
Gettextface (HDC, lf_facesize, szfacename );
Gettextmetrics (HDC, & TM );
Cxgrid = max (3 * TM. tmavecharwidth, 2 * TM. tmmaxcharwidth );
Cygrid = TM. tmheight + 3;

Textout (HDC, 0, 0, szbuffer,
Wsprintf (szbuffer, text ("% s: Face name = % s, charset = % I "),
Stockfont [ifont]. szstockfont,
Szfacename, TM. tmcharset ));

Settextalign (HDC, ta_top | ta_center );
// Vertical and horizontal lines
For (I = 0; I <17; I ++)
{
Movetoex (HDC, (I + 2) * cxgrid, 2 * cygrid, null );
Lineto (HDC, (I + 2) * cxgrid, 19 * cygrid );
 
Movetoex (HDC, cxgrid, (I + 3) * cygrid, null );
Lineto (HDC, 18 * cxgrid, (I + 3) * cygrid );
}

// Vertical and horizontal headings

 

For (I = 0; I <16; I ++)
{
Textout (HDC, (2 * I + 5) * cxgrid/2, 2 * cygrid + 2, szbuffer,
Wsprintf (szbuffer, text ("% x-"), I ));
Textout (HDC, 3 * cxgrid/2, (I + 3) * cygrid + 2, szbuffer,
Wsprintf (szbuffer, text ("-% x"), I ));
}

// Characters

 

For (y = 0; y <16; y ++)

For (x = 0; x <16; X ++)

{

Textout (HDC, (2 * x + 5) * cxgrid/2,

(Y + 3) * cygrid + 2, szbuffer,

Wsprintf (szbuffer, text ("% C"), 16 * x + y ));

}

 

Endpaint (hwnd, & PS );

Return 0;

Case wm_destroy:

Postquitmessage (0 );

Return 0;

}

Return defwindowproc (hwnd, message, wparam, lparam );

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.