我写了一个很小的例子来描述我的问题1.首先我建了个对话框程序
--我把对话框设置为透明窗口 BOOL CMy1Dlg::OnInitDialog()
{
CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
} // Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
ModifyStyle(WS_BORDER | WS_SIZEBOX | WS_DLGFRAME | DS_MODALFRAME, WS_POPUP);
ModifyStyleEx(WS_EX_APPWINDOW | WS_EX_DLGMODALFRAME, WS_EX_LAYERED);
::SetLayeredWindowAttributes(m_hWnd,RGB(0,0,0,0),0,ULW_COLORKEY);
return TRUE; // return TRUE unless you set the focus to a control
}
BOOL CMy1Dlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
//return CDialog::OnEraseBkgnd(pDC);
}--经过我这两步操作窗口已经透明控件除外(就是需要控件不透明)
--在此我新建了一个类叫CmyPng它继承CButton(目的是自绘按钮给按钮贴PNG图片)void CmyPng::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
//1得到DC
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
//2.构建Graphics对象
Graphics graphics(dc);
Image image(L"PNG\\icon_success.png",TRUE);//外部调用
graphics.DrawImage(&image,0,0,38,38);
//3.分离dc
dc.Detach();
}
BOOL CmyPng::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
//return CButton::OnEraseBkgnd(pDC);
}
--经过我这两步操作按钮已经被自绘成PNG图片形式了---运行即可显示。!!!!!!注意问题在这里!!!!!!!!由于窗口透明后。。只要PNG图片是外发光或者边缘是半透明都会出现黑色的边框(如果没有外发光一切都正常)
但是只要窗口不是全透明或者按钮在背景图片之上按钮的发光效果就显示正常。。
请问这个是什么原因怎么解决
(注意:不要叫我下载什么控件或者什么PNG类...我试过一些PNG类只要把它窗口给透明,效果和我这个一样,不要叫我用UpdateLayeredWindow函数因为我有用处,不要说叫我循环遍历把黑色给透明化我相信有更好的办法)描述问题的小示例地址:
http://ys-e.ys168.com/1.0/295954658/l254L5I3NKHNI5VKSLkK/1.rar
我写的示例程序运行截图这是个网上下载较多的程序小示例我把它窗口透明后---结果和我描述一样
--我把对话框设置为透明窗口 BOOL CMy1Dlg::OnInitDialog()
{
CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
} // Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
ModifyStyle(WS_BORDER | WS_SIZEBOX | WS_DLGFRAME | DS_MODALFRAME, WS_POPUP);
ModifyStyleEx(WS_EX_APPWINDOW | WS_EX_DLGMODALFRAME, WS_EX_LAYERED);
::SetLayeredWindowAttributes(m_hWnd,RGB(0,0,0,0),0,ULW_COLORKEY);
return TRUE; // return TRUE unless you set the focus to a control
}
BOOL CMy1Dlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
//return CDialog::OnEraseBkgnd(pDC);
}--经过我这两步操作窗口已经透明控件除外(就是需要控件不透明)
--在此我新建了一个类叫CmyPng它继承CButton(目的是自绘按钮给按钮贴PNG图片)void CmyPng::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
//1得到DC
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
//2.构建Graphics对象
Graphics graphics(dc);
Image image(L"PNG\\icon_success.png",TRUE);//外部调用
graphics.DrawImage(&image,0,0,38,38);
//3.分离dc
dc.Detach();
}
BOOL CmyPng::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
//return CButton::OnEraseBkgnd(pDC);
}
--经过我这两步操作按钮已经被自绘成PNG图片形式了---运行即可显示。!!!!!!注意问题在这里!!!!!!!!由于窗口透明后。。只要PNG图片是外发光或者边缘是半透明都会出现黑色的边框(如果没有外发光一切都正常)
但是只要窗口不是全透明或者按钮在背景图片之上按钮的发光效果就显示正常。。
请问这个是什么原因怎么解决
(注意:不要叫我下载什么控件或者什么PNG类...我试过一些PNG类只要把它窗口给透明,效果和我这个一样,不要叫我用UpdateLayeredWindow函数因为我有用处,不要说叫我循环遍历把黑色给透明化我相信有更好的办法)描述问题的小示例地址:
http://ys-e.ys168.com/1.0/295954658/l254L5I3NKHNI5VKSLkK/1.rar
我写的示例程序运行截图这是个网上下载较多的程序小示例我把它窗口透明后---结果和我描述一样
应该将对话框弄成SetLayeredWindowAttributes指定的关键色才对
我是SetLayeredWindowAttributes和TransparentBlt一起用的。当然本来我的图片的质量确实不怎么好,是用256*256的ICO放大的