实现 MSN QQ窗口抖动

本文介绍了通过调整窗口位置和大小实现类似MSN和QQ的窗口动态效果,包括使用PlaySound函数播放声音和自定义窗口位置移动逻辑。同时提供了一个控制台版本的实现,通过窗口抖动来展示动态效果。

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值