本文轉自:http://blog.csdn.net/testcs_dn/article/details/7647732
1.如何將對話框客戶區的背景設成透明的?
crybird (寒號鳥)
http://expert.csdn.net/Expert/topic/2172/2172079.xml
描述:如題。客戶區的背景能設成透明的麼?如果有時間,非客戶區的隱藏也講講啦!
回覆人: bcpl(我是宇宙中的一粒沙子)
BOOL CALLBACK EnumChildFunc(HWND hwnd, LPARAM lParam)
{
CRgn *pRgn = (CRgn*)lParam;
CRect rcChild;
::GetWindowRect(hwnd, rcChild);
CRgn rgnChild;
CRgn rgnCopy;
rgnCopy.CreateRectRgn(0, 0, 1, 1);
rgnCopy.CopyRgn(pRgn);
rgnChild.CreateRectRgn(rcChild.left, rcChild.top, rcChild.right, rcChild.bottom);
pRgn->CombineRgn(&rgnCopy, &rgnChild, RGN_OR);
return TRUE;
}
int SetBackTransparent(CWnd *pWnd, BOOL bClientOnly = TRUE)
{
CRgn rgn;
if(bClientOnly)
{
CRgn rgnWindow, rgnClient;
CRect rcWindow, rcClient, rcRgn;
pWnd->GetWindowRect(rcWindow);
pWnd->GetClientRect(rcClient);
pWnd->ClientToScreen(rcClient);
rgnWindow.CreateRectRgn(rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
rgnClient.CreateRectRgn(rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
rgn.CreateRectRgn(0, 0, 1, 1);
rgn.CombineRgn(&rgnWindow, &rgnClient, RGN_DIFF);
}
else
{
rgn.CreateRectRgn(0, 0, 0, 0);
}
::EnumChildWindows(pWnd->GetSafeHwnd(), (WNDENUMPROC)EnumChildFunc,(LPARAM)&rgn);
return pWnd->SetWindowRgn(rgn, TRUE);
}
調用辦法:
在CYourDialog::OnInitDialog里加上
SetBackTransparent(this);
如果要連非客戶區都透明,用
SetBackTransparent(this, FALSE);
版主點評:
高手。
//---------------------------------------------------------------------------
http://expert.csdn.net/Expert/topic/2422/2422164.xml
主 題: 如何在一個背景圖像上,做半透明的圖?
作 者: DMC (DMC)
描述:
如何在一個背景圖像上,做半透明的圖。我想實現在一個地圖上顯示半透明的數據信息,類似天氣預報中等壓圖的處理。如何才能實現這個背景圖和最上層圖的相互映射,完成半透明的效果?
回覆人: Raxxxer(Jasmine Hellstorm)
你可以使用windows的一個api AlphaBlend,用法和BitBlt差不多:
BLENDFUNCTION bf;
bf.AlphaFormat=0;
bf.BlendFlags=0;
bf.BlendOp=AC_SRC_OVER;
bf.SourceConstantAlpha=100;//透明度0-255
AlphaBlend(hBackDC,0,70,73,20,hMaskDC,0,0,73,20,bf);
不可以在WindowsCE裏用
#include <wingdi.h>
//還要在Project -- setting -- link 裏連接上msimg32.lib