📄 subject_31609.htm
字号:
<blockquote><p>
回复者:流氓羊 回复日期:2003-03-09 11:26:08
<br>内容:代码如下:<BR>/*----------------------------------------------------<BR> SYSMETS1.C -- System Metrics Display Program No. 1<BR> (c) Charles Petzold, 1996<BR> ----------------------------------------------------*/<BR><BR>#include <windows.h><BR>#include <string.h><BR>#include "sysmets.h"<BR><BR>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;<BR><BR>int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,<BR> PSTR szCmdLine, int iCmdShow)<BR> {<BR> static char szAppName[] = "SysMets1" ;<BR> HWND hwnd ;<BR> MSG msg ;<BR> WNDCLASSEX wndclass ;<BR><BR> wndclass.cbSize = sizeof (wndclass) ;<BR> wndclass.style = CS_HREDRAW | CS_VREDRAW ;<BR> wndclass.lpfnWndProc = WndProc ;<BR> wndclass.cbClsExtra = 0 ;<BR> wndclass.cbWndExtra = 0 ;<BR> wndclass.hInstance = hInstance ;<BR> wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;<BR> wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;<BR> wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;<BR> wndclass.lpszMenuName = NULL ;<BR> wndclass.lpszClassName = szAppName ;<BR> wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION) ;<BR><BR> RegisterClassEx (&wndclass) ;<BR><BR> hwnd = CreateWindow (szAppName, "Get System Metrics No. 1",<BR> WS_OVERLAPPEDWINDOW,<BR> CW_USEDEFAULT, CW_USEDEFAULT,<BR> CW_USEDEFAULT, CW_USEDEFAULT,<BR> NULL, NULL, hInstance, NULL) ;<BR><BR> ShowWindow (hwnd, iCmdShow) ;<BR> UpdateWindow (hwnd) ;<BR><BR> while (GetMessage (&msg, NULL, 0, 0))<BR> {<BR> TranslateMessage (&msg) ;<BR> DispatchMessage (&msg) ;<BR> }<BR> return msg.wParam ;<BR> }<BR><BR>LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)<BR> {<BR> static int cxChar, cxCaps, cyChar ;<BR> char szBuffer[10] ;<BR> HDC hdc ;<BR> int i ;<BR> PAINTSTRUCT ps ;<BR> TEXTMETRIC tm ;<BR><BR> switch (iMsg)<BR> {<BR> case WM_CREATE :<BR> hdc = GetDC (hwnd) ;<BR><BR> GetTextMetrics (hdc, &tm) ;<BR> cxChar = tm.tmAveCharWidth ;<BR> cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;<BR> cyChar = tm.tmHeight + tm.tmExternalLeading ;<BR><BR> ReleaseDC (hwnd, hdc) ;<BR> return 0 ;<BR><BR> case WM_PAINT :<BR> hdc = BeginPaint (hwnd, &ps) ;<BR><BR> for (i = 0 ; i < NUMLINES ; i++)<BR> {<BR> TextOut (hdc, cxChar, cyChar * (1 + i),<BR> sysmetrics[i].szLabel,<BR> strlen (sysmetrics[i].szLabel)) ;<BR><BR> TextOut (hdc, cxChar + 22 * cxCaps, cyChar * (1 + i),<BR> sysmetrics[i].szDesc,<BR> strlen (sysmetrics[i].szDesc)) ;<BR><BR> SetTextAlign (hdc, TA_RIGHT | TA_TOP) ;<BR><BR> TextOut (hdc, cxChar + 22 * cxCaps + 40 * cxChar,<BR> cyChar * (1 + i), szBuffer,<BR> wsprintf (szBuffer, "%5d",<BR> GetSystemMetrics (sysmetrics[i].iIndex))) ;<BR><BR> SetTextAlign (hdc, TA_LEFT | TA_TOP) ;<BR> }<BR><BR> EndPaint (hwnd, &ps) ;<BR> return 0 ;<BR><BR> case WM_DESTROY :<BR> PostQuitMessage (0) ;<BR> return 0 ;<BR> }<BR><BR> return DefWindowProc (hwnd, iMsg, wParam, lParam) ;<BR> }<BR>其中头文件的代码是:<BR>/*-----------------------------------------------<BR> SYSMETS.H -- System metrics display structure<BR> -----------------------------------------------*/<BR><BR>#define NUMLINES ((int) (sizeof sysmetrics / sizeof sysmetrics [0]))<BR><BR>struct<BR>{<BR>int iIndex ;<BR>char *szLabel ;<BR>char *szDesc ;<BR>}<BR>sysmetrics [] =<BR>{<BR>SM_CXSCREEN, "SM_CXSCREEN", "Screen width in pixels",<BR>SM_CYSCREEN, "SM_CYSCREEN", "Screen height in pixels",<BR>SM_CXVSCROLL, "SM_CXVSCROLL", "Vertical scroll arrow width",<BR>SM_CYHSCROLL, "SM_CYHSCROLL", "Horizontal scroll arrow height",<BR>SM_CYCAPTION, "SM_CYCAPTION", "Caption bar height",<BR>SM_CXBORDER, "SM_CXBORDER", "Window border width",<BR>SM_CYBORDER, "SM_CYBORDER", "Window border height",<BR>SM_CXDLGFRAME, "SM_CXDLGFRAME", "Dialog window frame width",<BR>SM_CYDLGFRAME, "SM_CYDLGFRAME", "Dialog window frame height",<BR>SM_CYVTHUMB, "SM_CYVTHUMB", "Vertical scroll thumb height",<BR>SM_CXHTHUMB, "SM_CXHTHUMB", "Horizontal scroll thumb width",<BR>SM_CXICON, "SM_CXICON", "Icon width",<BR>SM_CYICON, "SM_CYICON", "Icon height",<BR>SM_CXCURSOR, "SM_CXCURSOR", "Cursor width",<BR>SM_CYCURSOR, "SM_CYCURSOR", "Cursor height",<BR>SM_CYMENU, "SM_CYMENU", "Menu bar height",<BR>SM_CXFULLSCREEN, "SM_CXFULLSCREEN", "Full screen client area width",<BR>SM_CYFULLSCREEN, "SM_CYFULLSCREEN", "Full screen client area height",<BR>SM_CYKANJIWINDOW, "SM_CYKANJIWINDOW", "Kanji window height",<BR>SM_MOUSEPRESENT, "SM_MOUSEPRESENT", "Mouse present flag",<BR>SM_CYVSCROLL, "SM_CYVSCROLL", "Vertical scroll arrow height",<BR>SM_CXHSCROLL, "SM_CXHSCROLL", "Horizontal scroll arrow width",<BR>SM_DEBUG, "SM_DEBUG", "Debug version flag",<BR>SM_SWAPBUTTON, "SM_SWAPBUTTON", "Mouse buttons swapped flag",<BR>SM_RESERVED1, "SM_RESERVED1", "Reserved",<BR>SM_RESERVED2, "SM_RESERVED2", "Reserved",<BR>SM_RESERVED3, "SM_RESERVED3", "Reserved",<BR>SM_RESERVED4, "SM_RESERVED4", "Reserved",<BR>SM_CXMIN, "SM_CXMIN", "Minimum window width",<BR>SM_CYMIN, "SM_CYMIN", "Minimum window height",<BR>SM_CXSIZE, "SM_CXSIZE", "Minimize/Maximize icon width",<BR>SM_CYSIZE, "SM_CYSIZE", "Minimize/Maximize icon height",<BR>SM_CXFRAME, "SM_CXFRAME", "Window frame width",<BR>SM_CYFRAME, "SM_CYFRAME", "Window frame height",<BR>SM_CXMINTRACK, "SM_CXMINTRACK", "Minimum window tracking width",<BR>SM_CYMINTRACK, "SM_CYMINTRACK", "Minimum window tracking height",<BR>SM_CXDOUBLECLK, "SM_CXDOUBLECLK", "Double click x tolerance",<BR>SM_CYDOUBLECLK, "SM_CYDOUBLECLK", "Double click y tolerance",<BR>SM_CXICONSPACING, "SM_CXICONSPACING", "Horizontal icon spacing",<BR>SM_CYICONSPACING, "SM_CYICONSPACING", "Vertical icon spacing",<BR>SM_MENUDROPALIGNMENT, "SM_MENUDROPALIGNMENT", "Left or right menu drop",<BR>SM_PENWINDOWS, "SM_PENWINDOWS", "Pen extensions installed",<BR>SM_DBCSENABLED, "SM_DBCSENABLED", "Double-Byte Char Set enabled",<BR>SM_CMOUSEBUTTONS, "SM_CMOUSEBUTTONS", "Number of mouse buttons",<BR>SM_SHOWSOUNDS, "SM_SHOWSOUNDS", "Present sounds visually"<BR>} ;<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:小抱枕 回复日期:2003-03-09 12:53:58
<br>内容:main函数没有定义?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:tjhe 回复日期:2003-03-09 13:38:19
<br>内容:我新建一个Win32 Application项目(选空项目),然后建立SYSMETS1.C与SYSMETS1.h文件加入项目(将上面内容拷贝),编译,没有任何错误提示。<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:流氓羊 回复日期:2003-03-10 18:57:50
<br>内容:谢谢了,这次我的也正确了,不知道是什么原因,为什么上次不正确那》工作区也应该是默认的阿,为什么会把win32 consele application选上了那.(我在网上当的,上面的工作区,如果不建立工作区直接打开文件直接执行就象上面的错误有发生了???
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -