UpdateLayeredWindow() fails, GetLastError() == 0
-
Hi. I have (in my oppinion) a VERY annoying and wierd problem. I'm using UpdateLayeredWindow() according to the code below. I do the FillRect() just for testing. But when I do this UpdateLayeredWindow() returns 0 which, according to the msdn documentation, indicates that the function failed and more info should be in GetLastError(). However, if I call GetLastError() just after UpdateLayeredWindow() it simply returns 0, indicating that there was no last error. I have remembered to set WS_EX_LAYERED... Could it be that FillRect() doesn't set any alpha information? Any ideas? Thanks.
HDC dcScreen = ::GetDC(NULL); HDC dcMemory = ::CreateCompatibleDC(dcScreen); HBITMAP bmpMemory = ::CreateCompatibleBitmap(dcScreen, 500, 500); ::SelectObject(dcMemory, bmpMemory); BITMAP bitmap; GetObject(bmpMemory, sizeof(BITMAP), &bitmap); RECT rc = {0, 0, 100, 100}; ::FillRect(dcMemory, &rc, ::GetSysColorBrush(COLOR_HIGHLIGHTTEXT)); BLENDFUNCTION bf = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA}; UpdateLayeredWindow(m_hWnd, dcScreen, NULL, NULL, dcMemory, NULL, 0, &bf, ULW_ALPHA);
-
Hi. I have (in my oppinion) a VERY annoying and wierd problem. I'm using UpdateLayeredWindow() according to the code below. I do the FillRect() just for testing. But when I do this UpdateLayeredWindow() returns 0 which, according to the msdn documentation, indicates that the function failed and more info should be in GetLastError(). However, if I call GetLastError() just after UpdateLayeredWindow() it simply returns 0, indicating that there was no last error. I have remembered to set WS_EX_LAYERED... Could it be that FillRect() doesn't set any alpha information? Any ideas? Thanks.
HDC dcScreen = ::GetDC(NULL); HDC dcMemory = ::CreateCompatibleDC(dcScreen); HBITMAP bmpMemory = ::CreateCompatibleBitmap(dcScreen, 500, 500); ::SelectObject(dcMemory, bmpMemory); BITMAP bitmap; GetObject(bmpMemory, sizeof(BITMAP), &bitmap); RECT rc = {0, 0, 100, 100}; ::FillRect(dcMemory, &rc, ::GetSysColorBrush(COLOR_HIGHLIGHTTEXT)); BLENDFUNCTION bf = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA}; UpdateLayeredWindow(m_hWnd, dcScreen, NULL, NULL, dcMemory, NULL, 0, &bf, ULW_ALPHA);
Since you're specifying the source DC (dcMemory), I would try passing values for arguments 3,4 & 6 (i.e., the various size and positions). Argument 6 should just be the address of a POINT with value (0,0). I use this function all the time, and that's what I do (returns non zero - and it works of course:-))