?
Solved

Shortcut

Posted on 2003-03-14
1
Medium Priority
?
245 Views
Last Modified: 2010-05-18
When i drag a shorctut on my form i'd like to get it's path and create a button that lunches the shortcut's app(quick lounch or other windows toolbar).
0
Comment
Question by:rayek007
1 Comment
 
LVL 17

Accepted Solution

by:
geobul earned 750 total points
ID: 8137876
Hi,

Try this:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;

type
  TRunButton = class(TButton)
  private
    FLink: string;
  public
    property Link: string read FLink write FLink;
  end;

  TForm1 = class(TForm)
    Button1: TButton;
    procedure RunMe(Sender: TObject);
    procedure CreateButton(filename: string);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    procedure DROPFILES(var Message: TWMDROPFILES); message WM_DROPFILES;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses ShellApi;

// TRunButton button click procedure
procedure TForm1.RunMe(Sender: TObject);
begin
  if Sender is TRunButton then begin
    ShellExecute(0,'open', PChar((Sender as TRunButton).Link), nil, nil, SW_SHOWNORMAL);
  end;
end;

// create a button
procedure TForm1.CreateButton(filename: string);
begin
  with TRunButton.Create(Form1) do begin
    Parent := Form1;
    Left := 10; // replace with your value
    Top := 10; // replace with your value
    Caption := ExtractFileName(filename); // or something else
    Link := filename;
    OnClick := RunMe;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // Register the form for accepting files
  DragAcceptFiles(Form1.Handle, True);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  // Unegister the form for accepting files
  DragAcceptFiles(Form1.Handle, False);
end;

procedure TForm1.DROPFILES(var Message: TWMDROPFILES);
var
  NumFiles : longint;
  i : longint;
  buffer : array[0..255] of char;
begin
  // How many files are being dropped
  NumFiles := DragQueryFile(Message.Drop, $FFFFFFFF, nil, 0);
  // Accept the dropped files
  for i := 0 to (NumFiles - 1) do begin
    DragQueryFile(Message.Drop, i, @buffer, sizeof(buffer));
    CreateButton(buffer);
  end;
end;

end.

Regards, Geo
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

578 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