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


 

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


 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值