Jump to content
  • Advertisement
Sign in to follow this  
arthur83

UpdateLayeredWindow() fails, GetLastError() == 0

This topic is 4204 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I have (in my opinion) a VERY annoying and weird 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);
[Edited by - arthur83 on March 22, 2007 3:55:32 AM]

Share this post


Link to post
Share on other sites
Advertisement
I wouldn't be surprised, there is a case with PostMessage I think it was, where it returns a failure code and GetLastError returns zero.
It happens when the target window's mesage queue is full IIRC.

Just be very careful not to call any other API functions before you call GetLastError.

Share this post


Link to post
Share on other sites
What do you know. Now it works. Apparently the arguments I left to NULL in my case were more important than I thought, even though I interpreted it from the documentation that they were not important if you wanted to leave the size and position unchanged.
Thanks for your help! Good to know about PostMessage() aswell :)

The following peice did it:

RECT rcWindow;
GetWindowRect(m_hWnd, &rcWindow);

SIZE szDest = {rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top};
POINT ptDest = {rcWindow.left, rcWindow.top};
POINT ptSrc = {0, 0};

UpdateLayeredWindow(m_hWnd,
dcScreen,
&ptDest,
&szDest,
dcMemory,
&ptSrc,
0,
&bf,
ULW_ALPHA);



[Edited by - arthur83 on March 22, 2007 3:13:00 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!