新手求教。win32应用程序,运行时咋就不弹窗口额?
//Utility.h
#include<windows.h>
#include<wchar.h>
HWND SetUp(HINSTANCE& hInstance);
LRESULT CALLBACK WinProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lparam
);
//Utility.cpp
#include "Utility.h"
const wchar_t * pClassName=L"ATG";
HWND SetUp(HINSTANCE& hInstance)
{
WNDCLASSEX wnd;
wnd.cbSize=sizeof(WNDCLASSEX);
wnd.style=CS_HREDRAW|CS_VREDRAW;
wnd.lpfnWndProc=WinProc;
wnd.cbClsExtra=0;
wnd.cbWndExtra=0;
wnd.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wnd.hbrBackground=static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));
wnd.lpszClassName=0;
wnd.lpszClassName=pClassName;
wnd.hIconSm=NULL;
return CreateWindow(
pClassName,
L"一定成功",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,0,hInstance,0);
}
LRESULT CALLBACK WinProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_LBUTTONDOWN:
MessageBox(hwnd,L"mouse's left button clicked",L"attention",0);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,100,100,L"Visual C++ 2008",sizeof("Visual C++ 2008")-1);
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,L"to end?",L"attention",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
//exercise.cpp
#include "Utility.h"
int WINAPI WinMain(
HINSTANCE hinstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
HWND hWnd=SetUp(hinstance);
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0)==TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
[解决办法]
return CreateWindow( 语句前增加注册窗口类操作RegisterClassEx(&wnd);
[解决办法]
创建的窗口所属的类必须先注册