关于Windows:当新消息到达时,如何使任务栏像Messenger一样闪烁我的应用程序?

关于Windows:当新消息到达时,如何使任务栏像Messenger一样闪烁我的应用程序?

How to make the taskbar blink my application like Messenger does when a new message arrive?

当与我聊天的人做出响应时,.NET中是否存在API调用或本机DLL,可用来创建与Windows Live Messenger类似的行为?


FlashWindowEx是必经之路。 请参阅此处以获取MSDN文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool FlashWindowEx(ref FLASHWINFO pwfi);

[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
    public UInt32 cbSize;
    public IntPtr hwnd;
    public UInt32 dwFlags;
    public UInt32 uCount;
    public UInt32 dwTimeout;
}

public const UInt32 FLASHW_ALL = 3;

调用函数:

1
2
3
4
5
6
7
8
9
FLASHWINFO fInfo = new FLASHWINFO();

fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
fInfo.hwnd = hWnd;
fInfo.dwFlags = FLASHW_ALL;
fInfo.uCount = UInt32.MaxValue;
fInfo.dwTimeout = 0;

FlashWindowEx(ref fInfo);

这是从Pinvoke.net无耻地插入的


1
2
3
4
5
6
7
8
9
HWND hHandle = FindWindow(NULL,"YourApplicationName");
FLASHWINFO pf;
pf.cbSize = sizeof(FLASHWINFO);
pf.hwnd = hHandle;
pf.dwFlags = FLASHW_TIMER|FLASHW_TRAY; // (or FLASHW_ALL to flash and if it is not minimized)
pf.uCount = 8;
pf.dwTimeout = 75;

FlashWindowEx(&pf);

被专家交流成员gtokas窃取。

FlashWindowEx。


从Raymond Chen博客条目中:

How do I flash my window caption and taskbar button manually?

How do I flash my window caption and
taskbar button manually? Commenter
Jonathan Scheepers wonders about those
programs that flash their taskbar
button indefinitely, overriding the
default flash count set by
SysteParametersInfo(SPI_SETFOREGROUNDFLASHCOUNT).

The FlashWindowEx function and its
simpler precursor FlashWindow let a
program flash its window caption and
taskbar button manually. The window
manager flashes the caption
automatically (and Explorer follows
the caption by flashing the taskbar
button) if a program calls
SetForegroundWindow when it doesn't
have permission to take foreground,
and it is that automatic flashing that
the SPI_SETFOREGROUNDFLASHCOUNT
setting controls.

For illustration purposes, I'll
demonstrate flashing the caption
manually. This is generally speaking
not recommended, but since you asked,
I'll show you how. And then promise
you won't do it.

Start with the scratch program and
make this simple change:

1
2
3
4
5
6
7
8
9
void
OnSize(HWND hwnd, UINT state, int cx, int cy)
{
  if (state == SIZE_MINIMIZED) {
    FLASHWINFO fwi = { sizeof(fwi), hwnd,
                       FLASHW_TIMERNOFG | FLASHW_ALL };
    FlashWindowEx(&fwi);
  }
}

Compile and run this program, then
minimize it. When you do, its taskbar
button flashes indefinitely until you
click on it. The program responds to
being minimzed by calling the
FlashWindowEx function asking for
everything possible (currently the
caption and taskbar button) to be
flashed until the window comes to the
foreground.

Other members of the FLASHWINFO
structure let you customize the
flashing behavior further, such as
controlling the flash frequency and
the number of flashes. and if you
really want to take control, you can
use FLASHW_ALL and FLASHW_STOP to turn
your caption and taskbar button on and
off exactly the way you want it. (Who
knows, maybe you want to send a
message in Morse code.)

Published Monday, May 12, 2008 7:00 AM
by oldnewthing Filed under: Code


FlashWindowEx Win32 API是用于执行此操作的调用。 其文档位于:
http://msdn.microsoft.com/zh-CN/library/ms679347(VS.85).aspx


我相信您正在寻找SetForegroundWindow


推荐阅读

    linux外部命令调用?

    linux外部命令调用?,系统,软件,标准,命令,盘中,管理,外部,进程,程序,内存,lin

    linux怎么调用命令行?

    linux怎么调用命令行?,系统,地址,工具,工作,首页,终端,命令,密码,信息,情况,l

    浏览器调用linux命令?

    浏览器调用linux命令?,系统,信息,人工智能,软件,数据,首次,地址,代码,咨询,

    py调用linux的命令?

    py调用linux的命令?,系统,代码,状态,环境,标准,工具,命令,文件,脚本,终端,lin

    浏览器调用linux命令?

    浏览器调用linux命令?,系统,信息,人工智能,软件,数据,首次,地址,代码,咨询,

    py调用linux的命令?

    py调用linux的命令?,系统,代码,状态,环境,标准,工具,命令,文件,脚本,终端,lin

    linux系统命令调用?

    linux系统命令调用?,系统,单位,工具,工作,管理,地址,权威,密码,电脑,信息,怎

    linux调用上一条命令?

    linux调用上一条命令?,系统,命令,一致,数字,名称,网上,电脑,目录,空格,终端,l

    linux命令行调用程序?

    linux命令行调用程序?,工具,环境,代码,初级,工程,系统,网上,服务,管理,发行,l

    脚本调用linux命令?

    脚本调用linux命令?,代码,系统,工作,底部,脚本,位置,环境,行用,官网,标准,typ

    调用函数命令linux?

    调用函数命令linux?,系统,管理,网络,通用,统一,观察,地址,代码,设备,地方,怎

    linux内核总调用命令?

    linux内核总调用命令?,工作,地址,系统,信息,管理,策略,命令,目录,时间,基础,

    linux编程调用命令?

    linux编程调用命令?,系统,标准,管理,工作,基础知识,情况,环境,设备,基础,首

    linux命令窗口调用?

    linux命令窗口调用?,系统,工具,首页,终端,命令,数据,盘中,代码,密码,快捷键,

    linux服务器调用命令?

    linux服务器调用命令?,系统,地址,设备,标准,工作,密码,中心,盘中,网络,软件,

    linuxc调用命令框?

    linuxc调用命令框?,系统,工作,标准,情况,设备,环境,命令,函数,语言,程序,如何

    linux系统调用命令行?

    linux系统调用命令行?,系统,网络,代码,密码,位置,工作,通用,平台,电脑,环境,

    批量调用linux命令?

    批量调用linux命令?,工具,下来,软件,系统,密码,地址,时间,认证,向日葵,文件,l

    linux命令使网卡闪烁?

    linux命令使网卡闪烁?,网络,系统,地址,设备,服务,信息,状态,名称,名字,网卡,

    linux内核调用命令?

    linux内核调用命令?,系统,工作,信息,工具,内核,命令,名称,标准,流程,网络,在l