home *** CD-ROM | disk | FTP | other *** search
/ The Mother of All Windows Books / CD-MOM.iso / cd_mom / newsletr / winprogj / wpjv1n2 / dndclie.pas < prev    next >
Pascal/Delphi Source File  |  1993-01-31  |  3KB  |  112 lines

  1. (*****************************************)
  2. (*                                       *)
  3. (*   D&D-Client (d&dclie.pas)            *)
  4. (*                                       *)
  5. (*   A simple D&D-Client                 *)
  6. (*                                       *)
  7. (*   Copyright (c) 1992,93 by A. Furrer  *)
  8. (*                                       *)
  9. (*   This program requires Windows 3.1   *)
  10. (*****************************************)
  11.  
  12. program DDClie;
  13.  
  14. uses Strings, WinTypes, WinProcs, WObjects, WinCRT;
  15.  
  16.  
  17. (****************************************)
  18. (* Declarations for Drag&Drop-functions *)
  19. (****************************************)
  20.  
  21. const
  22.   wm_DropFiles = $0233;
  23.  
  24. function DragQueryFile(Drop: THandle;FileIndex: Word;
  25.                        FileName: PChar;MaxChars: Word):Word; external 'SHELL'
  26.  index 11;
  27. function DragQueryPoint(Drop: THandle;var Pt: TPoint):Bool;  external 'SHELL'
  28.  index 13;
  29. procedure DragFinish(Drop: THandle);                         external 'SHELL'
  30.  index 12;
  31. procedure DragAcceptFiles(Wnd: HWnd;Accept: Bool);           external 'SHELL'
  32.  index 9;
  33.  
  34.  
  35. (****************)
  36. (* Mainwindow   *)
  37. (****************)
  38.  
  39. type
  40.   PMainwindow = ^TMainwindow;
  41.   TMainwindow =object(TWindow)
  42.     procedure SetupWindow; virtual;
  43.     function CanClose: Boolean; virtual;
  44.     procedure WMDropFiles(var Msg : TMessage); virtual wm_first + wm_DropFiles;
  45.   end;
  46.  
  47. procedure TMainwindow.SetupWindow;
  48. begin
  49.   TWindow.SetupWindow;
  50.   DragAcceptFiles(HWindow,true);
  51. end;
  52.  
  53. function TMainwindow.CanClose;
  54. begin
  55.   if TWindow.CanClose then
  56.     DragAcceptFiles(HWindow,false);
  57.   CanClose:=true;
  58. end;
  59.  
  60. procedure TMainwindow.WMDropFiles;
  61. var s : array[0..255] OF char;
  62.     i,number : word;
  63.     P : TPoint;
  64.     pc : PChar;
  65. begin
  66.   DragQueryPoint(Msg.wParam,P);
  67.   writeln('Drop point: X:',P.X,' Y:',P.Y);
  68.  
  69.   (* This is a way to detect if the drop *)
  70.   (* was in the client area or not.      *)
  71.   (* It is NOT documented                *)
  72.   pc:=GlobalLock(Msg.wParam);
  73.   writeln('Drop in NonClient: ',bool((pc+6)^));
  74.   GlobalUnLock(Msg.wParam);
  75.  
  76.   number:=DragQueryFile(Msg.wParam,$ffff,nil,0);
  77.   writeln('Files:');
  78.   for i:=0 TO number-1 DO begin
  79.     DragQueryFile(Msg.wParam,i,s,SizeOf(s));
  80.     writeln('  ',s);
  81.   end;
  82.   DragFinish(Msg.wParam);
  83. end;
  84.  
  85.  
  86. (**********************)
  87. (* TDDClieApplication *)
  88. (**********************)
  89.  
  90. type
  91.    TDDClieApplication =
  92.      object(TApplication)
  93.        procedure InitMainWindow; virtual;
  94.      end;
  95.  
  96. procedure TDDClieApplication.InitMainWindow;
  97. begin
  98.   MainWindow := New(PMainwindow,Init(nil, 'D&DClient'));
  99. end;
  100.  
  101. (***************)
  102. (* Mainprogram *)
  103. (***************)
  104.  
  105. var
  106.    Prg : TDDClieApplication;
  107. begin
  108.   Prg.Init('D&DClient');
  109.   Prg.Run;
  110.   Prg.Done;
  111. end.
  112.