概述
win32 C RegisterClass失败
刚学win32没多久,,按书上的代码打了一遍,,,.
也没找到相关的资料..
很普通的代码:
#include
#include
#include
LRESULT CALLBACKWinSunProc(
HWND hwnd,UINT uMsg,WPARAM wparam,LPARAM lparam
);
int WINAPI WinMain(
HINSTANCE hinstance,
HINSTANCE hprevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hinstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName=_T("lihui");
wndcls.lpszClassName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
if(!RegisterClass(&wndcls))
return 0;
HWND hwnd;
hwnd=CreateWindow(_T("lihui"),_T("frank"),WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hinstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wparam,
LPARAM lparam )
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char code is %d",wparam);
MessageBoxA(hwnd,szChar,"char",0);
break;
case WM_LBUTTONDOWN:
MessageBoxA(hwnd,"mouse clicked","message",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,_T("frank"),strlen("frank"));
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,_T("www.myangguang.com"),strlen("www.myangguang.com"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBoxA(hwnd,"ÊÇ·ñÕæµÄ½áÊø£¿","message",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wparam,lparam);
}
return 0;
}
------解决方案--------------------
WNDCLASS wndcls;改成
WNDCLASS wndcls = {};
不然你那样的代码,这wndcls里面好几个成员都是无效值。。。
最后
以上就是怕孤单橘子为你收集整理的c语言class运行错误,win32 C RegisterClass失败,该如何处理的全部内容,希望文章能够帮你解决c语言class运行错误,win32 C RegisterClass失败,该如何处理所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复