Re: icon background is not transparent when aero is enabled in vista
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Wed, 30 Jul 2008 10:07:55 -0400
See below...
On Tue, 29 Jul 2008 21:26:00 -0700, John <John@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
hello, all:****
i meet a curious thing.
i make a icon using vc2005, and the backgournd of icon is transparent.
i draw it to a dialog.
in xp, it is right, the backgournd is transparent.
but when aero is enabled in vista, the background is wrong, change into
white.
i find a way to solve this
i get the dialog 's dc ,and create a bitmap.
draw icon on the bitmap, and then draw bitmap to dialog's dc.
the code like below
int lWidth = rtClient.right - rtClient.left;
int lHeight = rtClient.bottom - rtClient.top;
RECT rcWindow;
::GetWindowRect(hDestWindowOverride, &rcWindow);
HDC hDCDisplay = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
Why not
CClientDC dcDisplay(this);
?
****
HBITMAP hMemBmpScreen = ::CreateCompatibleBitmap(hDCDisplay, lWidth,****
lHeight);
Why not
CBitmap MemBmpScreen;
MemBmpScreen.CreateCompatibleBitmap(&dcDisplay, width, height);
?
HDC hMemDCScreen = ::CreateCompatibleDC(hDCDisplay);****
Why not
MemBmpScreen.CreateCompatibleDC(&dcDisplay);
or for that matter
MemBmpScreen.CreateCompatibleDC(NULL);
****
HBITMAP pOld = (HBITMAP)::SelectObject(hMemDCScreen, hMemBmpScreen);****
::BitBlt(hMemDCScreen, 0, 0, lWidth, lHeight, hDCDisplay, rcWindow.left,
rcWindow.top, SRCCOPY);
::GetObject(hMemBmpScreen, sizeof(BITMAP),&g_bmp);
Why would you use a global variable here? Why does this need to be global at all?
****
//////////////////////////////////////////****
// hDiglog is the handle to dialog
::OpenClipboard(hDialog);
::EmptyClipboard();
::SetClipboardData(CF_BITMAP,hMemBmpScreen);
::CloseClipboard();
/////////////////////////////////////
Why are you putting something on the clipboard? You must NOT manipulate the clipboard
unless the user has *explicitly* done a Copy or Cut operation. Otherwise, it is a
disaster waiting to happen
****
****
::SelectObject(hMemDCScreen, pOld);
You could have used SaveDC/RestoreDC
****
::DeleteObject(hMemBmpScreen);****
::DeleteDC(hMemDCScreen);
These should not be necessary because the destructors for the CBitmap, CClientDC and CDC
will free them. (I note you did not free the display DC...)
***
****
Where is the code below relative to the code above? Same problems of using HDC, HBITMAP,
etc. Why not use the MFC objects?
****
//show bk bmp****
HDC hMemDC = ::CreateCompatibleDC(hDc);
HBITMAP hOldImageBMP = (HBITMAP)::SelectObject(hMemDC, hMemBmpScreen);
::BitBlt(hDc, 0,0,lWidth,lHeight,hMemDC,0,0,SRCCOPY);
if(hOldImageBMP)
::SelectObject(hMemDC, hOldImageBMP);
::DeleteDC(hMemDC);
the curious is if i dont add below, the background is wrong
//////////////////////////////////////////
// hDiglog is the handle to dialog
::OpenClipboard(hDialog);
::EmptyClipboard();
::SetClipboardData(CF_BITMAP,hMemBmpScreen);
::CloseClipboard();
/////////////////////////////////////
What does the clipboard have to do with any of this? Why is the clipboard being used at
all? I did not see that this was in the context of a Copy or Paste
****
so i want to know why i must open a clipboard****
So do I. You should not be touching the clipobard in any way, for any reason, if the user
has not explicitly invoked a Cut or Copy operation. To do so is to create a complete
flaming disaster.
****
who know more details about clipboard, plz tell me****
thanks in advance
The most important detail of the clipboard you need to know is that unless this is part of
the code for a user-requested Cut or Copy operation, KEEP YOUR HANDS OFF OF IT!
joe
****
good regardsJoseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Prev by Date: RE: Hiding Messagebox in CEditView
- Next by Date: Re: Hiding Messagebox in CEditView
- Previous by thread: icon background is not transparent when aero is enabled in vista
- Next by thread: PreTranslateMessage and m_msgCur problem
- Index(es):
Relevant Pages
|