AnimateWindow 來美化你的對話方塊(淡入淡出,自動上升下降)

來源:互聯網
上載者:User

http://blog.sina.com.cn/s/blog_455245fc01000a42.html

 

法如下:

/**************************AnimateWindow()**************************/
 

#define AW_HOR_POSITIVE             0x00000001
#define AW_HOR_NEGATIVE             0x00000002
#define AW_VER_POSITIVE             0x00000004
#define AW_VER_NEGATIVE             0x00000008
#define AW_CENTER                   0x00000010
#define AW_HIDE                     0x00010000
#define AW_ACTIVATE                 0x00020000
#define AW_SLIDE                    0x00040000
#define AW_BLEND                    0x00080000

void CPageDlg::OnClose()    //實現淡出功能
{
 //定義AnimateWindow的函數指標 
 typedef UINT (CALLBACK* LPFUN)(HWND hwnd, DWORD dwTime,DWORD dwFlags);
 LPFUN pp; 
 HINSTANCE hInst=::LoadLibrary("user32.dll");

 if(hInst)
 {
  pp = (LPFUN)::GetProcAddress(hInst, "AnimateWindow" );
  pp(GetSafeHwnd(), 300,AW_BLEND|AW_HIDE);   // 紅色的是動畫類型
  ::FreeLibrary(hInst );                     //綠色的是時間
 }                                           //下同

CDialog::OnClose();
}

同理:

void CHipDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
 CDialog::OnShowWindow(bShow, nStatus);   //顯示時不過不是淡入,而是滾動
                                          //主要是表現下參數的不同
 // TODO: Add your message handler code here
  //定義AnimateWindow的函數指標
 typedef UINT (CALLBACK* LPFUN)(HWND hwnd, DWORD dwTime,DWORD dwFlags);
 LPFUN pp;
 HINSTANCE hInst=::LoadLibrary("user32.dll");

 if(hInst)
 {
  pp = (LPFUN)::GetProcAddress(hInst, "AnimateWindow" );
  pp(GetSafeHwnd(), 500, AW_SLIDE|AW_VER_NEGATIVE);
  ::FreeLibrary(hInst );
 }

}

 

 

關於參數問題:

函數原型:BOOL   AnimateWindow(HWND   hWnd,DWORD   dwTime,DWORD   dwFlags)。    
   
  函數功能:該函數能在顯示與隱藏視窗時產生兩種特殊類型的動畫效果:滾動動畫和滑動動畫。    
   
  參數含義:        
  hWnd:指定產生動畫的視窗的控制代碼。    
  dwTime:指明動畫持續的時間(以微秒計),完成一個動畫的標準時間為200微秒。    
  dwFags:指定動畫類型。這個參數可以是一個或多個下列標誌的組合。標誌描述:    
  AW_SLIDE:使用滑動類型。預設則為滾動動畫類型。當使用AW_CENTER標誌時,這個標誌就被忽略。    
  AW_ACTIVATE:啟用視窗。在使用了AW_HIDE標誌後不能使用這個標誌。    
  AW_BLEND:實現淡出效果。只有當hWnd為頂層視窗的時候才可以使用此標誌。    
  AW_HIDE:隱藏視窗,預設則顯示視窗。    
  AW_CENTER:若使用了AW_HIDE標誌,則使視窗向內重疊,即收縮視窗;若未使用AW_HIDE標誌,則使視窗向外擴充,即展開視窗。    
  AW_HOR_POSITIVE:自左向右顯示視窗。該標誌可以在滾動動畫和滑動動畫中使用。當使用AW_CENTER標誌時,該標誌將被忽略。    
  AW_VER_POSITIVE:自頂向下顯示視窗。該標誌可以在滾動動畫和滑動動畫中使用。當使用AW_CENTER標誌時,該標誌將被忽略。    
  AW_VER_NEGATIVE:自下向上顯示視窗。該標誌可以在滾動動畫和滑動動畫中使用。當使用AW_CENTER標誌時,該標誌將被忽略。    
   
     
  傳回值:如果函數成功,傳回值為非零;如果函數失敗,傳回值為零。在下列情況下函數將失敗:    
   
  視窗使用了視窗邊界;視窗已經可見仍要顯示視窗;視窗已經隱藏仍要隱藏視窗
 
$hwnd = GUICreate("Animate Window", 300, 300)

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00080000);fade-in
GUISetState()
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00090000);fade-out
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040001);slide in from left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050002);slide out to left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040002);slide in from right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050001);slide out to right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040004);slide-in from top
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050008);slide-out to top
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040008);slide-in from bottom
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050004);slide-out to bottom
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040005);diag slide-in from Top-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x0005000a);diag slide-out to Top-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040006);diag slide-in from Top-Right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050009);diag slide-out to Top-Right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040009);diag slide-in from Bottom-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050006);diag slide-out to Bottom-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x0004000a);diag slide-in from Bottom-right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050005);diag slide-out to Bottom-right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040010);explode
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050010);implode

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.