Tray Icon _ Implementation Method _ Minimized to Tray _ close to pallet _delphi_ Pallet Summary

Source: Internet
Author: User

Tray Icon _ Implementation Method _ Minimized to Tray _ close to pallet _delphi_ Pallet Summary

Transferred from: http://midasyang.blog.163.com/blog/static/189744104201141245344681/

start does not show main form
If it is implemented by Form1.visible:=false, the main form will appear flashing. A better approach is to add application.showmainform to the OnShow event: = False;

The program does not show up on the taskbar
Procedure Tform1.formshow (Sender:tobject);
Begin
ShowWindow (Application.handle,sw_hide);
End

Click the Close button to the tray
Procedure Tform1.formclosequery (Sender:tobject; var canclose:boolean);
Begin
Canclose: = False;
Self.hide;
End
But here's the problem, when you use the Shut down or restart system in the Start menu, the system never shuts down or restarts due to the existence of the program, and then returns to the desktop. The solution is as follows:
Declaring the process of intercepting wm_queryendsession messages
Procedure Wmqueryendsession (var msg:tmessage); Message wm_queryendsession;

Procedure Tform1.wmqueryendsession (var msg:tmessage);
Begin
Msg.result: = 1;
End
It is tested that the OnClose event is not performed when the system shuts down, but the OnDestroy event is executed. Another raize pallet control Rztrayicon has queryendsession (sender:tobject;
var allowsessiontoend:boolean); event, put Allowsessiontoend to be true also.

Minimized to Pallet
Procedure Wmsyscommand (var msg:twmsyscommand); Message Wm_syscommand;

Procedure Tform1.wmsyscommand (var msg:twmsyscommand);
Begin
If Msg.cmdtype = Sc_minimize Then
Self.close
Else
inherited;
End


animations when maximizing and minimizing
Type
Tzoomaction = (zaminimize, zamaximize);

Procedure Zoomeffect (aform:tform; Aoperation:tzoomaction);
Var
Rcstart, Rcend, Rctray:trect;
Hwndtray, Hwndchild:hwnd;
Begin
Find the location of the system tray area
Hwndtray: = FindWindow (' Shell_traywnd ', nil);
Hwndchild: = FindWindowEx (hwndtray, 0, ' Traynotifywnd ', nil);
GetWindowRect (Hwndchild, Rctray);
Click to maximize/minimize and toggle start/End
If aoperation = Zaminimize Then
Begin
Rcstart: = Aform.boundsrect;
Rcend: = Rctray;
End
ELSE begin
Rcend: = Aform.boundsrect;
Rcstart: = Rctray;
End
DrawAnimatedRects (Aform.handle, Idani_caption, Rcstart, rcend);
End
And then add them to the onclosequery separately.
Zoomeffect (self, zaminimize);
Add in OnShow
Zoomeffect (self, zamaximize);

Left click Tray to show or hide
Add in the left-click event of the Tray
If Self.showing Then
Self.close
ELSE begin
Self.show;
SetForegroundWindow (Application.handle);
End

whether the form is active
Procedure Wm_activateapp (var message:twmactivateapp); Message Wm_activateapp;

Procedure Tform1.wmactivateapp (var message:twmactivateapp);
Begin
is in the active form state message.active
End

whether the form minimizes state
If Isiconic (Self.handle) Then
ShowWindow (Self.handle, Sw_restore);

The program always appears on top
The simple approach is self.formstyle: = Fsstayontop; but flashes are preferable.
If not Showontop then
SetWindowPos (Self.handle, Hwnd_notopmost, 0,0,0,0, Swp_nomove + swp_nosize)//Normal window
Else
SetWindowPos (Self.handle, Hwnd_topmost, 0,0, 0,0, Swp_nomove + swp_nosize); The top


http://shuwen186.blog.163.com/blog/static/1642732020112973721371/

Tray Icon _ Implementation Method _ Minimized to Tray _ close to pallet _delphi_ Pallet Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.