Einzelnen Beitrag anzeigen

FarAndBeyond
(Gast)

n/a Beiträge
 
#14

AW: Ersatz für Office Shurtcut unter Windows 10

  Alt 20. Mai 2016, 20:33
Ein einfaches Beispiel:
Delphi-Quellcode:
Unit uSimpleLauncher;

Interface
 Uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, ExtCtrls, Forms;

 Type
  TwndGUI = Class(TForm)

   Procedure FormCreate (Sender: TObject);
   Procedure FormShow (Sender: TObject);
   Procedure FormMouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
   Procedure FormCloseQuery (Sender: TObject; Var CanClose: Boolean);

   Procedure TimerTOPdo (Sender: TObject);
   Procedure TimerGUIdo (Sender: TObject);

    PRIVATE
     Procedure WMGetMinMaxInfo (Var MSG: TWMGetMinMaxInfo); Message WM_GETMINMAXINFO;
     Procedure WMSysCommand (Var MSG: TWMSysCommand); Message WM_SYSCOMMAND;
  End;

 VAR
  wndGUI : TwndGUI;
  wndLaunch: TForm;
  timerGUI : TTimer;
  timerTOP : TTimer;
Implementation
 {$R *.dfm}


Procedure TwndGUI.FormCreate(Sender: TObject);
 Begin
  SetBounds(0, 0, Screen.Width, 100);

  DoubleBuffered:= True;
  Color := clNavy;
  BorderStyle := bsNone;
  FormStyle := fsStayOnTop;

   wndLaunch := TForm.Create(Application);
   wndLaunch.AlphaBlend := True;
   wndLaunch.AlphaBlendValue:= 1;
   wndLaunch.BorderStyle := bsNone;
   wndLaunch.FormStyle := fsStayOnTop;
   wndLaunch.OnCloseQuery := wndGUI.FormCloseQuery;
   wndLaunch.OnShow := wndGUI.FormShow;
   wndLaunch.SetBounds(100, 0, (Screen.Width-200), 1);
   wndLaunch.Show;

    timerTOP := TTimer.Create(Application);
    timerTOP.Interval:= 30;
    timerTOP.Enabled := False;
    timerTOP.OnTimer := wndGUI.TimerTOPdo;

    timerGUI := TTimer.Create(Application);
    timerGUI.Interval:= 30;
    timerGUI.Enabled := False;
    timerGUI.OnTimer := wndGUI.TimerGUIdo;

    timerTOP.Enabled:= True;
 End;


Procedure TwndGUI.WMGetMinMaxInfo(Var MSG: TWMGetMinMaxInfo);
 Begin
  Inherited;
   With MSG.MinMaxInfo^
   Do
    Begin
     ptMinTrackSize.x:= Screen.Width;
     ptMaxTrackSize.x:= Screen.Width;
     ptMinTrackSize.y:= 100;
     ptMaxTrackSize.y:= 100;
    End;
 End;


Procedure TwndGUI.WMSysCommand(Var MSG: TWMSysCommand);
 Begin
  If MSG.CmdType And $FFF0=SC_MINIMIZE
  Then wndGUI.Hide
  Else Inherited;
 End;


Procedure TwndGUI.FormShow(Sender: TObject);
  Var
   Owner: HWND;
 Begin
  Owner:= GetWindow(TForm(Sender).Handle, GW_OWNER);
  ShowWindow(Owner, SW_HIDE);
 End;


Procedure TwndGUI.TimerTOPdo(Sender: TObject);
  Var
   Cursor: TPoint;
 Begin
  GetCursorPos(Cursor);
   If PtInRect(wndLaunch.BoundsRect, Cursor)
   Then
    Begin
     timerTOP.Enabled:= False;
      wndGUI.Show;
     timerGUI.Enabled:= True;
      Exit;
    End;
  SetWindowPos(wndLaunch.Handle, HWND_TOPMOST,0,0,0,0, SWP_NOMOVE Or SWP_NOSIZE);
 End;


Procedure TwndGUI.TimerGUIdo(Sender: TObject);
  Var
   Cursor: TPoint;
 Begin
  GetCursorPos(Cursor);
   If Not PtInRect(wndGUI.BoundsRect, Cursor)
   Then
    Begin
     timerGUI.Enabled:= False;
      wndGUI.Hide;
     timerTOP.Enabled:= True;
    End;
 End;


Procedure ExitPRG;
 Begin
  If Assigned(wndGUI)
  Then
   Begin
    wndGUI.Release;
    wndGUI:= Nil;
   End;

  If Assigned(wndLaunch)
  Then
   Begin
    wndLaunch.Release;
    wndLaunch:= Nil;
   End;

  Application.Terminate;
 End;


Procedure TwndGUI.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
 Begin
  If Button = mbRight
  Then ExitPRG;
 End;


Procedure TwndGUI.FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
 Begin
  CanClose:= False;
 End;


End.
Delphi-Quellcode:
Program Launcher;

 Uses
  Forms,
  uSimpleLauncher In 'uSimpleLauncher.pas{wndGUI};

 {$R *.res}

Begin
 Application.Initialize;
 Application.ShowMainForm:= False;
 Application.CreateForm(TwndGUI, wndGUI);
 Application.Run;
End.
Was soll eigentlich falsch sein an ShellExecute ???
Delphi-Quellcode:
Procedure StartProgram(Path: String);
 Begin
  ShellExecute(wndGUI.Handle, Nil, PChar(Path), Nil, Nil, SW_SHOW);
 End;
Jetzt nur noch ein paar Bilder oder Icons drauf und den Pfad reinhauen und los geht's...
Kommt natürlich drauf an wie man den Pfad bezieht... (Datei, UserInput_Menü, Direkteingabe...)

Einfach starten und mit der Maus an die obere Bildschirmkante...
Schließen mit rechter Maustaste...


EDIT: CloseQuery war doppelt und wndLaunch.OnShow fehlte...

Geändert von FarAndBeyond (20. Mai 2016 um 21:55 Uhr)
  Mit Zitat antworten Zitat