Getting UpdateLayeredWindow to work

by 6.9.05 0 comments
This code may be useful to get UpdateLayeredWindow for GDI working. It took me hours to get this working by the way. There are not good and working examples arround. You should replace "GetDC(hWnd)" later with a bitmap that contains four chanels (One for alpha). You only need a window handle for this: hWnd, if it works you should see a weird white window.

RECT rt;
POINT ptSrc = {0,0};
SIZE size;

SetWindowLong(hWnd, GWL_EXSTYLE,
GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);

GetWindowRect(hWnd,&rt);
size.cx = rt.right - rt.left;
size.cy = rt.bottom - rt.left;

BLENDFUNCTION blendFunc = {AC_SRC_OVER,0,128,AC_SRC_ALPHA};

int res = UpdateLayeredWindow(hWnd, NULL, NULL, &size,
GetDC(hWnd),&ptSrc,0,&blendFunc,ULW_ALPHA);

pepgma

Programmer, scientist

I am an engineer that divides its work life between programming and neuroscience. This blog is a “bitacora” to share thoughts, programming ideas, useful findings, and stuff (more...)