?
Solved

Shortcut

Posted on 2003-03-14
1
Medium Priority
?
244 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
[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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

764 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