Re: icon background is not transparent when aero is enabled in vista



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 regards

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Drawing an icon so that a particular color is transparent
    ... Use the "Screen Color" as the color (that's the little ... formats using the VS 2008 icon editor. ... LoadImage and draw it with DrawIconEx on my WM_PAINT's DC. ... the image, white, to be transparent so the image looks better against ...
    (microsoft.public.win32.programmer.gdi)
  • icon background is not transparent when aero is enabled in vista
    ... i make a icon using vc2005, and the backgournd of icon is transparent. ... draw icon on the bitmap, and then draw bitmap to dialog's dc. ...
    (microsoft.public.vc.mfc)
  • about icon background in vista
    ... i make a icon using vc2005, and the backgournd of icon is transparent. ... draw icon on the bitmap, and then draw bitmap to dialog's dc. ...
    (microsoft.public.vc.mfc)
  • drawing image as a partly transparent one
    ... I have an icon I want to draw onto the screen, but I want to streatch it out ... to be about 256x256 and make it about 75% transparent how would I go about ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Cut & Paste in Office 2003 returns Bitmap image only - no tex
    ... Today I was typing an email and I highlighted a section to copy and paste to ... Then I the office clipboard and saw a little icon of the full screen shot ... Guess what - a new screen shot was automatically created when I ...
    (microsoft.public.office.misc)