Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created October 7, 2010 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoggy/614911 to your computer and use it in GitHub Desktop.
Save yoggy/614911 to your computer and use it in GitHub Desktop.
void SetWindowTransparent(HWND hWnd, unsigned char alpha)
{
BOOL (*pSetLayeredWindowAttributes)(HWND, COLORREF, BYTE, DWORD) = NULL;
HMODULE hDll = LoadLibrary(_T("\\Windows\\coredll.dll"));
pSetLayeredWindowAttributes = (BOOL (*)(HWND, COLORREF, BYTE, DWORD))GetProcAddress(hDll, _T("SetLayeredWindowAttributes"));
LONG style = GetWindowLong(hWnd, GWL_EXSTYLE);
SetWindowLong(hWnd, GWL_EXSTYLE, style | WS_EX_LAYERED);
pSetLayeredWindowAttributes(hWnd, 0, alpha, LWA_ALPHA);
FreeLibrary(hDll);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment