讓視窗可以在開啟及關閉時透明度的轉換 |
|
yjh0225
一般會員 發表:7 回覆:7 積分:2 註冊:2003-10-13 發送簡訊給我 |
底下是小弟寫的簡單程式
可以讓視窗在開啟時由透明漸漸轉為不透明
視窗關閉時可以由不透明漸漸轉為透明 如有寫的不好的地方請多多指教!!
bool SetTransparent(HWND hWnd,COLORREF crKey,Byte bAlpha,DWORD dwFlags) { HINSTANCE m_hUserDll=LoadLibrary("user32.dll"); BOOL bRet = TRUE; typedef BOOL (WINAPI* lpfnSetTransparent)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags); // Check that "USER32.dll" library has been // loaded successfully... if ( m_hUserDll ) { lpfnSetTransparent pFnSetTransparent = NULL; pFnSetTransparent = (lpfnSetTransparent)GetProcAddress(m_hUserDll,"SetLayeredWindowAttributes"); if (pFnSetTransparent ) bRet = pFnSetTransparent(hWnd, crKey, bAlpha, dwFlags); else bRet = FALSE; } // if( m_hUserDll ) //LoadLibrary("user32.dll"); return bRet; } // End of SetTransparent function //--------------------------------------------------------------------------- __fastcall Tlogo::Tlogo(TComponent* Owner) : TForm(Owner) { SetWindowLong(logo->Handle,GWL_EXSTYLE,GetWindowLong(logo->Handle, GWL_EXSTYLE) | WS_EX_LAYERED); SetTransparent(logo->Handle, 0, 0, LWA_ALPHA); } //--------------------------------------------------------------------------- void __fastcall Tlogo::FormActivate(TObject *Sender) { Application->ProcessMessages(); for(int nPercent=0; nPercent<=255 ;nPercent ) SetTransparent( logo->Handle, 0, 255 * nPercent/255, LWA_ALPHA); } //--------------------------------------------------------------------------- void __fastcall Tlogo::FormClose(TObject *Sender, TCloseAction &Action) { for(int nPercent=255; nPercent >= 0 ;nPercent--) SetTransparent( logo->Handle, 0, 255 * nPercent/255, LWA_ALPHA); } |
pireer
初階會員 發表:73 回覆:80 積分:30 註冊:2004-12-14 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |