程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> c++ 代碼 使窗體震動,實現最前提醒

c++ 代碼 使窗體震動,實現最前提醒

編輯:C++入門知識

#ifndef DEBUG_DISABLE 
#define DEBUG_ENTERED(M)  MessageBox(NULL,\ 
M,\ 
"Tip",\ 
    MB_OK); 
#else 
#define DEBUG_ENTERED(M)   
#endif 
 
BOOL                ShockWindow(HWND hWindow,DWORD dwDelayTime/*ms*/,DWORD dwShockTimes,DWORD dwSpan,BOOL bStayTop); 

 

[cpp]
BOOL                ShockWindow(HWND hWindow,DWORD dwDelayTime,DWORD dwShockTimes,DWORD dwSpan,BOOL bStayTop) 

    //get the information of the window 
    RECT rect; 
    GetWindowRect(hWindow,&rect); 
 
    //valid? 
    if(!hWindow) 
    { 
        DEBUG_ENTERED("Can not find window!") 
        return FALSE; 
    } 
    else 
    { 
        ShowWindow(hWindow,SW_NORMAL); 
        DEBUG_ENTERED("ENTER PROCESSING") 
 
        //if window is minimize,without this statement ,will cause the window hide 
        GetWindowRect(hWindow,&rect); 
 
        //on top 
        SetWindowPos(hWindow,HWND_TOPMOST,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,SWP_NOSIZE|SWP_NOMOVE); 
         
        //start shock 
        for(int i=0;i<dwShockTimes;++i) 
        { 
            MoveWindow(hWindow,rect.left+dwSpan,rect.top,rect.right-rect.left,rect.bottom-rect.top,TRUE); 
            Sleep(dwDelayTime); 
            MoveWindow(hWindow,rect.left,rect.top-dwSpan,rect.right-rect.left,rect.bottom-rect.top,TRUE); 
            Sleep(dwDelayTime); 
            MoveWindow(hWindow,rect.left-dwSpan,rect.top,rect.right-rect.left,rect.bottom-rect.top,TRUE); 
            Sleep(dwDelayTime); 
            MoveWindow(hWindow,rect.left,rect.top+dwSpan,rect.right-rect.left,rect.bottom-rect.top,TRUE); 
            Sleep(dwDelayTime); 
        } 
 
        //back to original position  www.2cto.com
        MoveWindow(hWindow,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,TRUE); 
 
        //weather the window want to be on top PS:now it is on top 
        if(!bStayTop) 
        { 
            SetWindowPos(hWindow,HWND_NOTOPMOST,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,SWP_NOSIZE|SWP_NOMOVE); 
        } 
         
        DEBUG_ENTERED("ENTER ENDING") 
        return TRUE; 
    } 


摘自 sryan的專欄

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved