|
I would like to be able to turn on and off a bitmap in a dialog when a particular condition exists. I can create the bitmap but I can't seem to find out how to make it invisible when I dont want to see it. Can someone tell how to accomplish this?
Thanks,
Terry
|
|
|
|
|
how do u display your bitmap?
if u call RedawWindow() without displaying it, the bitmap is invisible.
|
|
|
|
|
I have created the bitmap through the dialog editor. I have an ID for the bitmap but am not able to change it's state. How do I implement RedrawWindow? GetDlgItem(IDB_BITMAP)->RedrawWindow(??)?
|
|
|
|
|
Bitmaps don't have a state, nor are they dialog controls. Is the bitmap being displayed in a control? If so, hide or show that control using ShowWindow(). If you are drawing the bitmap
yourself, don't draw it if you want it invisible.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Excellent thanks Mark. I did not realize what I was doing. I did use a picture control to display the bitmap. After you mentioned the bitmap being displayed in a control it clicked. When I used
GetDlgItem(IDC_MYCONTROL)->ShowWindow(SW_HIDE);
The bitmap was hidden and I can make it visible when I need it.
Terry
|
|
|
|
|
if you have a control for show bitmap you can use of ShowWindow(SW_HIDE|SW_SHOW); for visible or invisible.
|
|
|
|
|
I tried to change the state by using GetDlgItem(IDB_BITMAP)->ShowWindow(SW_HIDE); but I get an error at runtime but builds okay. I am sure I am missing something. I created the bitmap in the dialog editor and gave it an ID (IDB_BITMAP).
|
|
|
|
|
Thanks. Once I figured out what I was doing I was able to use ShowWindow(SW_HIDE) to hide the bitmap.
Terry
|
|
|
|
|
It seems its not your control does IDB_BITMAP a bitmap resource?what control do you use? CStatic or Button ...
and how did you create it?
-----------------------
Well I think you solved problem.
|
|
|
|
|
To answer your questions... Yes I was originally trying to do this with my bitmap resource "IDB_BITMAP", which was not working at all. I created a picture control which is CStatic I believe and added the bitmap resource to it. I did not realize what I had done until Mark had mentioned the control was what I needed to change and not the bitmap. Yes, I got it going now. Thanks for your responses.
Terry
|
|
|
|
|
hi im trying to code below, but is not working.
void update(HWND hwnd){<br />
<br />
HBITMAP pBitmap;<br />
pBitmap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1));
<br />
no errors it compiles fine just no window <br />
<br />
HDC pDC = GetDC(hwnd);<br />
HDC dcMem;<br />
dcMem = CreateCompatibleDC(pDC);<br />
COLORREF colour;<br />
colour = RGB(255,255,255);<br />
<br />
SelectObject(dcMem,pBitmap);<br />
<br />
BLENDFUNCTION blend;<br />
blend.BlendOp = AC_SRC_OVER;<br />
blend.BlendFlags = 0;<br />
blend.SourceConstantAlpha = 255;<br />
blend.AlphaFormat = AC_SRC_ALPHA;<br />
<br />
POINT ptSrc = {0, 0 };<br />
SIZE sz = { 270, 270 };<br />
<br />
int p = UpdateLayeredWindow(hwnd, NULL, NULL, &sz, dcMem, &ptSrc, colour, &blend, LWA_ALPHA );<br />
}
thank you
|
|
|
|
|
|
pBitmap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1)); //
^ this shows the window
Image* pBitmap = new Image(L"clockbg.bmp");
^ this does not
they are the same image loaded differently.
thank you
|
|
|
|
|
Lamefif wrote: Image* pBitmap = new Image(L"clockbg.bmp");
^ this does not
Maybe you need the full pathname of the file?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
And where's clockbg.bmp(path of file)?
|
|
|
|
|
the image is in my project folder and i know it loads because i can display it like this:
Bitmap bitmap(L"clockbg.bmp");
graphics.DrawImage(&bitmap, 0, 0);
and it shows
thanks
|
|
|
|
|
Bitmap is derived from Image.
If
Bitmap bitmap(L"clockbg.bmp");
graphics.DrawImage(&bitmap, 0, 0);
works, then
Image* pBitmap = new Image(L"clockbg.bmp");
graphics.DrawImage(pBitmap, 0, 0);
should work.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
i know Mark thats not my problem, but when i use GDI+ to load the image:
Image* pBitmap = new Image(L"clockbg.bmp"); or Bitmap.
as appose to:
HBITMAP pBitmap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1));
and i use it for my:
UpdateLayeredWindow(hwnd, NULL, NULL, &sz, dcMem, &ptSrc, colour, &blend, LWA_ALPHA );
the window doesn't show, as i've posted in the code above
is the same image and i now it loads, i dont now..
thank you
|
|
|
|
|
Sorry about that - I should have read the first post more closely
Maybe this will work better...
Image* pBitmap = new Image(L"clockbg.bmp");
HDC pDC = GetDC(hwnd);
HDC dcMem;
dcMem = CreateCompatibleDC(pDC);
COLORREF colour;
colour = RGB(255,255,255);
<code>HBITMAP hBitmap;
pBitmap->GetHBITMAP(Color(0xFF,0xFF,0xFF), &hBitmap);</code>
SelectObject(dcMem, hBitmap);
...
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks Mark, but my aim is to use the transparency of the png and Alpha channel
to define the transparency, perpixelvlue as it were.
am goind all wrong about it?
thanks
|
|
|
|
|
I "think" you may be able to use a 32-bit ARGB DIBsection - I put together this test just to
make sure the alpha channel stuff was working.
(My "hdc" would be your "dcMem" and you wouldn't want to delete it or un-select your alpha bitmap
like I have if you pass it to UpdateLayeredWindow())
Image TransparentSrcBitmap(L"clockbg.bmp");
LONG lImageWidth = TransparentSrcBitmap.GetWidth();
LONG lImageHeight = TransparentSrcBitmap.GetHeight();
WORD wBitsPerPixel = 32;
LONG lBytesPerRow = lImageWidth * 4;
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = lImageWidth;
bmi.bmiHeader.biHeight = lImageHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = wBitsPerPixel;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = lBytesPerRow * lImageHeight;
HDC hdc = ::CreateCompatibleDC(0);
BYTE* pBitmapBits;
HBITMAP hBitmap = ::CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&pBitmapBits, NULL, 0);
if (hBitmap)
{
memset(pBitmapBits, 0, bmi.bmiHeader.biSizeImage);
HGDIOBJ hOldBitmap = ::SelectObject(hdc, hBitmap);
Graphics DstGraphics(hdc);
DstGraphics.DrawImage(&TransparentSrcBitmap, 0, 0, TransparentSrcBitmap.GetWidth(), TransparentSrcBitmap.GetHeight());
BLENDFUNCTION bf;
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 0x7F;
bf.AlphaFormat = AC_SRC_ALPHA;
HDC hClientDC = ::GetDC(*this);
::AlphaBlend(hClientDC, 50, 50, TransparentSrcBitmap.GetWidth(), TransparentSrcBitmap.GetHeight(),
hdc, 0, 0, TransparentSrcBitmap.GetWidth(), TransparentSrcBitmap.GetHeight(), bf);
::ReleaseDC(*this, hClientDC);
::SelectObject(hdc, hOldBitmap);<code>
::DeleteObject(hBitmap);<code>
}
::DeleteDC(hdc); <code>
Sorry about all the strange extra variables - I cut and paste from assorted working code to throw
together a test - saves some typing.
-- modified at 15:30 Friday 1st June, 2007
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
thank you Mark very much for taking the time, it mean as lot me.
but is not quite there is coming out pixalated, the alpha value is being replace by a black colour.
program running image:
http://img118.imageshack.us/img118/8953/testwindowhu9.png
.
.
.
Code: the main method.
http://rafb.net/p/1Dfouz58.html
thank you so much ....
|
|
|
|
|
No problem!
Can you show your latest code?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
What's "image" and what's "program window" in your screenshot?
Never mind I get it LOL
I'd still like to see your updated code if you can
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Code: the main method.
http://rafb.net/p/1Dfouz58.html
^i posted here
|
|
|
|