09. april 2001 - 17:04
Der er
3 kommentarer og
2 løsninger
minimeret app. i taskbarens statusområde
Hvordan laver man en applikation der kører minimeret, med en lille ikon i taskbarens statusområde a.la. lydstyrke, skærmopløsning og winamp. Det skal være sådan at når men trykker på ikonet (kommer System Menuen frem?) kan man maksimere vinduet.
På forhånd tak.
09. april 2001 - 17:07
#1
du kan gøre det sådan her:
unit unit1;
interface
uses Windows, Classes, Forms, Messages, Controls, ShellAPI, Menus, SysUtils;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
MainMenu1: TMainMenu;
procedure FormCreate(Sender: TObject);
procedure WndProc(var Message: TMessage); override;
procedure Showform1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
IconNotifyData : TNotifyIconData;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
// Catch the Minimize event before the application
procedure TForm1.WndProc(var Message: TMessage);
var
p : TPoint;
begin
case Message.Msg of
WM_SYSCOMMAND:
case Message.WParam and $FFF0 of
SC_MINIMIZE: begin
// Hide the Mainform
Hide;
// Bail out here, so the Application dont starts to show the form
Exit;
end;
SC_RESTORE: ;
end;
WM_USER + 1:
case Message.lParam of
WM_RBUTTONDOWN: begin
GetCursorPos(p);
PopupMenu1.Popup(p.x, p.y);
end;
WM_LBUTTONDOWN: begin
Show;
end;
end;
end;
inherited ;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//Now set up the IconNotifyData structure so that it receives//the window messages sent to the application and displays
//the application\'s tips
with IconNotifyData do begin
hIcon := Application.Icon.Handle;
uCallbackMessage := WM_USER + 1;
cbSize := sizeof(IconNotifyData);
Wnd := Handle;
uID := 100;
uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
end;
//Add the Icon to the system tray and use the
//the structure and its values
Shell_NotifyIcon(NIM_ADD, @IconNotifyData);
// Hide MainForm at startup.
//(Remove if application is to be shown at startup)
Application.ShowMainForm := False;
// Toolwindows dont have a TaskIcon.
//(Remove if TaskIcon is to be show when form is visible)
SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
end;
// Shows the form when user click on TrayIcon
procedure TForm1.Showform1Click(Sender: TObject);
begin
// Show the Mainform.
Show;
// Put the form in top of all others.
SetForegroundWindow(Self.handle);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @IconNotifyData);
end;
end.