Layered window !
-
im trying to get my window to update using update UpdateLayeredWindow, but no luck so far. this is the function im using:
void update(HWND hwnd){ HDC pDC = GetDC(hwnd); HDC dcMem; dcMem = CreateCompatibleDC(pDC); COLORREF colour; colour = RGB(255,255,255); HBITMAP bmp; //bmp = LoadBitmap(aInstance, "clockbg.bmp"); bmp = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1)); if(!bmp)MessageBox(NULL,"FAIL TO LOAD IMAGE", "ERROR",NULL); HBITMAP pOldBitmap = (HBITMAP) SelectObject(dcMem, bmp); BLENDFUNCTION blend; blend.BlendOp = AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = 255; blend.AlphaFormat = AC_SRC_ALPHA; POINT ptSrc = {10, 10 }; SIZE sz = { 100, 100 }; UpdateLayeredWindow(hwnd, NULL, NULL, &sz, dcMem, &ptSrc, colour, &blend, ULW_COLORKEY ); DWORD dwError = GetLastError(); // <- this gives me 87 DeleteDC(dcMem); DeleteObject(pDC); }
it compiles and runs fine is just that UpdateLayeredWindow is doing nothing. thank you -
im trying to get my window to update using update UpdateLayeredWindow, but no luck so far. this is the function im using:
void update(HWND hwnd){ HDC pDC = GetDC(hwnd); HDC dcMem; dcMem = CreateCompatibleDC(pDC); COLORREF colour; colour = RGB(255,255,255); HBITMAP bmp; //bmp = LoadBitmap(aInstance, "clockbg.bmp"); bmp = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1)); if(!bmp)MessageBox(NULL,"FAIL TO LOAD IMAGE", "ERROR",NULL); HBITMAP pOldBitmap = (HBITMAP) SelectObject(dcMem, bmp); BLENDFUNCTION blend; blend.BlendOp = AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = 255; blend.AlphaFormat = AC_SRC_ALPHA; POINT ptSrc = {10, 10 }; SIZE sz = { 100, 100 }; UpdateLayeredWindow(hwnd, NULL, NULL, &sz, dcMem, &ptSrc, colour, &blend, ULW_COLORKEY ); DWORD dwError = GetLastError(); // <- this gives me 87 DeleteDC(dcMem); DeleteObject(pDC); }
it compiles and runs fine is just that UpdateLayeredWindow is doing nothing. thank youMaybe a silly question - Is the HWND a handle to a window created as a layered window? If so... Is the window a child window? Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Maybe a silly question - Is the HWND a handle to a window created as a layered window? If so... Is the window a child window? Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
yes is the handle to the window and no is not a child window. i've also posted on this forum the code: http://www.gamedev.net/community/forums/topic.asp?topic\_id=449081 thank you
-
yes is the handle to the window and no is not a child window. i've also posted on this forum the code: http://www.gamedev.net/community/forums/topic.asp?topic\_id=449081 thank you
Cool thanks for the link! I don't think you should be calling SetLayeredWindowAttributes(). Try commenting out that call. :) Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
yes is the handle to the window and no is not a child window. i've also posted on this forum the code: http://www.gamedev.net/community/forums/topic.asp?topic\_id=449081 thank you
Also, check success or fail of UpdateLayeredWindow() call BEFORE calling GetLastError() - in other words, only call GetLastError() if the UpdateLayeredWindow() call fails. Not all APIs clear the thread's last error when they succeed. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Cool thanks for the link! I don't think you should be calling SetLayeredWindowAttributes(). Try commenting out that call. :) Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Also, check success or fail of UpdateLayeredWindow() call BEFORE calling GetLastError() - in other words, only call GetLastError() if the UpdateLayeredWindow() call fails. Not all APIs clear the thread's last error when they succeed. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
OK but they are not meant to be used together - they cause the window updates to be done two different ways. If you must use both, the docs state "Note that once SetLayeredWindowAttributes has been called for a layered window, subsequent UpdateLayeredWindow calls will fail until the layering style bit is cleared and set again."
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
OK but they are not meant to be used together - they cause the window updates to be done two different ways. If you must use both, the docs state "Note that once SetLayeredWindowAttributes has been called for a layered window, subsequent UpdateLayeredWindow calls will fail until the layering style bit is cleared and set again."
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
without the SetLayeredWindowAttributes i dont get the 87 error code form getlast error which is a good news, but the window is not showing and UpdateLayeredWindow is returning 0;
Lamefif wrote:
the window is not showing and UpdateLayeredWindow is returning 0;
If it's returning 0 then it's still failing, right? Or do you mean GetLastError() returns 0? ACK I just noticed in your code on the other site - you are destroying the memDC. I'm pretty sure the system is going to need that to draw the window! Try keeping it around for the life of the window instead. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Lamefif wrote:
the window is not showing and UpdateLayeredWindow is returning 0;
If it's returning 0 then it's still failing, right? Or do you mean GetLastError() returns 0? ACK I just noticed in your code on the other site - you are destroying the memDC. I'm pretty sure the system is going to need that to draw the window! Try keeping it around for the life of the window instead. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
Thanks mark you've been a great help, the window is now showing. it was blend.SourceConstantAlpha = 255; set to 0 i think. but i still have some problems im using this image, http://mathforum.org/library/drmath/gifs/analog\_clock.jpg the white part of the image is showing the blue part is transparent. and mouse clicks go through the window, regardless where i click on it.
-
Thanks mark you've been a great help, the window is now showing. it was blend.SourceConstantAlpha = 255; set to 0 i think. but i still have some problems im using this image, http://mathforum.org/library/drmath/gifs/analog\_clock.jpg the white part of the image is showing the blue part is transparent. and mouse clicks go through the window, regardless where i click on it.
-
Thanks mark you've been a great help, the window is now showing. it was blend.SourceConstantAlpha = 255; set to 0 i think. but i still have some problems im using this image, http://mathforum.org/library/drmath/gifs/analog\_clock.jpg the white part of the image is showing the blue part is transparent. and mouse clicks go through the window, regardless where i click on it.
To hide the white you'll need to use UpdateLayeredWindow(hwnd, NULL, NULL, NULL, dcMem, NULL, RGB(255,255,255), 0, ULW_COLORKEY); To use alpha blending on the entire bitmap you'd use UpdateLayeredWindow(hwnd, NULL, NULL, NULL, dcMem, NULL, 0, &blend, LWA_ALPHA); To use both alpha and color key, you need to use SetLayeredWindowAttributes() instead of UpdateLayeredWindow()... SetLayeredWindowAttributes(hwnd, RGB(255,255,255), alphavalue, LWA_COLORKEY | LWA_ALPHA); Then you'd have to draw the bitmap yourself in response to WM_PAINT. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
using LWA_COLORKEY gets around that it seems, but the window comes out pixilated . now i have to figure out how to use an alpha channel :(
Lamefif wrote:
the window comes out pixilated
Because you've sized the window bigger than the bitmap??
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
To hide the white you'll need to use UpdateLayeredWindow(hwnd, NULL, NULL, NULL, dcMem, NULL, RGB(255,255,255), 0, ULW_COLORKEY); To use alpha blending on the entire bitmap you'd use UpdateLayeredWindow(hwnd, NULL, NULL, NULL, dcMem, NULL, 0, &blend, LWA_ALPHA); To use both alpha and color key, you need to use SetLayeredWindowAttributes() instead of UpdateLayeredWindow()... SetLayeredWindowAttributes(hwnd, RGB(255,255,255), alphavalue, LWA_COLORKEY | LWA_ALPHA); Then you'd have to draw the bitmap yourself in response to WM_PAINT. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
im having trouble with the pixilated edge, i tried adding a png file with an alpha cannel as a resource but it came out as row data.. ups. i want to use perpixilalpha as you can tell, whats the best way to go about this? thanks again
Have you tried using CImage or the GdiPlus::Bitmap class to load the png? Then you should be able to use the associated HBITMAP, selected into the dcMem and use UpdateLayeredWindow() like this: blend.BlendOp = AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = 255; blend.AlphaFormat = AC_SRC_ALPHA; UpdateLayeredWindow(hwnd, NULL, NULL, NULL, dcMem, NULL, 0, &blend, LWA_ALPHA);
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder