How flashing application button on the taskbar author: Chris Bray (Chris Bray) Translation: Huang Lei (visli)
How to cause the user's attention by flashing the application window or taskbar button (or both flash)?
If the application you created is on a Windows 98 or later operating system, you can implement it by calling the API function FlashWindowEx and assigns a FlashWinfo structure. If it is running on Windows 95, it is more troublesome, but You can also implement the desired effect by using a TIMER component. FlashWindowEx When you call an API function FlashWindowEx, a TFLashWinfo is used to control the information of Windows to implement the flash function. Fortunately, Delphi has encapsulated the structure for you. It is declared as follows: TYPE
Tflashwinfo = Record
CBSIZE: Longint;
HWND: longint;
DWFLAGS: longint;
Ucount: longint;
Dwtimeout: longint;
END; all things you need are just filling and assembled the record type and call the API function. In this example, I put the two in the onclick event of a button, of course, you can also place them to any suitable place: procedure tform1.button1click (sender: TOBJECT);
VAR
Fwinfo: Tflashwinfo;
Begin
FwInfo.cbsize: = 20;
Fwinfo.hwnd: = Application.Handle; // Blinking the handle of the window
Fwinfo.dwflags: = flasew_all;
Fwinfo.ucount: = 10; // Flashing
Fwinfo.dwtimeout: = 0; // Speed in milliseconds, 0 defaults to flashing with the pointer flashingEx (fwinfo); // make it flash!
End; dwflags Indicates the flicker, the following is the value definition of the dwflags attribute: flashw_stop = 0 // Stop flashing
Flashw_caption = 1 // Flash window title
Flashw_tray = 2 // Flashing Task Bar Button
Flashw_all = 3 // Flash window title and taskbar button Flashw_timer = 4 // Stop flashing until Flashw_Stop flag setting
Flashw_timernofg = 5 // Stopping until the window is only valid on the Windows 98 or higher operating system, if you want to implement on Windows 95, you need to take another different way: FlashWindow Windows 95 (and Delphi 3 and more versions) require different ways. There is no FlashWindowEx this API function under this operating system, you need to use FlashWindow instead. (FlashWindow can also be at lower version operating system The problem is called.) But the problem is that FlashWindow can only flash once, so the purpose of the flash button is required to use a Timer component. Of course, in this way, it has increased valuable system resource overhead - but it can complete the results we want. In order to achieve this example, you will need to create a Form and put a Timer component and a button component. After selecting the Timer component and double-click, the ONTIMER event will be created. The following code is added: Procedure TFORM1.TIMER1TIMER (Sender: TOBJECT); Begin
FlashWindow (Application.handle, True);
End; Next, you need to start flashing. This step is very simple, setting the timeton's enabled property in the Button's OnClick event is TURE. In this example I use Button's event to switch the flashing of the flash: Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
Begin
Timer1.enabled: = not timer1.enable;
End; until this, two different methods have achieved the same functionality. CHRIS BRAY / VERTICAL SOFTWARE 2002
Updating this example is still a few minutes, Simon Clayton proposes a glittering method - only when the application is not a current activity. Simon reordering as follows: I did this: procedure tform1.timer1timer (sender: TOBJECT);
Begin
IF (GetForegroundWindow () <> form1.handle) THEN
Begin
FwInfo.cbsize: = 20;
Fwinfo.hwnd: = Application.handle;
Fwinfo.dwflags: = flasew_all;
Fwinfo.ucount: = 5;
FwInfo.dwtimeout: = 0;
Flashing: = true;
FlashWindowEx (FWInfo);
end
Else if (flashing) THEN
Begin
FwInfo.cbsize: = 20;
Fwinfo.hwnd: = Application.handle;
Fwinfo.dwflags: = flasew_stop;
Fwinfo.ucount: = 0;
FwInfo.dwtimeout: = 0;
FlashWindowEx (FWInfo);
Flashing: = false;
END;
End; I also added some stop flashing code in Form's onpaint event: Procedure TFORM1.FormPaint (Sender: TOBJECT);
Begin
IF (Flashing) THEN
Begin
FwInfo.cbsize: = 20;
Fwinfo.hwnd: = Application.handle;
Fwinfo.dwflags: = flasew_stop; fwinfo.ucount: = 0;
FwInfo.dwtimeout: = 0;
FlashWindowEx (FWInfo);
END;
END; the only question I have to solve now is that if I use an application in my second monitor, the form is on the top of my first monitor, then when I switch back to the application, the onpaint event seems to be Did not be called. That is to say that it is all going - I noticed that this should be a problem with MS real-time messages. Dry, Simon - very good skill!