简单的窗口创建遇到问题
#include<windows.h>#include <stdio.h>
LRESULT CALLBACK LiProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
class CWnd
{
public:
CWnd()
{
hwnd=NULL;
}
BOOL CreateEx(DWORD dwExStyle, // extended window style
LPCTSTR lpClassName, // registered class name
LPCTSTR lpWindowName, // window name
DWORD dwStyle, // window style
int x, // horizontal position of window
int y, // vertical position of window
int nWidth, // window width
int nHeight, // window height
HWND hWndParent, // handle to parent or owner window
HMENU hMenu, // menu handle or child identifier
HINSTANCE hInstance, // handle to application instance
LPVOID lpParam); // window-creation data
BOOL ShowWindow(int nCmdShow);
BOOL UpdateWindow();
public:
HWND hwnd;
};
BOOL CWnd::CreateEx(DWORD dwExStyle, // extended window style
LPCTSTR lpClassName, // registered class name
LPCTSTR lpWindowName, // window name
DWORD dwStyle, // window style
int x, // horizontal position of window
int y, // vertical position of window
int nWidth, // window width
int nHeight, // window height
HWND hWndParent, // handle to parent or owner window
HMENU hMenu, // menu handle or child identifier
HINSTANCE hInstance, // handle to application instance
LPVOID lpParam) // window-creation data
{
hwnd=::CreateWindowEx(dwExStyle,lpClassName,lpWindowName,dwStyle,x,y,
nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam);
if( hwnd!=NULL)
return TRUE;
else
return FALSE;
}
BOOL CWnd::ShowWindow(int nCmdShow)
{
return ::ShowWindow( hwnd,nCmdShow);
}
BOOL CWnd::UpdateWindow()
{
return ::UpdateWindow(hwnd);
}
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
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=LiProc;
wndclass.lpszClassName="exe";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wndclass);
CWnd wnd;
wnd.CreateEx(0,"exe","简单的窗口创建",WS_OVERLAPPEDWINDOW,100,100,600,500,NULL,NULL,hInstance,
NULL);
wnd.ShowWindow(SW_SHOWNORMAL);
wnd.UpdateWindow();
MSG msg;
while(GetMessage(&msg, hwnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK LiProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_CHAR:
char str[20];
sprintf(str, " char is%d",wParam);
MessageBox(hwnd,str,"消息盒子",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","消息盒子",0);
HDC hDc;
hDc=GetDC( hwnd);
TextOut(hDc,0,100,"Hello word, hello every people!",strlen("Hello word, hello every people!"));
ReleaseDC( hwnd,hDc);
break;
case WM_CLOSE:
if(IDYES==MessageBox( hwnd,"确定退出?","消息盒子",MB_YESNO))
{
DestroyWindow( hwnd);
}
break;
case WM_PAINT:
PAINTSTRUCT pt;
HDC hdc;
hdc=BeginPaint( hwnd,&pt);
TextOut(hdc,0,50,"Hello word!",strlen("Hello word!"));
EndPaint(hwnd,&pt);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc( hwnd,uMsg,wParam,lParam);
break;
}
return 0;
}
出现错误 error C2065: 'hwnd' : undeclared identifier
fatal error C1903: unable to recover from previous error(s); stopping compilation
为什么会这样啊(刚学MFC)