用API创建一个简单的WINDOWS窗口出错
#include "stdio.h"#include "windows.h"
LRESULT CALLBACK wndproc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
HINSTANCE hInstance;
class win
{
public:
BOOL W_class();
BOOL create();
};
BOOL win::W_class()
{
WNDCLASS wdnclass;//设计窗口
wdnclass.style=CS_HREDRAW|CS_VREDRAW;;//窗口
wdnclass.lpfnWndProc=wndproc;//窗口指针很重要
wdnclass.cbClsExtra=0;//通常为0
wdnclass.cbWndExtra=0;//通常为0
wdnclass.hInstance=hInstance;//句柄
wdnclass.hIcon=LoadIcon(NULL,IDI_ERROR);//图标句柄
wdnclass.hCursor=LoadCursor(NULL,IDC_CROSS);//光标句柄
wdnclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);//背色句柄
wdnclass.lpszMenuName=NULL;
wdnclass.lpszClassName="zhuzi";//类的名字
return (RegisterClass(&wdnclass));//注册窗口
}
BOOL win::create()
{
HWND hwnd;
hwnd=CreateWindow("zhuzi","猪",WS_OVERLAPPEDWINDOW,
200,200,600,400,NULL,NULL,
hInstance,NULL);
//显示窗口
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
return hwnd;
}
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
win window
if(!window.W_class())
return 0;
if(!window.create())
return 0;
//消息循环
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);//接收消息
DispatchMessage(&msg);//将接收的消息处理
}
return 0;
}
//过程函数
LRESULT CALLBACK wndproc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
HDC hdc;
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"猪",strlen("猪"));
EndPaint(hwnd,&ps);
break;
case WM_CHAR:
char szchar[20];
sprintf(szchar,"ch%d",wParam);
MessageBox(hwnd,szchar,"zhuzi",MB_OK);
break;
case WM_LBUTTONDOWN:
if(IDYES==MessageBox(hwnd,"猪编程","zhuzi",MB_YESNO))
{
HDC hDC;
hDC=GetDC(hwnd);
TextOut(hDC,150,150,"猪万岁",strlen("猪万岁"));
ReleaseDC(hwnd,hDC);
}
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"真的退出","zhuzi",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
break;
}
return 0;
}
出现:::
error C2440: 'return' : cannot convert from 'struct HWND__ *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\diyige.cpp(69) : error C2143: syntax error : missing ';' before 'if'
执行 cl.exe 时出错.
请高手改改到底那里错了~~~谢谢~~我是菜鸟