首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求大家看看这个窗口程序错哪了

2013-03-27 
求大家看看这个窗口程序哪里错了#includewindows.h#includestdio.hLRESULT CALLBACK WinSunProc(HWND

求大家看看这个窗口程序哪里错了
#include<windows.h>
#include<stdio.h>

LRESULT CALLBACK WinSunProc(
   HWND hwnd,
   UINT uMsg,
   WPARAM wParam,
   LPARAM lParam
   );




int WINAPI WinMain(HINSTANCE hInstance,
   HINSTANCE hPrevInsatance,
   LPSTR lpCmdLine,
   int nCmdshow)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);
wndcls.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="Hellomygramming";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;

RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("Hellomygramming","TestWindowname",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);

ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);

MSG msg;
while(GetMessage(&msg,NULL,0,0));
{
TranslateMessage(&msg);
DispatchMessage(&msg);

}
return 0;
}
LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{HDC hdc;
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"Char is %d",wParam);
MessageBox(hwnd,szChar,"hellohello",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","Never click",0);
HDC hDC;
hDC=GetDC(hwnd);
TextOut(hDC,0,50,"I dontbelive u",strlen("I dontbelive u"));
ReleaseDC(hwnd,hDC);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,20,"hellohe",strlen("hellohelloo"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"do you wanna quit?","Tips",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;


}

求大家看看这个窗口程序错哪了
运行之后就卡了,只能用任务管理器关掉,别的操作没反应
winapi
[解决办法]

引用:
case WM_PAINT:
hdc=BeginPaint(hwnd,&amp;ps);
TextOut(hdc,0,20,"hellohe",strlen("hellohelloo"));
EndPaint(hwnd,&amp;ps);
return DefWindowProc(hwnd,uMsg,wParam,lParam);


将你的消息循环代码改一下
HACCEL hAccelTable;
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}


[解决办法]
引用:
引用:case WM_PAINT:
hdc=BeginPaint(hwnd,&amp;amp;ps);
TextOut(hdc,0,20,"hellohe",strlen("hellohelloo"));
EndPaint(hwnd,&amp;amp;ps);
return DefWindowProc(hwnd,uMsg,wParam……



大哥你害死我了, 花了两个小时帮你看问题, 居然是这样的错误
MSG msg;
while(GetMessage(&msg,NULL,0,0));//看见后面的分号没?
{
TranslateMessage(&msg);
DispatchMessage(&msg);

}

必须多加分补偿一下才行求大家看看这个窗口程序错哪了

热点排行