VC6.0能通过编译,进程也有,但不能显示窗口,求真相,谢谢!
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0; //窗口类无扩展
wndcls.cbClsExtra=0; //窗口实例无扩展
wndcls.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);//窗口背景为白色
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);// 窗口采用十字光标
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);//窗口的最小化图标为缺省图标
wndcls.hInstance =hInstance;//当前实例句柄
wndcls.lpfnWndProc=WinSunProc;//定义窗口处理函数
wndcls.lpszClassName ="Weixin2003";//窗口类名为“窗口”
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("Weixin2003","北京维新科学技术培训中心",WS_OVERLAPPEDWINDOW,
0,0,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"weixin",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","wei xin",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"计算机编程语言",strlen("计算机编程语言"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT PS;
hDC=BeginPaint(hwnd,&PS);
TextOut(hDC,0,50,"维新培训",strlen("维新培训"));
EndPaint(hwnd,&PS);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否结束","weixin",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
[解决办法]
wndcls.cbClsExtra=0; //´°¿ÚÀàÎÞÀ©Õ¹
wndcls.cbClsExtra=0; //´°¿ÚʵÀýÎÞÀ©Õ¹
---------------------
这两个写成一样了