关于建立一个窗体运行后CPU占用很高的问题
这个是窗体的全部代码#include"windows.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitstanceClass(HINSTANCE);
BOOL Initstance(HINSTANCE,int);
HWND hwnd;
HINSTANCE hInstance;
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
MSG msg;
if (!InitstanceClass(hInstance))
{
MessageBox(hwnd,"EROOR!",0,MB_OK);
return FALSE;
}
if (!Initstance(hInstance,nShowCmd))
{
return FALSE;
}
while (GetMessage(&msg,hwnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (msg.wParam);
}
BOOL InitstanceClass(HINSTANCE hInstance)
{
WNDCLASS wndclass;
char a[]="FORM";
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=HBRUSH(GetStockObject(BLACK_BRUSH));
wndclass.hCursor=LoadCursor(hInstance,IDC_ARROW);
wndclass.hIcon=LoadIcon(hInstance,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=(WNDPROC)WndProc;
wndclass.lpszClassName="a";
wndclass.lpszMenuName=NULL;
wndclass.style=0;
return RegisterClass(&wndclass);
}
BOOL Initstance(HINSTANCE hInstance,int nShowCmd)
{
hwnd=CreateWindow("a","FORM",WS_OVERLAPPEDWINDOW,200,400,400,200,NULL,NULL,hInstance,NULL);
if (hwnd)
{
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
}
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hDc;
//HPEN hPen;
//HBRUSH hBrush;
switch(message)
{
case WM_LBUTTONDOWN:
hDc=GetDC(hwnd);
SetTextColor(hDc,RGB(44,125,35));
SetBkColor(hDc,RGB(0,255,0));
TextOut(hDc,100,100,"I`am alarght!",strlen("I`am alarght!"));
ReleaseDC(hwnd,hDc);
case WM_PAINT:
hDc=GetDC(hwnd);
SetPixel(hDc,20,30,RGB(44,63,160));
LineTo(hDc,40,60);
Rectangle(hDc,100,200,70,80);
//SetTextColor(hDc,RGB(44,125,35));
//SetBkColor(hDc,RGB(0,255,0));
//TextOut(hDc,100,100,"I`am alarght!",strlen("I`am alarght!"));
ReleaseDC(hwnd,hDc);
break;
case WM_DESTROY:PostQuitMessage(0);break;
default:return(DefWindowProc(hwnd,message,wParam,lParam));
}
}
我想请教为什么这个窗体运行后会占用很高的CPU资源,是不是哪里没有正确结束掉,还有就是default:return(DefWindowProc(hwnd,message,wParam,lParam));这里提示有个Warning,是什么问题!