Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Anwendung versteckt autostarten (https://www.delphipraxis.net/62493-anwendung-versteckt-autostarten.html)

mr-unbekannt 5. Feb 2006 14:50


Anwendung versteckt autostarten
 
hello


mein programm startet versteckt mit windows mit, das habe ich geschafft. Ich habe einen HotKey eingebaut, und wenn der aktiviert wird, öffnet sich die Form. Wenn ShowMainForm auf False ist, reagiert der Hotkey nicht...

ich habe den code in der Form1 für den Hotkey:
Delphi-Quellcode:
private
  id1: Integer;
    procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
    { Private-Deklarationen }
  public
     { Public-Deklarationen }
  end;

 
var
  Form1: TForm1;
implementation

{$R *.dfm}

 procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
  if Msg.HotKey = id1 then begin Form1.Show; TrayIcon1.Active := True; end;
end;
und den Beim Project-Quelltext:
Delphi-Quellcode:
var r: Tregistry;
begin

  CreateHook(Application.Handle,true);
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
   R:=TRegistry.Create;
  R.RootKey:=HKEY_LOCAL_MACHINE;
  try
  R.OpenKey('SOFTWARE\Microsoft\APK', true);
  if R.ReadString('hon') = 'True' then begin Application.ShowMainForm := false;
  Form1.TrayIcon1.Active := False; end;
  finally R.Free end;

  Application.Run;



end.

Der_Unwissende 5. Feb 2006 18:11

Re: Anwendung versteckt autostarten
 
Hi,
sag mal registrierst du überhaupt deinen Hotkey korrekt? Das geht hier nicht so wirklich aus deinem Code hervor. Wenn du das nicht machst, ist es wenig verwunderlich, dass du da nichts siehst. Du musst nur im OnCreate einmal die RegisterHotKey Methode aufrufen. So in der Art:

Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
  self.atom := GlobalAddAtom(UNIQUE_IDENTIFIER);
  if not RegisterHotKey(self.Handle, atom, MOD_SHIFT, VK_WHAT_EVER) then
    begin
      // Fehler aufgetreten, müsstest du natürlich behandeln
    end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  GlobalDeleteAtom(self.atom);
end;
Das sollte dann auch funktionieren, wenn das Form nicht angezeigt wird (solange es existiert).

Gruß Der Unwissende

mr-unbekannt 6. Feb 2006 08:11

Re: Anwendung versteckt autostarten
 
danke, habs hinbekommen

bye


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:48 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz