
21.08.2013, 19:45
|
Начинающий
|
|
Регистрация: 27.09.2011
Сообщения: 158
Репутация: 10
|
|
Панель для ярлыков
Не выходит сделать drag and drop чтоб ярлыки перетаскивать можно было на панель
делаю как написано а ярлык не высвечиваетса на панеле у меня Windows 8 и delphi xe3 что не так подскажите
Код:
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Winapi.ShellAPI, Vcl.ExtCtrls, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Image1: TImage;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure WmDropFiles( var Msg: TWMDropFiles); message WM_DropFiles;
public
{ Public declarations }
end;
var
Form1: TForm1;
CFileName: array[0..MAX_PATH] of Char; // Переменная с именем перетаскиваемого файла
F: string; //Это для удобства
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(handle, true); // Включаем режим Drag-and-drop
end;
procedure TForm1.WmDropFiles(var Msg: TWMDropFiles);
var
icon: hicon; //Иконка файла
iconindex: word;
begin
try
if DragQueryFile(Msg.Drop,0, CfileName, Max_Path)> 0 then //Если перетащили файл
begin
F:=CfileName; // Конвертируем Array of Char -> String
Label1.Caption:=ExtractFileName(F); // Получаем имя файла из его полного пути
Msg.Result:=0;
end;
finally
DragFinish(Msg.Drop); //Говорим что приняли файл
end;
iconindex:=1;
//получаем картинку из файла
Image1.Picture.Icon.Handle:= ExtractAssociatedIcon(HInstance, Pchar(F), iconIndex);
DrawIcon(Canvas.Handle,10,10,icon); //Рисуем картинку
end;
end.
|