ウィンドウを透明に
SetLayeredWindowAttributes
#ifndef _INC_H_HELP_USER_DLL
#define _INC_H_HELP_USER_DLL
#include <WinUser.h>
////
//*******************************************************************************
// 関数名 :SetLayeredWindowAttributes
// 作成日 :’11/01/26
//*******************************************************************************
// C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\WinUser.h より
#ifndef LWA_COLORKEY
WINUSERAPI BOOL WINAPI SetLayeredWindowAttributes(HWND hwnd,COLORREF crKey,BYTE bAlpha,DWORD dwFlags) ;
#define LWA_COLORKEY 0x00000001
#define LWA_ALPHA 0x00000002
inline
BOOL Hlp_SetLayeredWindowAttributes (HWND hwnd,COLORREF crKey,BYTE bAlpha,DWORD dwFlags)
{
HMODULE hDll = ::LoadLibrary(_T(“User32.dll”)) ;
if (hDll == NULL) { return FALSE ; }
HRESULT (WINAPI *pfSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD) = NULL ;
(FARPROC&)pfSetLayeredWindowAttributes = ::GetProcAddress(hDll,(“SetLayeredWindowAttributes”)) ;
BOOL res = FALSE ;
if (pfSetLayeredWindowAttributes != NULL) {
res = pfSetLayeredWindowAttributes(hwnd,crKey,bAlpha,dwFlags) ;
}
::FreeLibrary(hDll) ;
return res ;
}
#define Use_Help
#endif
////
//*******************************************************************************
// 関数名 :SetLayeredWindowAttributes
// 作成日 :’11/01/26
//*******************************************************************************
#ifndef WS_EX_LAYERED
#define WS_EX_LAYERED 0x00080000
#endif
inline
BOOL SetLayeredWindowAttributes(CWnd*wnd,COLORREF key,BYTE alpha=128,DWORD flags=LWA_COLORKEY)
{
if (wnd == NULL) { return FALSE ; }
HWND hwnd = wnd->GetSafeHwnd() ;
if (hwnd == NULL) { return FALSE ; }
BOOL result = FALSE ;
LONG exStyle=::GetWindowLong(hwnd,GWL_EXSTYLE) ;
::SetWindowLong(hwnd,GWL_EXSTYLE,exStyle|WS_EX_LAYERED) ;
#ifdef Use_Help
result = ::Hlp_SetLayeredWindowAttributes(hwnd,key,alpha,flags) ;
#else
result = ::SetLayeredWindowAttributes(hwnd,key,alpha,flags) ;
#endif
return result ;
}
#endif