[法式设想]VC新手,问高手们一个问题

3个月前 (11-25 19:18)阅读4回复0
xx
xx
  • 管理员
  • 注册排名6
  • 经验值131890
  • 级别管理员
  • 主题26378
  • 回复0
楼主

#includewindows.h

  #includestdlib.h

  #includestring.h

  long WINAPI WndProc(HWND hwnd,UINT iMessage,UINT wParam,LONG lParam);

  BOOL InitWindowsClass(HINSTANCE hInstance);

  BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);

  int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)

   MSG message;

   if(!InitWindowsClass(hInstance))

   return FALSE;

   if(!InitWindowsClass(hInstance))

   return FALSE;

   while(GetMessage(message,0,0,0))

   TranslateMessage(message);

   DispatchMessage(message);

   return message.wParam;

  long WINAPI WndProc(HWND hwnd,UINT iMessage,UINT wParam,LONG lParam)

   HDC hDc;

   HBRUSH hBrush;

   HPEN hPen;

   PAINTSTRUCT PtStr;//定义了指向绘图信息的构造体变量

   POINT points[6]={{100,212},{70,227},{70,250},{130,250},{130,227},{100,212}};

   //定义了六个点

   switch(iMessage)

   case WM_PAINT:

   hDc=BeginPaint(hwnd,PtStr);

   hPen=(HPEN)GetStockObject(NULL_PEN);//获得系统定义的空笔

   SelectObject(hDc,hPen);//抉择画笔

   hBrush=(HBRUSH)GetStockObject(BLACK_BRUSH);//获得系统定义的黑画刷

   SelectObject(hDc,hBrush);//抉择画刷

   LineTo(hDc,50,50);

   DeleteObject(hPen);

   hPen=CreatePen(PS_SOLID,2,RGB(255,0,0));

   SelectObject(hDc,hPen);//抉择画笔

   LineTo(hDc,150,150);

   LineTo(hDc,100,137);

   LineTo(hDc,50,50);

   //画三角形

   Polyline(hDc,points,6);

   Arc(hDc,63,137,138,212,100,137,100,137);

   Pie(hDc,213,137,288,212,240,137,260,137);

   Rectangle(hDc,213,212,287,250);

   RoundRect(hDc,213,100,287,137,20,20);

   DeleteObject(hPen);

   DeleteObject(hBrush);

   EndPaint(hwnd,PtStr);

   return 0;

   case WM_DESTROY:

   PostQuitMessage(0);

   return 0;

   default:

   return (DefWindowProc(hwnd,iMessage,wParam,lParam));

  BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)

   HWND hwnd;

   hwnd=CreateWindow(“WINFILL“,“填充分例法式“,WS_OVERLAPPEDWINDOW,

   CW_USEDEFAULT,0,

   CW_USEDEFAULT,0,

   NULL,NULL,hInstance,NULL);

   if(!hwnd)

   return FALSE;

  /////////////下面那行呈现错误啦////////////////////////////

   hWndMain=hwnd;

   ShowWindow(hwnd,nCmdShow);

   UpdateWindow(hwnd);

   return TRUE;

  BOOL InitWindowsClass(HINSTANCE hInstance)

   WNDCLASS wndclass;

   wndclass.cbClsExtra=0;

   wndclass.cbWndExtra=0;

   wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);

   wndclass.hCursor=LoadCursor(hInstance,IDC_ARROW);

   wndclass.hIcon=LoadIcon(hInstance,“END“);

   wndclass.hInstance=hInstance;

   wndclass.lpfnWndProc=WndProc;

   wndclass.lpszClassName=“WINFILL“;

   wndclass.lpszMenuName=NULL;

   wndclass.style=CS_HREDRAW | CS_VREDRAW;

   return RegisterClass(wndclass);

  Compiling...

  03.cpp

  E:\VC讲义\1-17代码\03\03.cpp(88) : error C2065: ’hWndMain’ : undeclared identifier

  E:\VC讲义\1-17代码\03\03.cpp(88) : error C2440: ’=’ : cannot convert from ’struct HWND__ *’ to ’int’

   This conversion requires a reinterpret_cast, a C-style cast or function-style cast

  Error executing cl.exe.

  03.exe - 2 error(s), 0 warning(s)

  那个错误怎么纠正啊?

0
回帖

[法式设想]VC新手,问高手们一个问题 期待您的回复!

取消