当前位置: 代码迷 >> Delphi >> mxoutlookbarpro控件如何实现拖拽文件功能?也就是动态创建按钮,哪位高人现身说法一上
  详细解决方案

mxoutlookbarpro控件如何实现拖拽文件功能?也就是动态创建按钮,哪位高人现身说法一上

热度:1711   发布时间:2013-02-25 00:00:00.0
mxoutlookbarpro控件怎么实现拖拽文件功能?也就是动态创建按钮,哪位高人现身说法一下?
如题:我现在用这个控件时发现它的demo中的拖拽功能,在实现动态创建按钮时,它里面得先有了一个按钮才能创建,否则创建不了;
代码如下:

procedure TFrm_Main.mxOutlookBarProDragDrop(Sender: TmxOutlookBarPro;
  Source: TObject; DataObject: IDataObject; const Formats: array of Word;
  Shift: TShiftState; Pt: TPoint; var Effect: Integer; Mode: TmxDropMode);
Var
  Button: TmxButton;
  medium: TStgMedium;
  DropFiles: PDropFiles;
  Filename: PChar;

  Procedure CreateButton( FileName: String );
  Begin   
    Button.Caption := FileName;
    Button.Hint := FileName;
    Button.ImageIndex :=10;
    Button.OnClick:=click;
    Sender.ProcessOuterDrop( DataObject, Button, Sender.CurrentTargetButton, Effect, Sender.CurrentTargetButton.HitStatus );
  End;

Begin
  { You need to change this code to your own }
  If Mode = dmButton Then  //一开始就判断是不是按钮,为什么要一开始就判断
//是不是按钮,我都没创建,所以这不太明白。
  Begin
    If ( DataObject.GetData( HDropFormatEtc, medium ) <> S_OK ) Then exit;
    Try
      If ( medium.tymed = TYMED_HGLOBAL ) Then
      Begin
        DropFiles := PDropFiles( GlobalLock( medium.HGlobal ) );
        Try
          Filename := PChar( DropFiles ) + DropFiles^.pFiles;
          While ( Filename^ <> #0 ) Do
          Begin
          If ( DropFiles^.fWide ) Then
          Begin
          CreateButton( PWideChar( FileName ) );
          Inc( Filename, ( Length( PWideChar( FileName ) ) + 1 ) * 2 );
          End
          Else
          Begin
          CreateButton( Filename );
          Inc( Filename, Length( Filename ) + 1 );
          End;
          End;
        Finally
          GlobalUnlock( medium.HGlobal );
        End;
      End;
    Finally
      ReleaseStgMedium( medium );
    End;
  End
  Else
    MessageDlg( 'You have dropped something on the outlookbar!!', mtWarning, [ mbOK ], 0 );
  相关解决方案