delphi - Add a IFileDialogCustomize PushButton Event -


i can create pushbutton filesavedialog1.dialog.queryinterface shown below. how setup , handle onpushbutton click event can respond button click?

procedure tform1.filesavedialog1execute(sender: tobject); const   dwvisualgroup1id: dword = 1900; var   c: ifiledialogcustomize;   d: ifiledialogcontrolevents; begin   if filesavedialog1.dialog.queryinterface(ifiledialogcustomize, c) = s_ok   begin     // add advanced button     c.addpushbutton(dwvisualgroup1id, 'advanced');     c.makeprominent(dwvisualgroup1id);     // setup pushbutton click event?    end; 

the following works fine me in xe2:

type   tmyfiledialogevents = class(tinterfacedobject, ifiledialogevents, ifiledialogcontrolevents)   public     { ifiledialogevents }     function onfileok(const pfd: ifiledialog): hresult; stdcall;     function onfolderchanging(const pfd: ifiledialog;       const psifolder: ishellitem): hresult; stdcall;     function onfolderchange(const pfd: ifiledialog): hresult; stdcall;     function onselectionchange(const pfd: ifiledialog): hresult; stdcall;     function onshareviolation(const pfd: ifiledialog; const psi: ishellitem;       out presponse: dword): hresult; stdcall;     function ontypechange(const pfd: ifiledialog): hresult; stdcall;     function onoverwrite(const pfd: ifiledialog; const psi: ishellitem;       out presponse: dword): hresult; stdcall;     { ifiledialogcontrolevents }     function onitemselected(const pfdc: ifiledialogcustomize; dwidctl: dword;       dwiditem: dword): hresult; stdcall;     function onbuttonclicked(const pfdc: ifiledialogcustomize;       dwidctl: dword): hresult; stdcall;     function oncheckbuttontoggled(const pfdc: ifiledialogcustomize;       dwidctl: dword; bchecked: bool): hresult; stdcall;     function oncontrolactivating(const pfdc: ifiledialogcustomize;       dwidctl: dword): hresult; stdcall;   end;  const    dwvisualgroup1id: dword = 1900;   function tmyfiledialogevents.onfileok(const pfd: ifiledialog): hresult; begin   result := e_notimpl; end;  function tmyfiledialogevents.onfolderchange(const pfd: ifiledialog): hresult; begin   result := e_notimpl; end;  function tmyfiledialogevents.onfolderchanging(const pfd: ifiledialog;   const psifolder: ishellitem): hresult; begin   result := e_notimpl; end;  function tmyfiledialogevents.onoverwrite(const pfd: ifiledialog;   const psi: ishellitem; out presponse: dword): hresult; begin   result := e_notimpl; end;  function tmyfiledialogevents.onselectionchange(const pfd: ifiledialog): hresult; begin   result := e_notimpl; end;  function tmyfiledialogevents.onshareviolation(const pfd: ifiledialog;   const psi: ishellitem; out presponse: dword): hresult; begin   result := e_notimpl; end;  function tmyfiledialogevents.ontypechange(const pfd: ifiledialog): hresult; begin   result := e_notimpl; end;  function tmyfiledialogevents.onitemselected(const pfdc: ifiledialogcustomize; dwidctl: dword; dwiditem: dword): hresult; begin   result := e_notimpl; end;  function tmyfiledialogevents.onbuttonclicked(const pfdc: ifiledialogcustomize; dwidctl: dword): hresult; begin   if dwidctl = dwvisualgroup1id begin     // ...     result := s_ok;   end else begin     result := e_notimpl;   end; end;  function tmyfiledialogevents.oncheckbuttontoggled(const pfdc: ifiledialogcustomize; dwidctl: dword; bchecked: bool): hresult; begin   result := e_notimpl; end;  function tmyfiledialogevents.oncontrolactivating(const pfdc: ifiledialogcustomize; dwidctl: dword): hresult; begin   result := e_notimpl; end; 

.

var   filedialog: ifiledialog = nil;   myevents: ifiledialogevents = nil;    myeventscookie: dword = 0;  procedure tform1.filesavedialog1execute(sender: tobject);  var    c: ifiledialogcustomize;    d: ifiledialogevents;    cookie: dword; begin    if supports(filesavedialog1.dialog, ifiledialogcustomize, c)    begin      // add advanced button      c.addpushbutton(dwvisualgroup1id, 'advanced');      c.makeprominent(dwvisualgroup1id);       // setup pushbutton click event      d := tmyfiledialogevents.create;      if succeeded(filesavedialog1.dialog.advise(d, cookie))     begin       filedialog := filesavedialog1.dialog       myevents := d;       myeventscookie := cookie;     end;   end;  end;  procedure tform1.button1click(sender: tobject);  var   ok: boolean; begin   filedialog := nil;   myevents := nil;    myeventscookie := 0;    try     ok := filesavedialog1.execute;       if (filedialog <> nil) , (myeventscookie <> 0)       filedialog.unadvise(myeventscookie);     filedialog := nil;     myevents := nil;      myeventscookie := 0;   end;    if ok ... end; 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -