windows窗口程序问题
#include "windows.h"
BOOL InitApplication( HINSTANCE hinstance );
BOOL InitInstance( HINSTANCE hinstance, int nCmdShow );
LRESULT CALLBACK MainWndProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
BOOL fGotMessage;
if( !InitApplication( hinstance ) )
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"), "MainWClass", MB_ICONERROR);
return FALSE;
}
if( InitInstance( hinstance, nCmdShow ) )
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"), "MainWClass", MB_ICONERROR);
return FALSE;
}
while( fGotMessage = GetMessage( &msg, (HWND) NULL, 0, 0 ) != 0 && fGotMessage != -1 )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
//UNREFERENCED_PARAMETER( lpCmdShow);
}
BOOL InitApplication( HINSTANCE hinstance )
{
WNDCLASSEX wcx;
wcx.cbSize = sizeof( wcx );
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hinstance;
wcx.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wcx.hCursor = LoadCursor( NULL, IDC_ARROW );
wcx.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
wcx.lpszMenuName = NULL;
wcx.lpszClassName = "MainWClass";
wcx.hIconSm = NULL;
return RegisterClassEx( &wcx );
}
BOOL InitInstance( HINSTANCE hinstance, int nCmdShow )
{
HWND hwnd;
//RECT rect;
//hinst = hinstance;
hwnd = CreateWindowEx(
0,
"MainWClass",
"Mem Mangament",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUPWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
600,
NULL,
NULL,
hinstance,
NULL);
if( !hwnd )
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"), "MainWClass", MB_ICONERROR);
return FALSE;
}
ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd );
return TRUE;
}
LRESULT CALLBACK MainWndProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch( uMsg )
{
case WM_CREATE:
break;
case WM_PAINT:
break;
//case WM_SIZE:
//{
//OnWindowResize();
//break;
//}
case WM_DESTROY:
{
PostQuitMessage( 0 );
break;
}
default:
break;
}
return DefWindowProc( hwnd, uMsg, wParam, lParam );
}
这个是代码 ,其功能就是创建一个窗口,但编译通过,运行报错,不知道哪里出了问题。
[解决办法]
wcx.lpfnWndProc = MainWndProc;
少了窗口过程