从您贴出来的代码来看,其实没有严重错误,只是有着几处地方拼写错误,下面是调试运行通过的代码,除了把WndProc的实现放到了Winmain函数之外,其他的改动都已经用注释符号标出,希望您看了以后有帮助。#include <windows.h>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)//error
{
static char szAppName[]="winhello";
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize=sizeof(wndclass);
wndclass.style=CS_HREDRAW|CS_VREDRAW;
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;
wndclass.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
RegisterClassEx(&wndclass);
hwnd=CreateWindow(szAppName,"winhello program",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,500,300,
NULL,NULL,hInstance,NULL);//error
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam)//error c2601:WndProc:local function definitions //are illegal
{
HDC hdc;
//PAINSTRUCT ps;
PAINTSTRUCT ps;
RECT rect;
//swith(iMsg)
switch(iMsg)
{
//case WN_PAINT:
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
//GetClientRect(hwnd,rect);
GetClientRect(hwnd,&rect);
DrawText(hdc,"helloworld from window",-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
//EndPaint(hwnd,ps);
EndPaint(hwnd,&ps);
return 0;
//case WM_DESTORY:
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,iMsg,wParam,lParam);
}
- 微软全球技术中心 VC技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。