关于填充问题?
#include<windows.h>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
MSG msg;
WNDCLASS wndclass;
HWND hwnd;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=TEXT("hi");
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("错误"),TEXT("警告"),MB_ICONERROR);
}
hwnd=CreateWindow(TEXT("hi"),TEXT("画图"),WS_OVERLAPPEDWINDOW,100,100,500,500,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{ HDC hdc;
PAINTSTRUCT ps;
RECT rect;
HPEN gpen,rpen;
gpen=CreatePen(PS_SOLID,7,RGB(34,139,34));
rpen=CreatePen(PS_SOLID,7,RGB(250,128,114));
HBRUSH gbrush,rbrush;
gbrush=CreateSolidBrush(RGB(46,139,87 ));
rbrush=CreateSolidBrush(RGB(250,128,114));
GetClientRect(hwnd,&rect);
switch(message)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SelectObject(hdc,gpen);
FillRect(hdc,&rect,gbrush);
Rectangle(hdc,0,0,200,900);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
DeleteObject(gpen);
DeleteObject(gbrush);
EndPaint(hwnd,&ps);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
为什么那个FillRect()函数不可以填充Rectangle()这个矩形,如果放在Rectangle()上面就会只剩下这个矩形没填充,如果放在Rectangle()下面就全部覆盖,难道这个函数只是可以填充背景?