Hi Michael,
Thank you for posting.
My answers to your two questions are in the below.
(1) In order to use your custom icon in a winform, you should set the icon
property of each winform to your custom icon separately. There isn't a
global property for a winform project to set winform icon to your custom
icon.
(2) There're two WinAPI functions you can use to enable a Taskbar item
flash when requesting user attention. They are GetForgroundWindow and
FlashWindow.
The GetForegroundWindow function returns the handle to the foreground
window ¡ª the window with which the user is currently working.And the
FlashWindow function flashes the specified window one time. It does not
change the active state of the window.
The syntax of GetForegroundWindow function is:
HWND GetForegroundWindow(VOID);
The return value is a handle to the foreground window.
And the syntax of FlashWindow function is:
BOOL FlashWindow( HWND hWnd, BOOL bInvert);
Parameters:
hWnd
Handle to the window to be flashed. The window can be either open or
minimized.
bInvert
If this parameter is TRUE, the window is flashed from one state to the
other. If it is FALSE, the window is returned to its original state (either
active or inactive).
Return Values:
The return value specifies the window's state before the call to the
FlashWindow function. If the window caption was drawn as active before the
call, the return value is nonzero. Otherwise, the return value is zero.
Since the specified window flashes only once using FlashWindow function,
you should call this function in a timer's tick event handling method in
the specified window.
The following is a sample.
// state the two API functions in Class1
public class Class1
{
[DllImport("user32.dll")]
public extern static bool FlashWindow(IntPtr hwnd,bool bInvert);
[DllImport("user32.dll")]
public extern static IntPtr GetForegroundWindow();
}
public class Form1
{
private System.Windows.Forms.Timer timer1;
public Form1()
{
this.timer1 = new
System.Windows.Forms.Timer(this.components);
this.timer1.Interval = 1000;
this.timer1.Tick += new
System.EventHandler(this.timer1_Tick);
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.timer1.Start();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
IntPtr foregroundWin = Class1.GetForegroundWindow();
// if the current foreground window isn't
this window, flash this window in task bar once every 1 second
if (foregroundWin != this.Handle)
{
Class1.FlashWindow(this.Handle,true);
}
// if this window is the current foreground
window, stop the timer and don't flash this window any more
else
{
this.timer1.Stop();
}
}
}
I hope this is helpful to you.
If you have any other concerns or need anything else, please don't hesitate
to tell me.
Sincerely,
Linda Liu
Microsoft Online Community Support
====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================