Implement the task bar icon cartridge effect with C ++ Builder

zhaozj2021-02-08  220

Home: http://www.maxss.net email: maxchou@163.com

The Windows platform provides a lot of feature features for the app, the task chart is a very practical and classic. It not only saves the space of the taskbar, but also the information of the program's current state, etc., but also the current state of the program. There is no support for the task bar icon animation effect in Windows, so you have to implement it yourself. In this article, you can see one of the methods of achieving the task bar icon animation. First, you must learn about the knowledge about the taskbar icon programming, to achieve the control of the taskbar icon is mainly through the shell_notifyicon () function. The API declaration of this function is as follows:

Bool shell_notifyicon

DWORD DWMESSAGE,

PNOTIFYICONDATA LPDATA

);

The parameter dwMessage is specified for what action, optional value is: NIM_ADD, NIM_DELETE, NIM_MODIFY, NIM_SETFOCUS, NIM_SETVERSION, representation as: Add, Remove, Modify, Get Focus, Settings Version, for NIM_SETFOCUS, NIM_SETVERSION is generally less used We are most commonly used by NIM_ADD, NIM_DELETE, NIM_MODIFY.

Another parameter LPDATA is a

NOTIFYICONDATA structure pointer, this structure is more content, as follows:

Typedef struct _notifyicondata {

DWORD CBSIZE;

Hwnd hwnd;

UINT UID;

UINT UFLAGS;

Uint ucallbackmessage;

Hicon Hicon;

#if (_WIN32_IE <0x0500)

TCHAR SZTIP [64];

#ELSE

TCHAR SZTIP [128];

#ENDIF

#if (_WIN32_IE> = 0x0500)

DWORD DWSTATE;

DWORD DWSTATEMASK;

Tchar Szinfo [256];

Union {

Uint utimeout;

Uint Uversion;

} DummyunionName;

Tchar szinfotitle [64];

DWORD DWINFOFLAGS;

#ENDIF

#if (_WIN32_IE> = 0x600)

Guid GuidItem;

#ENDIF

Notifyicondata, * PNOTIFYICIONDATA;

Here we mainly pay attention to members of the bold above

CBSIZE,

HWnd,

UID,

UFLAGS,

UcallbackMessage,

Hicon,

The content and usage of SZTIP et al. The representative it means: structural size, window handle, icon identification, callback function, content flag, icon handle, text prompt.

We want to define your own notification messages and icon identification, the content is as follows: (these contents are defined in the form of the form)

Const int WM_NC_NOTIFY = (WM_USER 1); // Custom Notification Message

Const int WM_NC_TRAYID = (WM_USER 2); // Custom Icon Identifier

Under normal circumstances, it is a small icon in the taskbar after the user minimizes the application, so we must also capture system messages.

WM_SYSCOMMAND The wparam parameter is minimized, and then processes the process. In addition, the most important thing is to capture custom notification messages WM_NC_NOTIFY, these contents are defined as follows: (Definition in the form class) Begin_MESSAGE_MAP

VCL_MESSAGE_HANDLER (WM_SYSCOMMAND, TMESSAGE, WMSYSCOMMAND);

VCL_MESSAGE_HANDLER (WM_NC_NOTIFY, TMESSAGE, WMNCNOTIFY)

END_MESSAGE_MAP (TFORM)

In order to achieve animation, we need to have an ImageList and Timer objects. The icon of each frame is stored in ImageList, and Timer is a constant change.

The icon handle in the NOTIFYICONDATA structure is realized. It mainly creates several functional functions, namely add icon addTrayicon (), modify the icon modifytrayicon (), and delete the icon deleTrayicon ().

As for the implementation details of the specific function, you can not fill the pen, everyone can

Download the taskbar icon animation sample source code for viewing, which is compiled under BCB6 Windows 2000. Welcome to exchange!

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

New Post(0)