Shell

zhaozj2021-02-11  204

First define new constants:

Const

NIF_INFO = $ 10;

NIM_SETVERSION = $ 00000004;

Notifyicon_version = 3;

NIM_SETFOCUS = $ 00000003;

Niif_info = $ 00000001;

Niif_Warning = $ 00000002;

Niif_ERROR = $ 00000003;

NIN_BALLOONSHOW = WM_USER 2;

Nin_balloonhide = wm_user 3;

NIN_Balloontimeout = WM_USER 4;

NIN_BALLOONUSERCLICK = WM_USER 5;

Nin_select = WM_USER 0;

NINF_KEY = $ 1;

NIN_KEYSELECT = NIN_SELECT or NINF_KEY;

{The above column may not be complete, if it is not defined, you can find the platformsdk / include / shellapi.h in VC7 in VS.NET}

Available in a SYSTRAYICON back message:

TRAY_CALLBACK = WM_USER $ 7258;

Then define a new Notifyicondata structure (in Type):

Type

PNEWNOTIFYICONDATA = ^ TNEWNOTIFYICONDATA;

TDummyunionName = Record

Case Integer of

0: (utimeout: uint);

1: (Uversion: UINT);

END;

TNEWNOTICONDATA = Record

CBSIZE: DWORD;

Wnd: hwnd;

Uid: uint;

Uflags: uint;

UcallbackMessage: uint;

Hicon: Hicon;

Sztip: array [0..127] of char; // version 5.0 is 128, formerly 64

DWState: dWord; // Version 5.0

DwStatemask: DWORD; // Version 5.0

Szinfo: array [0..255] of char; // version 5.0

Dummyunionname: TDummyunionName;

Szinfotitle: array [0..63] of char; // version 5.0

DWINFOFLAGS: DWORD; // Version 5.0

END;

Declare a global variable:

VAR

Icondata: TNEWNOTIFYICONDATA;

Then transfer to the topic, the following process is used to add SYSTRAYICON:

PROCEDURE ADDSYSTRAYICON;

Begin

IconData.cbsize: = sizeof (icondata);

ICondata.Wnd: = allocatehwnd (Systrayiconmsghandler); //self.handle; {systrayiconmsghandler is the message processing process defined later.

Icondata.uid: = 0;

IconData.uflags: = nif_icon or nif_message or nif_tip;

IconData.ucallbackMessage: = tray_callback; // Custom Rehabilitation Message

ICondata.hicon: = image1.picture.icon.handle; // This is an icon of Handleicondata.sztip: = 'please send me email.';

IF not shell_notifyicon (nim_add, @icondata) THEN

ShowMessage ('add fail');

END;

There is another process to display Balloon Tips:

Procedure ShowballoontIps;

VAR

Tipinfo, TIPTITLE: STRING

Begin

IconData.cbsize: = sizeof (icondata);

IconData.uflags: = nif_info;

Tipinfo: = 'please send me email.';

Strplcopy (icondata.szinfo, Tipinfo, Sizeof (IconData.Szinfo) - 1);

IconData.dummyunionName.utimeout: = 3000;

TIPTITE: =

'Happyjoe@21cn.com';

Strplcopy (iconder.szinfotitle, tiptitle, sizeof (icondata.szinfotitle) - 1);

Icondata.dwinfoflags: = niif_info; // niif_error; // niif_warning;

Shell_Notifyicon (Nim_Modify, @icondata);

// The following code is actually useless, you can remove it (at least now)

IconData.dummyunionName.uversion: = notifyicon_version;

IF not shell_notifyicon (nim_setversion, @icondata) THEN

ShowMessage ('setversion fail');

END;

Don't forget to delete the process:

Procedure deletesystrayicon;

Begin

DeallocatehWnd (icondata.wnd);

IF not shell_notifyicon (nim_delete, @icondata) THEN

ShowMessage ('Delete Fail');

END;

There is also an important link --- message processing:

statement:

Procedure Systrayiconmsghandler (Var Msg: TMESSAGE); Message Tray_Callback;

definition:

Procedure Systrayiconmsghandler (Var Msg: TMessage);

Begin

Case msg.lparam of

WM_MOUSEMOVE:;

WM_LBUTTONDOWN:;

WM_LBUTTONUP:;

WM_LBUTTONDBLCLK:;

WM_RBUTTONDOWN:;

WM_RBUTTONUP:;

WM_RBUTTONDBLCLK:;

// The following is a new message

Nin_balloonshow: {Perform {when the Balloon TIPS pops up}

ShowMessage ('nin_balloonshow');

NIN_BALLOONHIDE: {When the Balloon TIPS disappears (for example, SYSTRAYICON is deleted), but the specified Timeout time or the mouse clicks on the disappearance of the balloon tips does not send this message} showMessage ('nin_balloonhide');

Nin_balloontimeout: {When the timeout time of the balloon tiPs is executed}

ShowMessage ('nin_balloontimeout');

NIN_BalloonUserClick: {Perform it when the mouse click on Balloon TIPS. Note: There is a closed button on the Balloon TIPS when XP is executed, and the balloon tips has been displayed (icholda.dummyunionName.utimeout: = 3000; this sentence is not used, my test is like this), if the mouse Point will receive a nin_balloontimeout message on the button. }

ShowMessage ('nin_balloonuserclick ";

END;

END;

Ok, the code is finished. I was also asked for a post to ask how to force the SYSTRAYICON TIPS. Now it seems to be executed as long as ShowballoontIPS (to assign the new domain in the structure, execute the NIM_MODIFY action). I don't know if I have answered my question. ^ _ ^

The new feature requires IE5.0 or above, I have passed the test under Win2000, XP Delphi 6.0. There is no 98 / me in the hand, I don't know if it can. (Finish)

转载请注明原文地址:https://www.9cbs.com/read-4409.html

New Post(0)