从批处理文件触发任务栏按钮闪烁? [英] Triggering taskbar button flash from batch file?
问题描述
是否有可能触发Windows的闪烁任务栏按钮X次,或直至窗口来到前台从一个批处理文件的行为?我想打电话给用户注意完成后长时间运行脚本。
使用外部程序触发闪烁是好的,只要它不需要安装(即可执行文件可以用我的剧本被捆绑)。
更新
下面就是我结束了(Andreas的德尔福code的最低限度的端口)。它似乎只依赖于KERNEL32.DLL和USER32.DLL我的MinGW下编译,所以应该是高度可移植的。
闪烁三次,然后保持突出显示,直到被推上前台。
的#define WINVER 0x501
#定义_WIN32_WINNT 0x501#包括LT&;&WINDOWS.H GT;无效的主要(INT ARGC,字符** argv的){
FLASHWINFO信息= {sizeof的(信息),GetConsoleWindow(),FLASHW_TIMERNOFG | FLASHW_TRAY,3,0}; FlashWindowEx(安培;信息);
}
这是很容易用一个非常简单的外部* .EXE做。它只是调用 FlashWindowEx 的功能Windows API的。
这是一个简单的德尔福控制台应用程序:
程序flashwnd;{$ APPTYPE CONSOLE}用途
SysUtils单元时,Windows;VAR
OldTitle,UniqueTitle:字符串;
H:HWND;
C:基数;
FWI:TFlashWInfo;开始 尝试
//我们需要一个独特的称号
SetLength函数(OldTitle,1024);
GetConsoleTitle(PChar类型(OldTitle),1024);
UniqueTitle:='RAND'+ IntToStr(GetTickCount的);
SetConsoleTitle(PChar类型(UniqueTitle));
睡眠(50);
H:= FindWindow函数(零,PChar类型(UniqueTitle));
SetConsoleTitle(PChar类型(OldTitle)); C:= 10;
如果ParamCount = 1,则
C:= StrToInt(ParamStr这(1)); FillChar(FWI,sizeof的(FWI),0);
fwi.cbSize:= sizeof的(FWI);
fwi.hwnd:= H;
fwi.dwFlags:= FLASHW_ALL;
fwi.uCount:= C;
fwi.dwTimeout:= 0;
FlashWindowEx(FWI);
除
在E:异常做
Writeln(E.ClassName +:+ E.Message);
结束;
结束。
只需调用它像
flashwnd
闪烁当前控制台窗口十倍。呼叫
flashwnd 27
闪烁窗口27倍。
Is it possible to trigger Windows' "flash the task bar button X times or until the window comes to the foreground" behavior from a batch file? I'm trying to call the user's attention to a long-running script upon completion.
Using an external program to trigger the flashing is fine, as long as it doesn't require an install (i.e. the executable can be bundled with my scripts).
Update
Here's what I ended up with (a minimalist port of Andreas' Delphi code). I've compiled it under MinGW at it appears to be dependent only on KERNEL32.DLL and USER32.DLL, so should be highly portable.
Flashes three times, then stays highlighted until brought to the foreground.
#define WINVER 0x501
#define _WIN32_WINNT 0x501
#include <windows.h>
void main(int argc, char **argv) {
FLASHWINFO info = { sizeof(info), GetConsoleWindow(), FLASHW_TIMERNOFG | FLASHW_TRAY, 3, 0 };
FlashWindowEx(&info);
}
It is very easy to do using a very simple external *.exe. It simply has to call the FlashWindowEx function of the Windows API.
This is a sample Delphi console application:
program flashwnd;
{$APPTYPE CONSOLE}
uses
SysUtils, Windows;
var
OldTitle, UniqueTitle: string;
h: HWND;
c: cardinal;
fwi: TFlashWInfo;
begin
try
// We need a unique title
SetLength(OldTitle, 1024);
GetConsoleTitle(PChar(OldTitle), 1024);
UniqueTitle := 'RAND' + IntToStr(GetTickCount);
SetConsoleTitle(PChar(UniqueTitle));
sleep(50);
h := FindWindow(nil, PChar(UniqueTitle));
SetConsoleTitle(PChar(OldTitle));
c := 10;
if ParamCount = 1 then
c := StrToInt(ParamStr(1));
FillChar(fwi, sizeof(fwi), 0);
fwi.cbSize := sizeof(fwi);
fwi.hwnd := h;
fwi.dwFlags := FLASHW_ALL;
fwi.uCount := c;
fwi.dwTimeout := 0;
FlashWindowEx(fwi);
except
on E: Exception do
Writeln(E.ClassName + ': ' + E.Message);
end;
end.
Simply call it like
flashwnd
to flash the current console window ten times. Call
flashwnd 27
to flash the window 27 times.
这篇关于从批处理文件触发任务栏按钮闪烁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!