//main.c
#include<windows.h>
#include "sysment.h"LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(
  HINSTANCE hInstance,  // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,      // pointer to command line
  int nCmdShow          // show state of window
)
{
static TCHAR szAppName[]=TEXT("SYSMENT");
MSG msg;
WNDCLASS wndclass;
HWND hwnd;

wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szAppName;
wndclass.lpfnWndProc=WndProc;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.cbWndExtra=0;
wndclass.cbClsExtra=0;
if(!RegisterClass(&wndclass) )
{
MessageBox(NULL,TEXT("get sysment No!"),szAppName,MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szAppName,TEXT("SYSMENT"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while( GetMessage(&msg,NULL,0,0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}LRESULT CALLBACK WndProc(  HWND hwnd,      // handle to window
  UINT message,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
)
{
PAINTSTRUCT ps;
static cxChar,cyChar,cxCaps;
HDC hdc;
TEXTMETRIC tm;
TCHAR szBuffer[10];
int i;
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<NUMLINE;i++)
{
TextOut(hdc,0,cyChar*i, sysment[i].szLabel , lstrlen(sysment[i].szLabel) );
TextOut(hdc, 22*cxCaps ,cyChar*i,sysment[i].szDesc , lstrlen(sysment[i].szDesc) );
SetTextAlign(hdc,TA_TOP|TA_RIGHT);
TextOut(hdc, 22*cxCaps+40*cxChar , cyChar*i , szBuffer , wsprintf(szBuffer,TEXT("%5d"),GetSystemMetrics(sysment[i].ilndex)));
SetTextAlign(hdc,TA_TOP|TA_LEFT);
}
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}//sysment.h#define NUMLINE ((int)(sizeof( sysment/sizeof sysment[0]))
struct
{
int ilndex;
TCHAR * szLabel;
TCHAR * szDesc;
}
sysment[]=
{
SM_CXSCREEN,TEXT("SM_CXSCREEN"),TEXT("Screen width in pixels"),
SM_CYSCREEN,TEXT("SM_CYSCREEN"),TEXT("Screen heigth in pixels"),
SM_CXVSCROLL,TEXT("SM_CXVSCROLL"),TEXT("Vertical scroll width"),
SM_CYHSCROLL,TEXT("SM_CYHSCROLL"),TEXT("horizontal scroll heigth"),
};

解决方案 »

  1.   

    d:\c++\sysment\main.cpp(69) : error C2296: '/' : illegal, left operand has type 'struct [4]'
    d:\c++\sysment\main.cpp(69) : error C2143: syntax error : missing ')' before ';'
      

  2.   

    #define NUMLINE ((int)(sizeof(sysment)/sizeof(sysment[0])))
      

  3.   

    #define NUMLINE ((int)(sizeof(sysment)/sizeof(sysment[0])))
    缺括号
      

  4.   

    知道什么是visual assit 吗?下个用一下,可以有效防止括号出错!!