MFC创建窗口时的问题
最近在学习使用MFC,想要创建一个窗口,结果运行以后不显示窗口,但是任务管理器中有这个程序。。。。我好郁闷啊,不知道哪的问题,哪位大哥帮忙找一下啊,谢谢了。代码如下: (只有一个cpp文件,用的是VC7.1中文版,建立的是个空项目,往里面添加的cpp文件)
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
)
{
WNDCLASS wndclass;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground=(HBRUSH)(GetStockObject(BLACK_BRUSH));
wndclass.hCursor = LoadCursor(NULL ,IDC_CROSS);
wndclass.hIcon = LoadIcon(NULL ,IDI_ERROR);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WinSunProc;
wndclass.lpszClassName = "My window";
wndclass.lpszMenuName=NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);
HWND hWnd;
hWnd = CreateWindow("My window" ,"my MFC" , WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0 ,0 ,600 ,400 ,NULL ,NULL ,hInstance ,NULL);
ShowWindow(hWnd ,SW_SHOWNORMAL);
UpdateWindow(hWnd);
MSG msg;
while (GetMessageA(&msg ,NULL ,0 ,0))
{
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch (uMsg)
{
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd ,&ps);
TextOut(hdc ,0 ,50 ,"wm_paint !!" ,strlen("wm_paint !!"));
EndPaint(hwnd ,&ps);
break;
case WM_CHAR:
char szChar[20];
sprintf(szChar ,"char is %d !!" ,wParam);
MessageBox(hwnd ,szChar ,"WM_CHAR" ,0);
break;
case WM_CLOSE:
if (IDYES == MessageBox(hwnd ,"是否真的结束 !!" ,"close" ,0))
{
//SendMessage(HWND ,WM_DESTROY ,wParam ,lParam);
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd ,"mouse clicked !!" ,"WM_LBUTTONDOWN" ,0);
HDC hDc;
hDc = GetDC(hwnd);
TextOut(hDc ,0 ,0 ,"wm_lbuttondown" ,strlen("wm_lbuttondown"));
ReleaseDC(hwnd ,hDc);
break;
default:
DefWindowProc(hwnd ,uMsg ,wParam ,lParam);
break;
}
return 0;
}