请大家给看看问题出在哪了? 问什么静态文本框不透明 还是初始灰色的窗口?
我用这个给附上背景void CDlgLogin::OnPaint()
{
PAINTSTRUCT ps;
CDC *dc=BeginPaint(&ps);
CDC memdc;
CRect rect;
CBitmap bitmap;
BITMAP szbitmap;
bitmap.LoadBitmap(IDB_IMG_LOGINBG); //背景图片ID
bitmap.GetObject(sizeof(BITMAP),&szbitmap);
CSize size(szbitmap.bmWidth,szbitmap.bmHeight);
memdc.CreateCompatibleDC(dc);
CBitmap *oldbitmap=memdc.SelectObject(&bitmap);
GetClientRect(&rect);
dc->StretchBlt(0,0,rect.Width(),rect.Height(),
&memdc,0,0,size.cx,size.cy,SRCCOPY);
memdc.SelectObject(oldbitmap);
memdc.DeleteDC();
EndPaint(&ps);
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
在给上面的静态文本进行透明化
HBRUSH CDlgLogin::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if(pWnd->GetDlgCtrlID() == CTLCOLOR_STATIC) // ID_YOURCTRL是要透明的control的ID
{
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)GetStockObject(NULL_BRUSH);
}
else
{
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
}
但是运行后只有主窗口有背景,而静态文本等都还是原来的灰色窗口,没有透明显示主窗口背景,请教这是怎么回事?