Programming Windows Programming Guide-> Chapter 5 example program 5

Source: Internet
Author: User

/*_##################################### #######################################
_##
### Programming Windows Programming Design Guide-> Chapter 5 example program 5
_ ## Author: xwlee
_ ## Time: 2007.06.19
### Chang'an University
_ ## Development condition: win2003 SERVER + vc6.0
_##
_ ## Program 5-4 whatsize
_ ## Whatsize. c file
### The program displays the size of the window customer area displayed in five metric ing modes.
_ ## The program is only for verification
_##
_##
_ ## Whatsize. c -- What size is the window?
_ ## (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 ("whatsize ");

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 ("this program requires Windows NT! "),

Szappname, mb_iconerror );

Return 0;

}

Hwnd = createwindow (szappname, text ("What size is the window? "),

Ws_overlappedwindow,

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;

}

Void show (hwnd, HDC, int xtext, int ytext, int imapmode,

Tchar * szmapmode)

{

Tchar szbuffer [60];

Rect;

Savedc (HDC );

Setmapmode (HDC, imapmode );

Getclientrect (hwnd, & rect );

Dptolp (HDC, (Ppoint) & rect, 2 );

Restoredc (HDC,-1 );

Textout (HDC, xtext, ytext, szbuffer,

Wsprintf (szbuffer, text ("%-20 S % 7D % 7D % 7D % 7D"), szmapmode,

Rect. Left, rect. Right, rect. Top, rect. Bottom ));

}

 

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

{

Static tchar szheading [] =

Text ("Mapping mode left right top bottom ");

Static tchar szundline [] =

Text ("------------------------------");

Static int cxchar, cychar;

HDC;

Paintstruct pS;

Textmetric TM;

Switch (Message)

{

Case wm_create:

HDC = getdc (hwnd );

SelectObject (HDC, getstockobject (system_fixed_font ));

Gettextmetrics (HDC, & TM );

Cxchar = TM. tmavecharwidth;

Cychar = TM. tmheight + TM. tmexternalleading;

Releasedc (hwnd, HDC );

Return 0;

Case wm_paint:

HDC = beginpaint (hwnd, & PS );

SelectObject (HDC, getstockobject (system_fixed_font); // fixed-padding font

Setmapmode (HDC, mm_anisotropic );

Setwindowextex (HDC, 1, 1, null );

Setviewportextex (HDC, cxchar, cychar, null );

Textout (HDC, 1, 1, szheading, lstrlen (szheading ));

Textout (HDC, 1, 2, szundline, lstrlen (szundline ));

Show (hwnd, HDC, 1, 3, mm_text, text ("text (pixels )"));

Show (hwnd, HDC, 1, 4, mm_lometric, text ("lometric (. 1mm )"));

Show (hwnd, HDC, 1, 5, mm_himetric, text ("himetric (. 01mm )"));

Show (hwnd, HDC, 1, 6, mm_loenglish, text ("loenglish (. 01 in )"));

Show (hwnd, HDC, 1, 7, mm_hienglish, text ("hienglish (. 001 in )"));

Show (hwnd, HDC, 1, 8, mm_twips, text ("twips (1/1440 in )"));

Endpaint (hwnd, & PS );

Return 0;

Case wm_destroy:

Postquitmessage (0 );

Return 0;

}

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

}
 

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.