2007. október 29., hétfő

How to change the directory while a TOpenDialog is open


Problem/Question/Abstract:

I have created an extra TSpeedButton on my TOpenDialog and would like to change the active directory if the user clicks it. If I change the current directory, nothing happens.

Answer:

{ ... }
hDlg := GetForeGroundWindow;
repeat
  {Sending the path. Try until the dialog has received it}
  SendDlgItemMessage(hDlg, 1152, WM_SETTEXT, 0, Integer(PChar(sDir)));
  L := SendDlgItemMessage(hDlg, 1152, WM_GETTEXTLENGTH, 0, 0);
  Application.ProcessMessages;
  if Application.Terminated then
    Exit;
until
L <> 0;
{And now click OK}
SendMessage(hDlg, WM_COMMAND, 1 + BN_CLICKED * $10000, GetDlgItem(hDlg, 1));
{Clear}
SendDlgItemMessage(hDlg, 1152, WM_SETTEXT, 0, Integer(PChar('')));
{ ... }

Nincsenek megjegyzések:

Megjegyzés küldése