#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;
}
}
本文介绍了一个简单的Windows应用程序功能,该功能可以使指定的窗口产生震动效果。通过调整几个参数,如延迟时间、震动次数和跨度,可以定制震动的效果。文章详细展示了如何获取窗口信息、检查窗口有效性,并使用MoveWindow函数来实现窗口位置的变化。
1万+

被折叠的 条评论
为什么被折叠?



