How to create a simple taskbar application

Source: Internet
Author: User

Windows 95 and Windows NT 4.0 contain an exciting feature: the taskbar. This area, usually on the right side of the area task bar, can contain small icons that can lead to large applications or menus. This article mainly discusses how to use Delphi to establish such an application.

Before you begin, look at the interface requirements for the following:

Technically, a taskbar application is very much like a normal application, it has a message loop, and the corresponding Windows message completes the function.

Procedure RunTrayApplication;
Var Msg : TMsg;
Begin
CreateWindow;
AddTrayIcon;
While GetMessage(Msg,0,0,0) do Begin
TranslateMessage(Msg);
DispatchMessage(Msg);
End;
DeleteTrayIcon;
End;

As you can see: All that needs to be done is create a window, register an icon to the taskbar, set its message loop, and finally close it. Of course, there must be additional code to complete the corresponding function, however, it is really no need to worry.

Let's start with the creation of the window. In fact, this window is not a window that can be seen on the taskbar. Accordingly, this window only handles the work of the message loop and other parent classes. The Task window (Windows & NT) handles create messages (such as mouse clicks, and so on) and send messages to our windows.

Procedure CreateWindow;
Var
WC : TWndClass;
W : hWnd;
Begin
With WC do Begin
Style := 0;
lpfnWndProc := @WndProc;
cbClsExtra := 0;
cbWndExtra := 0;
hIcon := 0;
hCursor := 0;
hbrBackground := 0;
lpszMenuName := nil;
lpszClassName := MyTrayIconClass;
hInstance := System.hInstance;
end;
RegisterClass(WC);
W := Windows.CreateWindow(MyTrayIconClass,MyVeryOwnTrayIconWindow,
ws_OverlappedWindow,0,0,0,0,0,0,hInstance,nil);
ShowWindow(W,sw_Hide);
UpdateWindow(W);
MainWindow := W;
End;

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.