现在的位置: 首页 > 自动控制 > 工业·编程 > 正文

实现 MSN QQ窗口抖动

2012-09-10 11:46 工业·编程 ⁄ 共 2505字 ⁄ 字号 暂无评论

void CWindouDlg::OnButton1() 
{
// TODO: Add your control notification handler code here

PlaySound(MAKEINTRESOURCE(IDR_WAVE1),AfxGetResourceHandle(),SND_ASYNC|
    SND_RESOURCE|SND_NODEFAULT);//使用PlaySound需要包含头文件Header: Declared in mmsystem.h.
                                //Import Library: Use winmm.lib.
int ty=7;
CRect   m_rect;   
GetWindowRect(&m_rect);  
for(int i=0;i<70;i++)
{
SetWindowPos( NULL,m_rect.left,m_rect.top,0,0,SWP_NOSIZE );
  m_rect.top = m_rect.top + ty;  
  m_rect.left = m_rect.left - ty;
  SetWindowPos( NULL,m_rect.left,m_rect.top,0,0,SWP_NOSIZE );
  m_rect.top = m_rect.top - ty;  
  m_rect.left = m_rect.left + ty;
  SetWindowPos( NULL,m_rect.left,m_rect.top,0,0,SWP_NOSIZE );
  m_rect.top = m_rect.top - ty;  
  m_rect.left = m_rect.left + ty;
  SetWindowPos( NULL,m_rect.left,m_rect.top,0,0,SWP_NOSIZE );
  m_rect.top = m_rect.top + ty;  
  m_rect.left = m_rect.left - ty;
  SetWindowPos( NULL,m_rect.left,m_rect.top,0,0,SWP_NOSIZE );
}
}

吃饭的时候又想了想回来又弄了一下,比上午弄的那个更像MSN 和QQ了 嘿嘿 代码差不多

int ty=5;
CRect   m_rect;   
GetWindowRect(&m_rect);  
int recordy=m_rect.left;
int recordx=m_rect.top;

for(int i=0;i<3;i++)
{
    m_rect.left=recordy;
    m_rect.top=recordx;
    m_rect.top = m_rect.top + ty;  
    m_rect.left = m_rect.left - ty;
    SetWindowPos( NULL,m_rect.left,m_rect.top,0,0,SWP_NOSIZE );Sleep(35);
    m_rect.top = m_rect.top -ty;
    SetWindowPos( NULL,m_rect.left,m_rect.top,0,0,SWP_NOSIZE );Sleep(35);
    m_rect.top = m_rect.top -2*ty;
    SetWindowPos( NULL,m_rect.left,m_rect.top,0,0,SWP_NOSIZE );Sleep(35);
    m_rect.left=m_rect.left+ty;
    SetWindowPos( NULL,m_rect.left,m_rect.top,0,0,SWP_NOSIZE );Sleep(35);
    m_rect.left=m_rect.left+2*ty;
    SetWindowPos( NULL,m_rect.left,m_rect.top,0,0,SWP_NOSIZE );Sleep(35);
    m_rect.top = m_rect.top + ty;  
    SetWindowPos( NULL,m_rect.left,m_rect.top,0,0,SWP_NOSIZE );Sleep(35);
    m_rect.top=m_rect.top+2*ty;
    SetWindowPos( NULL,m_rect.left,m_rect.top,0,0,SWP_NOSIZE );
    SetWindowPos( NULL,recordy,recordx,0,0,SWP_NOSIZE );
    Sleep(35);
  }

控制台版本:

#include <windows.h>
int main()
{
HWND hTopWnd;
RECT rect;
int cxWidth, cyHeight, iIdx;
//隐藏自身,即控制台本身,如不隐藏只抖动控制台.
ShowWindow(GetForegroundWindow(), SW_HIDE);
//休眠
Sleep(1000);
//获取Z次序顶端窗口句柄
hTopWnd = GetForegroundWindow();
GetWindowRect(hTopWnd, &rect);
//获取窗口的宽高
cxWidth = rect.right - rect.left;
cyHeight = rect.bottom - rect.top;
//抖动窗体
for(iIdx = 0; iIdx <= 5000; iIdx += 100)
{
MoveWindow(hTopWnd, rect.left - 5, rect.top, cxWidth, cyHeight, TRUE);
Sleep(50);
MoveWindow(hTopWnd, rect.left - 5, rect.top + 5, cxWidth, cyHeight, TRUE);
Sleep(50);
MoveWindow(hTopWnd, rect.left, rect.top + 5, cxWidth, cyHeight, TRUE);
Sleep(50);
MoveWindow(hTopWnd, rect.left, rect.top, cxWidth, cyHeight, TRUE);
Sleep(50);
}
return 0;
}

给我留言

留言无头像?