Недавно добавленные исходники

•  TDictionary Custom Sort  3 223

•  Fast Watermark Sources  2 989

•  3D Designer  4 750

•  Sik Screen Capture  3 259

•  Patch Maker  3 466

•  Айболит (remote control)  3 526

•  ListBox Drag & Drop  2 903

•  Доска для игры Реверси  80 757

•  Графические эффекты  3 842

•  Рисование по маске  3 171

•  Перетаскивание изображений  2 544

•  Canvas Drawing  2 671

•  Рисование Луны  2 500

•  Поворот изображения  2 089

•  Рисование стержней  2 119

•  Paint on Shape  1 522

•  Генератор кроссвордов  2 180

•  Головоломка Paletto  1 730

•  Теорема Монжа об окружностях  2 156

•  Пазл Numbrix  1 649

•  Заборы и коммивояжеры  2 016

•  Игра HIP  1 261

•  Игра Go (Го)  1 200

•  Симулятор лифта  1 421

•  Программа укладки плитки  1 176

•  Генератор лабиринта  1 511

•  Проверка числового ввода  1 295

•  HEX View  1 465

•  Физический маятник  1 322

•  Задача коммивояжера  1 356

 
скрыть


Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Реализация Drag-and-Drop из внешнего приложения в ваше



Оформил: DeeCo

{ 
  The following example demonstrates the Drag&Drop machanism from an external 
  application (Wordpad, Microsoft,..) to a TMemo in your own application. 

{ 
  Das folgende Beispiel demonstriert der Drag&Drop Maechanismus 
  aus externen Anwendungen (wie zum Beispiel WordPad oder Microsoft Word) 
  in ein TMemo des eigenen Delphi-Programms. 
 }

 unit TMemoDragDropFrm;

 { **************************************************************** 
  Source File Name :  TMemoDragDropFrm.pas 
  Typ              :  Hauptformular 
  Autor            :  Andreas Kosch 
  Compiler         :  Delphi 4.02 CSS 
  Betriebssystem   :  Windows 98 
  Beschreibung     :  Text via OLE Drag&Drop ьbernehmen aus einer 
                      anderen Anwendung (wie zum Beispiel WordPad) 
                      ьbernehmen. 
  16.01.2003: Test mit Delphi 7 und Microsoft Word XP unter Windowx XP 
 **************************************************************** }
  { Comments by Thomas Stutz }

 interface

 uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, ComCtrls, ActiveX, ShlObj, ComObj, StdCtrls;

 type
   // TForm1's declaration indicates that it's a TForm and that 
  // it supports the IDropTarget interface: 

 { 

  IDropTarget 

  Any application wanting to accept drop operations must 
  implement the IDropTarget interface. 

  Methods of the IDropTarget interface: 

  DragEnter 
    Dragged item has just been moved into the application's window, 
    return the relevant icon. 

  DragOver 
    Dragged item is being moved over the application's window, 
    return the relevant icon. 

  DragLeave 
    Dragged item has just moved out of the application's window. 

  Drop 
    The dragged item has been dropped on this application. 

  }

   TForm1 = class(TForm, IDropTarget)
     Memo1: TMemo;
     procedure FormCreate(Sender: TObject);
     procedure FormDestroy(Sender: TObject);
   private
     { Private declarations }
     // IDropTarget 
    function DragEnter(const dataObj: IDataObject;
                        grfKeyState: Longint;
                        pt: TPoint;
                        var dwEffect: Longint): HResult; stdcall;
     function DragOver(grfKeyState: Longint;
                       pt: TPoint;
                       var dwEffect: Longint): HResult; stdcall;
     function DragLeave: HResult; stdcall;
     function Drop(const dataObj: IDataObject;
                   grfKeyState: Longint; pt: TPoint;
                   var dwEffect: Longint): HResult; stdcall;
    // IUnknown 
   // Ignore referance counting 
   function _AddRef: Integer; stdcall;
    function _Release: Integer; stdcall;

   public
     { Public declarations }
   end;

 var
   Form1: TForm1;

 implementation

 {$R *.dfm}

 uses
   ShellAPI;


 // In the OnCreate event handler, two important methods are called. 
// First, OleInitalize is called. This initializes the OLE libraries and should always be 
// called before your application uses any OLE functions. 
// RegisterDragDrop registers the window as a valid drop target. 
// If this isn't called, the window will never receive any drop events. 


procedure TForm1.FormCreate(Sender: TObject);
 begin
   OleInitialize(nil);
   {Allow window to accept drop events}
   OleCheck(RegisterDragDrop(Handle, Self));
   { Execute Wordpad for testing }
   ShellExecute(Handle, 'open', 'wordpad', 'c:\Test.doc', nil, SW_SHOW);
 end;

 // OnDestroy does the exact opposite. It calls RevokeDropTarget to indicate that 
// drop events are no longer accepted. 
// It then calls OleUninitialize, since the application is finished using all OLE functions. 

procedure TForm1.FormDestroy(Sender: TObject);
 begin
   {Finished accepting drops}
   RevokeDragDrop(Handle);
   OleUninitialize;
 end;

 {-----------------------------------------------------------------}
 { IDropTarget-Implementierung                                     }
 {-----------------------------------------------------------------}
 function TForm1.DragEnter(const dataObj: IDataObject;
   grfKeyState: Longint;
   pt: TPoint;
   var dwEffect: Longint): HResult;
 begin
   dwEffect := DROPEFFECT_COPY;
   Result  := S_OK;
 end;

 function TForm1.DragOver(grfKeyState: Longint;
   pt: TPoint;
   var dwEffect: Longint): HResult;
 begin
   dwEffect := DROPEFFECT_COPY;
   Result := S_OK;
 end;

 function TForm1.DragLeave: HResult;
 begin
   Result := S_OK;
 end;

 function TForm1._AddRef: Integer;
 begin
    Result := 1;
 end;

 function TForm1._Release: Integer;
 begin
    Result := 1;
 end;

 function TForm1.Drop(const dataObj: IDataObject;
   grfKeyState: Longint;
   pt: TPoint;
   var dwEffect: Longint): HResult;
 var
   aFmtEtc: TFORMATETC;
   aStgMed: TSTGMEDIUM;
   pData: PChar;
 begin
   {Make certain the data rendering is available}
   if (dataObj = nil) then
     raise Exception.Create('IDataObject-Pointer is not valid!');
   with aFmtEtc do
   begin
     cfFormat := CF_TEXT;
     ptd := nil;
     dwAspect := DVASPECT_CONTENT;
     lindex := -1;
     tymed := TYMED_HGLOBAL;
   end;
   {Get the data}
   OleCheck(dataObj.GetData(aFmtEtc, aStgMed));
   try
     {Lock the global memory handle to get a pointer to the data}
     pData := GlobalLock(aStgMed.hGlobal);
     { Replace Text }
     Memo1.Text := pData;
   finally
     {Finished with the pointer}
     GlobalUnlock(aStgMed.hGlobal);
     {Free the memory}
     ReleaseStgMedium(aStgMed);
   end;
   Result := S_OK;
 end;

 end.




Похожие по теме исходники

Текст Drag & Drop

Drag and Drop Text

Quick Drag & Drop

Dragster Tree Relay

 

ListBox Drag & Drop

Backup and Restore

Market Monitoring and Billing

Black and White Effects

 

Sand Dog

Wave and MIDI In-Out

Vista and 7 Sound

Improved Buttons and ProgressBar

 

Desktop Sands

Rotation and Symmetry

Dropper (пипетка Фотошоп)




Copyright © 2004-2024 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте