用SetWindowRgn可以设置窗口得形状。我用两个CRgn对象保存了两个RGN区域:
CRgn rgn1;
CRgn rgn2;其中rgn2的区域可以包含住rgn1,也就是说rgn1可以在rgn2内。然后写一个函数,大致如下:
ChangeWindow()
{
    if (bChange)
        SetWindowRgn((HRGN)rgn1, 1);
    else
        SetWindowRgn((HRGN)rgn2, 2);    bChange = !bChange;
}可是实际结果当换到大区域(rgn2)时,再次换回小区域(rgn1)就换不回来了,
窗口仍然是rgn2那么大。这里想请教大家是怎么回事,该如何解决?

解决方案 »

  1.   

    是这样的,hrgn 被赋值一次后就失效了
      

  2.   

    你的最后一个参数有问题吧。你看看的函数参考:
    SetWindowRgn
    The SetWindowRgn function sets the window region of a window. The window region determines the area within the window where the system permits drawing. The system does not display any portion of a window that lies outside of the window region int SetWindowRgn(
      HWND hWnd,     // handle to window
      HRGN hRgn,     // handle to region
      BOOL bRedraw   // window redraw option
    );
    Parameters
    hWnd 
    [in] Handle to the window whose window region is to be set. 
    hRgn 
    [in] Handle to a region. The function sets the window region of the window to this region. 
    If hRgn is NULL, the function sets the window region to NULL. bRedraw 
    [in] Specifies whether the system redraws the window after setting the window region. If bRedraw is TRUE, the system does so; otherwise, it does not. 
    Typically, you set bRedraw to TRUE if the window is visible. 
      

  3.   

    哎,你可以只使用一个rgn当bChange为真的时候让rgn=rgn1
    为假的时候rgn=rgn2
    这样不是很好吗
      

  4.   

    CRgn rgn1;
    CRgn rgn2;ChangeWindow()
    {
        if (bChange)
            SetWindowRgn((HRGN)rgn1.GetSafeHandle(),TRUE);
        else
            SetWindowRgn((HRGN)rgn2.GetSafeHandle(),TRUE);    bChange = !bChange;
    }
      

  5.   

    to smhpnuaa(农奴翻身感谢党):
    hrgn被赋值后会失效?不会吧?用CreateRectRgn创建的rgn,只能用DeleteObject让它失效吧?to ylb_and_xy(~0~蜗牛先生~0~):
    没问题的,我用的是MFC的函数。上面那个函数是用在窗口类里面的。to realyfly(我爱和平):
    有区别吗?你这样的话,相当于要定义一个临时变量rgn 啊?
      

  6.   

    to sans(sans):MFC的 SetWindowRgn的第一个参数要求一个HRGN的句柄。而CRgn类将HRGN重载了,所以(HRGN)rgn1得到就是这个对象的句柄。
    效果和rgn1.GetSafeHandle()是一样的。这不是问题的关键。关键在于好像SetWindowRgn将窗口设成大区域后,想再设成小区域就不行了。
    就好像小区域rgn1的值丢失了一样。可是跟踪发现它的句柄是有效句柄啊。感谢大家的关注,请大家继续。
      

  7.   

    up 
    u            p
      

  8.   

    to wanglei888(阿笨猫):头一次是没问题,可你多切换几次试试?