How to flash entire screen in C#?
It takes some time for my program to finish computation, so I would like开发者_JAVA技巧 to run it, read some web pages meanwhile, and when the screen flashes (notification of finished computation), I would get back to my program.
The only missing part is -- how to flash entire screen in C#? I use WPF if this matters.
Please note -- my program is not visible, the other program (web browser for example) takes entire screen (that is the point of the problem, because otherwise, I wouldn't need any notification at all).
Flash = blink.
my first approach would be: on completion of the computation have your program open a new topmost window with transparent background and set it to some color (white) for some brief intervals and close the window again. mind you, while the window is on top you'll not be able to interact with underlying windows during the flashing because the window will eat those events. Alternatively, you could do what most other windows applications (like outlook or messenger) do: display a brief notification box that is clickable to get you to the associated application (your program).
i think a more 'normal' practice would be to install the app as a sys tray icon - then you can change that upon any status change.
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern Int16 FlashWindowEx(ref FLASHWINFO pwfi);
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct FLASHWINFO {
public UInt32 cbSize;
public IntPtr hwnd;
public UInt32 dwFlags;
public UInt32 uCount;
public UInt32 dwTimeout;
}
public const UInt32 FLASHW_STOP = 0;
public const UInt32 FLASHW_CAPTION = 1;
public const UInt32 FLASHW_TRAY = 2;
public const UInt32 FLASHW_ALL = 3;
public void Flash() {
FLASHWINFO flashInfo = new FLASHWINFO();
flashInfo.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(flashInfo);
flashInfo.hwnd = this.Handle; // get the window handle
flashInfo.dwFlags = FLASHW_TIMERNOFG | FLASHW_ALL;
flashInfo.uCount = UInt32.MaxValue;
flashInfo.dwTimeout = 0;
FlashWindowEx(ref flashInfo);
}
I don't think that you can technically flash your screen with WPF. Maybe with a Win32 function. But would it be a possibility to make a screenshot and show a Windows that shows a modified version of that screenshot? This window would have to be declared as TopMost and cover your screen and your image could be modified by increasing the alpha channel over the time.
Edit: OK, I think I misunderstood "flash". If you just want to show a flashing rectangle with one color have a look at the thread which Mamta Dalal posted.
精彩评论