VC 模拟QQ闪屏功能

1  用一个对话框加一个按钮完成:即点击按钮对话框类似QQ发闪屏晃动。 见练习程序51

主要就是用了

①CWnd::GetWindowRect

void    GetWindowRect(LPRECT   lpRect)    const;

取得窗口位置,尺寸。

eg.

CRect rect;

GetWindowRect(&rect);

②CWnd::SetWindowPos

BOOL   SetWindowPos(const   CWnd  *pWndInsertAfter, int  x, int  y, int  cx, int  cy,UINT  nFlags);

 

③定时器 

CWnd::SetTimer  //设置定时器

UINT    SetTimer(UINT   nIDEvent, UINT  nElapse, void (CALLBACKEXPORT*lpfnTimer)(HWND,UINT,UINT,DWORD));

如果第三个参数为NULL,则用WM_TIMER消息函数来响应定时器事件

 

CWnd::KillTimer  //取消定时器

BOOL   KillTimer(int  nIDEvent);

?

2  codes

 

//按此button设置定时器

void CMy51Dlg::OnButton1() 

{

// TODO: Add your control notification handler code here

const int elapse = 40;    //定时间隔

SetTimer(IDT_TIMER0, elapse, NULL);

}

 

 

//闪屏按照上左下右的顺序,重复三次

void CMy51Dlg::OnTimer(UINT nIDEvent) 

{

    if( IDT_TIMER0 == nIDEvent)

    { 

        const int xChange = 10;

        const int yChange = 10;  //对话框晃动幅度

        static int times = 0;         //记录次数

        CRect rect;  

        GetWindowRect(&rect);  //取得当前窗口在屏幕上的位置

 

        switch (times)

        {

        case 0:

        case 4:

        case 8:

        SetWindowPos(NULL, rect.left, rect.top - yChange, 0, 0, SWP_NOSIZE | SWP_NOZORDER); 

        times++; 

        break;

        case 1:

        case 5:

        case 9:

        SetWindowPos(NULL, rect.left - xChange, rect.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);

        times++; 

        break;

        case 2:

        case 6:

        case 10:

        SetWindowPos(NULL, rect.left, rect.top + yChange, 0, 0, SWP_NOSIZE | SWP_NOZORDER);

        times++; 

        break;

        case 3:

        case 7:

        case 11:

        SetWindowPos(NULL, rect.left + xChange, rect.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);

        times++; 

        break; 

        case 12:

        KillTimer(IDT_TIMER0);

        times = 0;

        break; 

        }   

     }

   CDialog::OnTimer(nIDEvent);

}


 

VC 模拟QQ闪屏功能 - 大灰狼 - 大灰狼 的博客?




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值