如题:我现在用这个控件时发现它的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 );
End;
高手帮忙看下
怎么改才能一开始就实现动态添加按钮,谢谢了
------解决方案--------------------------------------------------------
顶顶
------解决方案--------------------------------------------------------
仔细看下,应该可以实现的吧