我在我的窗口消息处理函数有这么一段代码,case WM_PAINT:
         hdc = BeginPaint(hWnd, &ps);         RECT rect;
GetClientRect(hWnd, &rect);
         
         //擦除背景
hRgnSrc1 = CreateRectRgn(rect.left, rect.top, rect.right, rect.bottom);
FillRgn(hdc, hRgnSrc1, (HBRUSH)(COLOR_WINDOW+2));         EndPaint(hWnd, &ps);擦除背景段代码好像没有作用,但如果将 FillRgn 改成 FillRect(hdc, &rect, (HBRUSH)(COLOR_WINDOW+2)) 就可以,不知道是什么原因,请各位老兄帮帮忙。
谢谢!

解决方案 »

  1.   

    那就是你的hRgnSrc1没有取到呀!!
      

  2.   

    To: feiniaoliang(飞鸟良):我已经调试过 hRgnSrc1 是取到了, CreateRectRgn返回了有效的句柄,并没有返回NULL值
      

  3.   

    To: FlyingSch(BoyWithWings)谢谢你的帮助!我按照你说的将代码改为如下: HBRUSH hBrush = CreateSolidBrush( COLOR_WINDOW +2 );
     FillRgn(hdc, hRgnSrc1, hBrush);它就可以正常工作了,真是谢谢你了。
    我通过Microsoft 的新闻组得到了原因:原文:-----------------------------------------------------------------------------
    FillRgn is a GDI function, FillRect is a USER function. GDI function only
    takes real GDI object handle
    --
    Feng Yuan (www.fengyuan.com)This posting is provided "AS IS" with no warranties, and confers no rights.
    -----------------------------------------------------------------------------意思是:FillRgn 是属于 GDI 模块的,而 FillRect 是属于 USER 模块的, GDI 的函数
    必须要使用真正的 GDI 对象句柄。所以我必须使用 CreateSolidBrush 来创建 GDI 的 Brush 对象来给 FillRgn 使用。