C++ Builder Tips


Windows 2000/XPで半透明ウィンドウを使用するには


Windows 2000/XPで半透明ウィンドウを使用するには、SetLayeredWindowAttributes APIを使用します。

void TkSetTransparentWindow(HWND hWnd, int opacity)
{
  //ポインタ宣言
  typedef DWORD (WINAPI *FWINLAYER)(HWND hwnd,DWORD crKey,BYTE bAlpha,DWORD dwFlags);

  //DLLから関数アドレス取得
  HINSTANCE hDll = LoadLibrary("user32.dll");
  FWINLAYER setLayeredWindowAttributes = (FWINLAYER)GetProcAddress(hDll,"SetLayeredWindowAttributes");

  if(setLayeredWindowAttributes != NULL)
  {
    //WS_EX_LAYEREDを設定
    SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_LAYERED);

    //ポインタpfWinにSetLayeredWindowAttributes()のアドレスが設定されたので、後は
    setLayeredWindowAttributes(hWnd, 0, 255-opacity, 2);
  }
}


目次に戻る
Copyright(c) 2008 WoodenSoldier Software