Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Drag & Drop im Edit erkennen und farbig markieren (https://www.delphipraxis.net/163498-drag-drop-im-edit-erkennen-und-farbig-markieren.html)

Helmi 30. Sep 2011 18:03

Drag & Drop im Edit erkennen und farbig markieren
 
Hallo,

ich verwende diesen Code um Dateinamen via Drag & Drop aus dem Explorer in ein Edit zu bekommen.

Nun würd ich gerne, wenn die Maus über dem Edit ist, dass Drag & Drop erlaubt, dieses Edit farbig markieren.

Nur wie kann ich feststellen ob Drag & Drop im Edit aktiv ist und nur in diesem Falle es farbig markieren?
(Die Markierung sollte natürlich wieder zurück gesetzt werden, wenn das Dragen zu ende ist)

Ich hab schon: OnStartDrag, OnEndDrag, OnDragDrop, OnDragOver ausprobiert - aber kein Ereignis wird ausgelöst

stahli 30. Sep 2011 18:18

AW: Drag & Drop im Edit erkennen und farbig markieren
 
Du könntest evtl. in MouseEnter und MouseExit auf DragControl prüfen...

Helmi 30. Sep 2011 19:18

AW: Drag & Drop im Edit erkennen und farbig markieren
 
Zitat:

Zitat von stahli (Beitrag 1127804)
Du könntest evtl. in MouseEnter und MouseExit auf DragControl prüfen...

Hättest du vielleicht ein Beispiel dafür?

stahli 30. Sep 2011 19:45

AW: Drag & Drop im Edit erkennen und farbig markieren
 
Nein sorry.
Habe es gerade mal probiert, das funktioniert so leider doch nicht :-(

Helmi 30. Sep 2011 21:37

AW: Drag & Drop im Edit erkennen und farbig markieren
 
Ich hab schon überlegt den Cursor im OnMouseMove abzufragen, aber leider funktioniert das auch nicht.
Der Screen.Cursor scheint nicht verändert zu werden, wenn Explorer-Drag & Drop aktiv ist

Habs so probiert:
Delphi-Quellcode:
procedure TForm1.Edit1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  If Screen.Cursor <> crDefault then
    Edit1.Color := clRed
  else
    Edit1.Color := clBlue;
end;

himitsu 30. Sep 2011 23:05

AW: Drag & Drop im Edit erkennen und farbig markieren
 
Du könntest im OnEnter mit GetAsyncKeyState prüfen, ob die linke Maustaste gedrückt ist
und wenn gleichzeitig gewisse Datenformate im Zwischenspeicher sind, dann könntest du zu relativ großer Wahrscheinlichkeit davon ausgehn, daß es sich um Drag&Drop handelt.

Was genau sich im Zwischenspeicher befindet, müßtest'e aber nochmal nachsehn.
Ich glaub das waren zwei verschiedene Dinge, welche sich dabei immer darin befinden.


Kann aber sein, daß du kein OnEnter/OnMouseMove bekommst, da der sich Eingabefokus, wärend des Clicks+Drags, noch beim Explorer befindet.

stahli 30. Sep 2011 23:28

AW: Drag & Drop im Edit erkennen und farbig markieren
 
Zitat:

Zitat von himitsu (Beitrag 1127842)
Kann aber sein, daß du kein OnEnter/OnMouseMove bekommst, da der sich Eingabefokus, wärend des Clicks+Drags, noch beim Explorer befindet.

So sah es bei meinem kurzen Test aus. Man müsste wohl nachschauen, wo und wie der Cursor genau geändert wird.
Ich denke mal, das wird vom Aufwand unverhältnismäßig sein....

himitsu 30. Sep 2011 23:45

AW: Drag & Drop im Edit erkennen und farbig markieren
 
Zitat:

Zitat von http://www.codeguru.com/cpp/cpp/cpp_mfc/dragdrop/article.php/c4059
The drag-and-drop can be obtained in two ways; the first is OLE and the second is using the MFC. MFC supports the functionality of drag-and-drop without using OLE.

Dann bleibt dir wohl nur noch der andere Weg. (mit etwas Glück gibt es dort ein passendes Ereignis)


API / MFC : in der WinAPI und im MFC würde dann wohl DragAcceptFiles, WM_DROPFILES und Co. verwendet

OLE / MFC OLE : k.A. ... das müßtest du erstmal irgendwie rausbekommen

[add]
ShlObj.IDropTargetHelper ?

Helmi 6. Dez 2011 20:19

AW: Drag & Drop im Edit erkennen und farbig markieren
 
Zitat:

Zitat von himitsu (Beitrag 1127849)
[add]
ShlObj.IDropTargetHelper ?

Jetzt seh ich erst dass da noch was hinzugefügt wurde...

ShlObj kennt leider IDropTargetHelper nicht

himitsu 6. Dez 2011 21:20

AW: Drag & Drop im Edit erkennen und farbig markieren
 
Dieses Interface gibt es seit Windows 2000,
und Delphi 7 stammt aus dem Jahre 2002.

Embarcadero ... ähhhhhh Borland, waren beim Importieren der WinAPI noch nie die Schnellsten. :stupid:


http://msdn.microsoft.com/en-us/libr.../bb762034.aspx
usw.

Eventuell ist in den JEDI-WinAPI-Headern, bzw in der JCL noch mehr/besseres Zeugs enthalten,
wenn nicht gar ein ganzes Drag&Drop-Komponentendinges.

Delphi-Quellcode:
///////////////////////////////////////////////////////
//
// Drag and Drop helper
//
// Purpose: To expose the Shell drag images
//
// This interface is implemented in the shell by CLSID_DragDropHelper.
//
// To use:
//   If you are the source of a drag (i.e. in response to LV_DRAGBEGIN or
//    equivelent begin drag message) call
//    IDragSourceHelper::InitializeFromWindow
//              (<hwnd of window supporting DI_GETDRAGIMAGE>,
//               <pointer to POINT indicating offset to the mouse from
//                  the upper left corner of the image>,
//               <pointer to data object>)
//
//      NOTE: The Data object must support IDataObject::SetData with multiple
//            data types and GetData must implement data type cloning
//            (Including HGLOBAL), not just aliasing.
//
//   If you wish to have an image while over your application add the
//    IDragImages::Dr* calls to your IDropTarget implementation. For Example:
//
//    STDMETHODIMP CUserDropTarget::DragEnter(IDataObject* pDataObject,
//                                            DWORD grfKeyState,
//                                            POINTL pt, DWORD* pdwEffect)
//    {
//          // Process your DragEnter
//          // Call IDragImages::DragEnter last.
//          _pDropTargetHelper->DragEnter(_hwndDragOver, pDataObject,
//                                        (POINT*)&pt, *pdwEffect);
//          return hres;
//    }
//
//
//   If you wish to be able to source a drag image from a custom control,
//     implement a handler for the RegisterWindowMessage(DI_GETDRAGIMAGE).
//     The LPARAM is a pointer to an SHDRAGIMAGE structure.
//
//      sizeDragImage -   Calculate the length and width required to render
//                          the images.
//      ptOffset      -   Calculate the offset from the upper left corner to
//                          the mouse cursor within the image
//      hbmpDragImage -   CreateBitmap( sizeDragImage.cx, sizeDragImage.cy,
//                           GetDeviceCaps(hdcScreen, PLANES),
//                           GetDeviceCaps(hdcScreen, BITSPIXEL),
//                           NULL);
//
//   Drag Images will only be displayed on Windows NT 5.0 or later.
//
//
//   Note about IDropTargetHelper::Show - This method is provided for
//     showing/hiding the Drag image in low color depth video modes. When
//     painting to a window that is currently being dragged over (i.e. For
//     indicating a selection) you need to hide the drag image by calling this
//     method passing FALSE. After the window is done painting, Show the image
//     again by passing TRUE.

const
  SID_IDropTargetHelper = '{4657278B-411B-11D2-839A-00C04FD918D0}';
  SID_IDragSourceHelper = '{DE5BF786-477A-11D2-839D-00C04FD918D0}';
  SID_IDragSourceHelper2 = '{83E07D0D-0C5F-4163-BF1A-60B274051E40}';

  // This is sent to a window to get the rendered images to a bitmap
  // Call RegisterWindowMessage to get the ID
  DI_GETDRAGIMAGE = 'ShellGetDragImage';

  DSH_ALLOWDROPDESCRIPTIONTEXT = $1;

type
  LPSHDRAGIMAGE = ^SHDRAGIMAGE;
  SHDRAGIMAGE = record
      sizeDragImage: SIZE;           // OUT - The length and Width of the
                                      //        rendered image
      ptOffset: TPoint;              // OUT - The Offset from the mouse cursor to
                                      //        the upper left corner of the image
      hbmpDragImage: HBITMAP;        // OUT - The Bitmap containing the rendered
                                      //        drag images
      crColorKey: COLORREF;          // OUT - The COLORREF that has been blitted
                                      //        to the background of the images
  end;
  TShDragImage = SHDRAGIMAGE;
  PShDragImage = ^TShDragImage;

  IDropTargetHelper = interface(IUnknown)
    [SID_IDropTargetHelper]
    function DragEnter(hwndTarget: HWND; const pDataObject: IDataObject;
                       var ppt: TPoint; dwEffect: DWORD): HRESULT; stdcall;
    function DragLeave: HResult; stdcall;
    function DragOver(var ppt: TPoint; dwEffect: DWORD): HRESULT; stdcall;
    function Drop(const pDataObject: IDataObject; var ppt: TPoint;
                  dwEffect: DWORD): HRESULT; stdcall;
    function Show(fShow: BOOL): HRESULT; stdcall;
  end;

  IDragSourceHelper = interface(IUnknown)
    [SID_IDragSourceHelper]
    function InitializeFromBitmap(pshdi: LPSHDRAGIMAGE;
      const pDataObject: IDataObject): HRESULT; stdcall;
    function InitializeFromWindow(hwnd: HWND; var ppt: TPoint;
      const pDataObject: IDataObject): HRESULT; stdcall;
  end;

  IDragSourceHelper2 = interface(IDragSourceHelper)
    [SID_IDragSourceHelper2]
    function SetFlags(dwFlags: DWORD): HRESULT; stdcall;
  end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:47 Uhr.
Seite 1 von 2  1 2      

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