15,980
社区成员
发帖
与我相关
我的任务
分享
//
void CTransDlgDlg::RgnSubtractCtrls(CRgn &rgn,int offX,int offY)
{
CWnd *pWnd;
int ID[]={IDOK,IDCANCEL,IDC_BUTTON1};// list all ctrls's id here !
for(int jj=0;jj< sizeof(ID)/sizeof(int);jj++)
{
pWnd=GetDlgItem(ID[jj]);
CRect rc;
pWnd->GetWindowRect(&rc);
ScreenToClient(&rc);
rc.OffsetRect(offX,offY);
//
CRgn ctlRgn;
ctlRgn.CreateRectRgnIndirect(&rc);
rgn.CombineRgn(&rgn,&ctlRgn,RGN_XOR);
DeleteObject(ctlRgn);
}
}
是保证控件 不透明 。
void CTransDlgDlg::OnButton1()
{
// TODO: Add your control notification handler code here
static BOOL sw=FALSE;
if(!sw)
{
sw=TRUE;
CRect rcWin;
GetWindowRect(&rcWin);
//
CRect rcClt;
GetClientRect(&rcClt);
// rcClt.DeflateRect(20,20);
ClientToScreen(rcClt);
rcClt.OffsetRect(-rcWin.left,-rcWin.top);
//
int offX=rcClt.left;
int offY=rcClt.top;
rcWin.OffsetRect(-rcWin.left,-rcWin.top);
//
CRgn tmp;
tmp.CreateRectRgnIndirect(&rcClt);
// client - ctrls
RgnSubtractCtrls(tmp,offX,offY);
// finally
CRgn rgn;
rgn.CreateRectRgnIndirect(&rcWin);
rgn.CombineRgn(&rgn,&tmp,RGN_DIFF);
DeleteObject(tmp);
//
SetWindowRgn(rgn,TRUE);
m_Trans.SetWindowText("不透明");
}
else
{
sw=FALSE;
SetWindowRgn(0,TRUE);
m_Trans.SetWindowText("透明");
}
}
使窗口透明和不透明就是
SetWindowRgn(rgn,TRUE);
SetWindowRgn(0,TRUE);
对窗口调用
SetWindowRgn(0,TRUE);
就是 不透明。