Sysmets.c
#include <windows.h>#include"SYSMETS. H"//Custom units, So use "", not with <>//message loop handler function, Windows callback functionLRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);//entry functions for Windows programsintWINAPI WinMain (hinstance hinstance, hinstance hprevinstance, PSTR szcmdline,intIcmdshow) { StaticTCHAR szappname[] = TEXT ("Windowofc"); HWND hwnd;//form Handle VariablesMsg msg;//Message VariablesWndclass wndclass;//window class Variables//Configuring the window class structureWndclass.style = Cs_hredraw |cs_vredraw; Wndclass.lpfnwndproc= WndProc;//set up functions to process message loopsWndclass.cbclsextra =0; Wndclass.cbwndextra=0; Wndclass.hinstance=hinstance; Wndclass.hicon=LoadIcon (NULL, idi_application); Wndclass.hcursor=loadcursor (NULL, idc_arrow); Wndclass.hbrbackground=(hbrush) color_window; Wndclass.lpszmenuname=NULL; Wndclass.lpszclassname=szappname; //Register window class if(! RegisterClass (&WNDCLASS)) {MessageBox (NULL, TEXT ("failed to register window class! "), szappname, mb_iconerror); return 0; } //Create Windowhwnd =CreateWindow (szappname, TEXT ("Get Windows graphics widget size information"), ws_overlappedwindow, cw_usedefault, cw_usedefault, cw_usedefault, cw_usedefault, null, null, hinstance, null); //Display windowShowWindow (hwnd, icmdshow); //Update window ContentsUpdateWindow (hwnd); //Get Windows messages while(GetMessage (&msg, NULL,0,0) {translatemessage (&msg); DispatchMessage (&msg); } returnmsg.wparam;};//Message Handling methods, callback functions for Windows operating systemsLRESULT CALLBACK WndProc (hwnd hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) {hdc hdc;//Graphics Device Description Table variablespaintstruct ps; Static intcxchar, cxcaps, cychar;//variable of text size intI//cyclic display of component information variablesTCHAR szbuffer[Ten];//Output Build-size VariablesTextmetric tm;//Font Information Structure intisysments;//the Windows widget size returned by the system Switch(message) { casewm_create://Get the device description tableHDC =GetDC (hwnd); //Get text size informationGetTextMetrics (hdc, &tm); Cxchar=tm.tmavecharwidth; Cxcaps= (tm.tmpitchandfamily &1?3:2) *cxchar/2; Cychar= Tm.tmheight +tm.tmexternalleading; //Release the device description tableReleaseDC (hwnd, hdc); return 0; casewm_paint://Get the device description tableHDC = BeginPaint (hwnd, &ps); for(i =0; I < numlines; i++) { //Output IDTextOut (hdc,0, cychar*i, sysmetrics[i].szlabel, Lstrlen (sysmetrics[i].szlabel)); //output The original English description informationTextOut (hdc, a* cxcaps, cychar*i, sysmetrics[i].szdesc, Lstrlen (sysmetrics[i].szdesc)); //Set Text alignmentSetTextAlign (hdc, Ta_right |ta_top); //get the current Windows widget sizeIsysments =GetSystemMetrics (sysmetrics[i].iindex); TextOut (hdc, a* Cxcaps + +* cxchar, cychar*i, szbuffer, wsprintf (szbuffer, TEXT ("%5d") , isysments)); //Set Text alignmentSetTextAlign (hdc, Ta_left |ta_top); //output The original English description informationTextOut (hdc, a* Cxcaps + -* cxchar, cychar*i, sysmetrics[i].szcndesc, Lstrlen (sysmetrics[i].szcndesc)); //Set Text alignmentSetTextAlign (hdc, Ta_left |ta_top); } //Release the device description tableEndPaint (hwnd, &ps); return 0; caseWm_destroy:postquitmessage (0); return 0; } returndefwindowproc (hwnd, message, wParam, lParam);};
SYSMETS.h
#pragmaOnce//ensure that the same content is compiled only once#include<windows.h>//macro definition (numlines is directly replaced by the following content at precompiled Time)#defineNumlines ((int) (sizeof sysmetrics/sizeof sysmetrics[0]))struct{ intiIndex; TCHAR*szlabel; TCHAR*szdesc; TCHAR* szcndesc;//This is my added content, display the Chinese description information, the above English description information translation text}/*1, This is an array of structures, each structure in the array describes the currently acquired Windows widget 2, the structure element in the array was modified by me, each structure element periphery has added "{}", so that the program readability should be better, the original code does not have "{}"*/sysmetrics[]={{sm_cxscreen,text ("Sm_cxscreen"), TEXT ("screen width in pixels"), TEXT ("screen width (units: pixels)")}, {sm_cyscreen,text ("Sm_cyscreen"), TEXT ("screen height in pixels"), TEXT ("screen height (units: pixels)") } //There's A lot more to be continued};
[c language] (ii) 01 Get Windows graphics Widget size information