2014-10-03 94 views
0

我想要一個無邊框對話框,但卻有對話框陰影。我遇到了這種解決方案Borderless Window Using Areo Snap, Shadow, Minimize Animation, and Shake,它通過使對話框的邊距爲1 px並將客戶區擴展到該解決方案來使用解決方法。通過MFC對話框中的對話框邊距繪圖

MARGINS borderless = { 1, 1, 1, 1 }; 
DwmExtendFrameInfoClientArea(this->GetSafeHwnd(), &borderless); 

Blank Dialog without a Border but with a Dialog Shadow

帖子中提到的客戶區字面上正在擴展和透明拉絲再次使得1px的每個可見對話框的邊緣。

現在,這到底發生了什麼,當我試圖畫一個實心矩形到整個對話:

// getting the client area 
CRect clientRect; 
GetClientRect(&clientRect); 

// expanding it to the new margins 
clientRect.left -= 1; 
clientRect.top -= 1; 
clientRect.right += 2; 
clientRect.bottom += 2; 

// set the Device Context to draw non transparent and with a black background 
pDC->SetBkMode(OPAQUE); 
pDC->SetBkColor(RGB(0, 0, 0)); 

// finally draw a rectangle to it 
CBrush brush_back_ground(RGB(0, 0, 0)); 
pDC->FillRect(clientRect, &brush_back_ground); 

但對話仍與它的利潤率得出: Blank Dialog with a Border of 1px each

如何將它有可能繪製一些東西在邊緣?稍後我將使用圖片作爲對話框背景,這些背景也應該繪製在邊緣上。

+2

不能使用傳統24 bpp的GDI函數在玻璃面積繪製,輸出將保持透明。你需要32bpp渲染,alpha通道必須包含,GDI +可以做到這一點。 – 2014-10-03 12:21:09

回答

0

感謝Hans Passant對他的評論。該解決方案是使用GDI +繪圖,而不是GDI的繪圖

// making a Gdi+ graphics object from my CDC* 
Graphics g(*pDC); 

// getting the client area 
CRect clientRect; 
GetClientRect(&clientRect); 

// making a Gdi+ rect 
Rect bkRect(0,0,clientRect.Width(), clientRect.Height()); 

// making a pen for the Rect Drawing 
Pen bkPen(Color(255,0,0,0)); 

// draw the rectangle over the full dialog 
g.DrawRectangle(&bkPen, bkRect); 

enter image description here