Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Drag Drop Problem (https://www.delphipraxis.net/103137-drag-drop-problem.html)

Hunni 10. Nov 2007 23:23


Drag Drop Problem
 
Hallo,

ich habe ein kleines Problem mit Drag/Drop in eine Listbox.

Wenn ich die Listbox direkt auf dem Formular habe, kann ich einen File per drag/drop hinzufügen.
Wenn die Listbox aber auf einem Panel liegt funktioniert es leider nicht :(

Als Grundlage habe ich den TIP aus Drag Drop

Irgend wie stehe ich auf dem Schlauch warum es nicht funktioniert


Gruß
Torsten

bitsetter 11. Nov 2007 07:23

Re: Drag Drop Problem
 
Hallo,

so müsste es gehen:
Delphi-Quellcode:
unit Unit1;

interface

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

type
  TListBox = class(StdCtrls.TListBox)
  private
    procedure WMDROPFILES(var Msg: TMessage); Message WM_DROPFILES;
end;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Panel1: TPanel;
    procedure FormCreate(Sender: TObject);
  private

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  ShellAPI;

procedure TListBox.WMDROPFILES(var Msg: TMessage);
var
  i, Counts, Size: Integer;
  PCharFileName: PChar;
begin
  inherited;

  PCharFileName := nil;
  Counts := DragQueryFile(Msg.WParam, $FFFFFFFF, PCharFileName, 255);

  for i := 0 to Counts - 1 do
  begin
    Size := DragQueryFile(Msg.WParam, i, nil, 0) + 1;
    PCharFileName := StrAlloc(Size);
    DragQueryFile(Msg.WParam, i, PCharFileName, Size);
    Items.Add(String(PCharFileName));
    StrDispose(PCharFileName);
  end;

  DragFinish(Msg.WParam);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DragAcceptFiles(ListBox1.Handle, True);
end;

end.
Du fängst einfach die Nachricht WM_DROPFILES dann von der Listbox ab.

EDIT: mit Subclassing geht es ansonsten auch noch.

Hunni 11. Nov 2007 08:22

Re: Drag Drop Problem
 
Danke

noch ein schönes Wochenende

Torsten


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:35 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