Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to iconise App.?

Posted on 1999-06-22
2
Medium Priority
?
149 Views
Last Modified: 2010-04-06
I would like my App. to load with Win. and
stay iconised waiting for a hot key or R.M.
click....How?
0
Comment
Question by:srbenavrbe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 1384098
To starts an app with windows put a shortcut in the StartUp menu or in the registry under:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

The hotkey kan be entered in a shortcut.


0
 
LVL 2

Accepted Solution

by:
CalvinDay earned 330 total points
ID: 1384099
Actually, you would do better to put the application in the system tray else you have to add a menu item to the system menu which can be done like this:

syshmenu:THandle;
syshmenu=GetSystemMenu(Handle,FALSE);
AppendMenu(syshmenu,MF_SEPARATOR,0,NULL);
AppendMenu(syshmenu,MF_ENABLED,100,'New Item');

You have to then use WM_SYSCOMMAND message.

To run when windows starts:

  with TRegIniFile.Create('') do
    begin
    RootKey:=HKEY_LOCAL_MACHINE;
    WriteString('Software\Microsoft\Windows\CurrentVersion\Run'+#0,'MyApp','c:\MyApp.EXE');
    Free;
    end;

If you use the system tray, you can use a popupmenu component. Which is much easier.

Here is the SystemTrayIcon component:

unit TrayIco;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ShellAPI, Menus;

type
  TSystemTrayIcon = class(TComponent)
  private
  protected
    FHandle: HWND;
    FOnDblClick: TNotifyEvent;
    FOnLeftClick: TNotifyEvent;
    FOnRightClick: TNotifyEvent;
    FMessageID: UINT;
    FIcon: TIcon;
    FTip: String;
    HaveIcon: Boolean;
    IconData: TNotifyIconData;
    FData: Pointer;
    FPopupMenu: TPopupMenu;
    procedure SetIcon(Value: TIcon);
    procedure UpdateIcon(Command: DWord);
    procedure Loaded; override;
    procedure SetTip(Value: String);
  public
    procedure WndProc(var Message: TMessage); virtual;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property Data: Pointer read FData write FData;
  published
    property MessageID: UINT read FMessageID write FMessageID;
    property Icon: TIcon read FIcon write SetIcon;
    property Tip: String read FTip write SetTip;
    property PopupMenu: TPopupMenu read FPopupMenu write FPopupMenu;
    property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick;
    property OnLeftClick: TNotifyEvent read FOnLeftClick write FOnLeftClick;
    property OnRightClick: TNotifyEvent read FOnRightClick write FOnRightClick;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Win32', [TSystemTrayIcon]);
end;

constructor TSystemTrayIcon.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FHandle := AllocateHWnd(WndProc);
  FMessageID := WM_User + 1;
  FIcon := TIcon.Create;
  HaveIcon := False;
end;

destructor TSystemTrayIcon.Destroy;
begin
  UpdateIcon(NIM_DELETE);
  DeAllocateHWnd(FHandle);
  FIcon.Free;
  inherited Destroy;
end;

procedure TSystemTrayIcon.Loaded;
begin
  inherited Loaded;
  Icon := FIcon;
end;

procedure TSystemTrayIcon.SetTip(Value: String);
begin
  FTip := Value;
  if (csDesigning in ComponentState) then exit;
  if HaveIcon then UpdateIcon(NIM_MODIFY)
end;

procedure TSystemTrayIcon.SetIcon(Value: TIcon);
begin
  FIcon.Assign(Value);
  if (csDesigning in ComponentState) then exit;
  if Value = nil then
  begin
    UpdateIcon(NIM_DELETE);
    HaveIcon := false;
    Exit;
  end;
  if HaveIcon then UpdateIcon(NIM_MODIFY)
  else UpdateIcon(NIM_ADD);
  HaveIcon := true;
end;

procedure TSystemTrayIcon.UpdateIcon(Command: DWord);
begin
  with IconData do
  begin
    Wnd := FHandle;
    uID := 1;
    uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
    hIcon := FIcon.Handle;
    uCallbackMessage := FMessageID;
    StrPLCopy(szTip, FTip, 63);
    cbSize := sizeof(IconData);
    Shell_NotifyIcon(Command, @IconData);
  end;
end;

procedure TSystemTrayIcon.WndProc(var Message: TMessage);
var
  CPos: TPoint;
begin
  if (Message.Msg = FMessageID) then
  begin
    case Message.lParam of
    WM_LBUTTONDBLCLK: if Assigned(FOnDblClick) then FOnDblClick(Self);
    WM_LBUTTONDOWN: if Assigned(FOnLeftClick) then FOnLeftClick(Self);
    WM_RBUTTONDOWN:
      begin
        if Assigned(FOnRightClick) then FOnRightClick(Self);
        if Assigned(FPopupMenu) then
        begin
          GetCursorPos(CPos);
          FPopupMenu.Popup(CPos.X, CPos.Y);
        end;
      end;
    else Message.Result := DefWindowProc(FHandle, Message.Msg, Message.WParam, Message.LParam);
    end;
  end
  else Message.Result := DefWindowProc(FHandle, Message.Msg, Message.WParam, Message.LParam);
end;

end.


0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question