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;