Programming Windows Programming Guide-> Chapter 5 example program 1

Source: Internet
Author: User
Tags textout

/*_##################################### #######################################
_##
### Programming Windows Programming Design Guide-> Chapter 5 example program 1
_ ## Author: xwlee
_ ## Time: 2007.06.17
### Chang'an University
_ ## Development condition: win2003 SERVER + vc6.0
_##
_ ## Program 5-1 devcaps
_ ## Devcaps. c file
### When the program displays a video display device environment as a parameter,
### Some information that can be obtained from the getdevicecaps Function
_##
_##
_##
_##
_##
_##
_ ## Devcaps. c -- device capabilities display program No. 1
_ ## (C) Charles Petzold, 1998
_##
_####################################### ###################################*/

# Include <windows. h>

# Define numlines (INT) (sizeof devcaps/sizeof devcaps [0])

Struct

{

Int iindex;

Tchar * szlabel;

Tchar * szdesc;

}

Devcaps [] =
{
// The actual screen width in millimeters
Horzsize, text ("horzsize"), text ("width in millimeters :"),

// The actual screen height in millimeters
Vertsize, text ("vertsize"), text ("height in millimeters :"),

Horzres, text ("horzres"), text ("width in pixels :"),

Vertres, text ("vertres"), text ("height in raster lines :"),

Bitspixel, text ("bitspixel"), text ("color bits per pixel :"),

Planes, text ("planes"), text ("Number of color planes :"),

Numbrushes, text ("numbrushes"), text ("Number of device Brushes :"),

Numpens, text ("numpens"), text ("Number of device pens :"),

Nummarkers, text ("nummarkers"), text ("Number of device markers :"),

Numfonts, text ("numfonts"), text ("Number of device fonts :"),

Numcolors, text ("numcolors"), text ("Number of device colors :"),

Pdevicesize, text ("pdevicesize"), text ("size of device structure :"),

// Finally, the other three values from getdevicecaps are related to the video size. Aspectx, aspecty, and aspectxy
// The value is the relative width, height, and diagonal line of each pixel, rounded to an integer. For square pixels,
// The aspectx and aspecty values are the same. In any case, the aspectxy value should be equal to the sum of the squares of aspectx and aspecty
// Square root, just like a right triangle.
Aspectx, text ("aspectx"), text ("relative width of pixel :"),
Aspecty, text ("aspecty"), text ("relative height of pixel :"),
Aspectxy, text ("aspectxy"), text ("relative diagonal of pixel :"),

Logpixelsx, text ("logpixelsx"), text ("Horizontal dots per inch :"),

Logpixelsy, text ("logpixelsy"), text ("vertical dots per inch :"),

Sizepalette, text ("sizepalette"), text ("Number of palette entries :"),

Numreserved, text ("numreserved"), text ("Reserved palette entries :"),

Colorres, text ("colorres"), text ("actual color resolution :")

};

 

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

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

Wndclass. Style = cs_hredraw | cs_vredraw | cs_owndc;
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 ("device capabilities "),
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;
}

 
Lresult callback wndproc (hwnd, uint message, wparam, lparam)
{
Static int cxchar, cxcaps, cychar;
Tchar szbuffer [10];
HDC;
Int I;
Paintstruct pS;
Textmetric TM;

Switch (Message)
{
Case wm_create:
HDC = getdc (hwnd );

Gettextmetrics (HDC, & TM );
Cxchar = TM. tmavecharwidth;
Cxcaps = (TM. tmpitchandfamily & 1? 3: 2) * cxchar/2;
Cychar = TM. tmheight + TM. tmexternalleading;


Releasedc (hwnd, HDC );
Return 0;

Case wm_paint:
HDC = beginpaint (hwnd, & PS );
For (I = 0; I <numlines; I ++)
{
Textout (HDC, 0, cychar * I,
Devcaps [I]. szlabel,
Lstrlen (devcaps [I]. szlabel ));

Textout (HDC, 14 * cxcaps, cychar * I,
Devcaps [I]. szdesc,
Lstrlen (devcaps [I]. szdesc ));

Settextalign (HDC, ta_right | ta_top );
Textout (HDC, 14 * cxcaps + 35 * cxchar, cychar * I, szbuffer,
Wsprintf (szbuffer, text ("% 5d "),
Getdevicecaps (HDC, devcaps [I]. iindex )));

Settextalign (HDC, ta_left | ta_top );
}

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.