A quirk regarding what happens when you dismiss a file dialog has become evident in the beta testing of my Shadow Analysis macro. I am using a standard Delphi TOpenDialog here, so this may be a Delphi question rather than a specific D4D question, but I am wondering if anybody can offer any suggestions or alternate way of doing things ....
I am not using any of the D4D supplied GetFlName procedures because they can't display a custom prompt (the prompt parameter is a line number referencing the DCADWIN.msg file, which makes them unusable for most macros where you would want to display your own prompt).
Although DataCAD is obviously the active window before the macro displays the file dialog, once the dialog is dismissed the previous window seems to become active (e.g. if I had a Windows Explorer window active immediately before switching to DataCAD and then execute a file dialog from my D4D macro, Windows Explorer window becomes the active window once the file dialog is dismissed (whether by pressing OK or Cancel)).
I have coded a workaround to this where I get DataCADs handle before displaying the file dialog and then I move Datacad back to the top window afterwards. This works, but the other window (Windows Explorer in the above example) flashes up briefly after exiting the file dialog and before DC becomes the top window again. My code to do this is pasted below .... Just wondering if anybody can suggest a better solution (e.g. should I pass some parameter other than Application to the TOpenDialog.Create procedure) ?
I am not using any of the D4D supplied GetFlName procedures because they can't display a custom prompt (the prompt parameter is a line number referencing the DCADWIN.msg file, which makes them unusable for most macros where you would want to display your own prompt).
Although DataCAD is obviously the active window before the macro displays the file dialog, once the dialog is dismissed the previous window seems to become active (e.g. if I had a Windows Explorer window active immediately before switching to DataCAD and then execute a file dialog from my D4D macro, Windows Explorer window becomes the active window once the file dialog is dismissed (whether by pressing OK or Cancel)).
I have coded a workaround to this where I get DataCADs handle before displaying the file dialog and then I move Datacad back to the top window afterwards. This works, but the other window (Windows Explorer in the above example) flashes up briefly after exiting the file dialog and before DC becomes the top window again. My code to do this is pasted below .... Just wondering if anybody can suggest a better solution (e.g. should I pass some parameter other than Application to the TOpenDialog.Create procedure) ?
Code: Select all
dchandle := GetForegroundWindow; // get DataCADs handle so it can be moved back to the top when file dialog exits
openDialog := TOpenDialog.Create(Application);
openDialog.Filter := 'Excel Files|*.xlsx|Comma Separated Values|*.csv';
getpath (dir, pathcad);
.. <snip> ..
openDialog.InitialDir := string(dir);
openDialog.FileName := string(fil);
openDialog.Title := 'Default Output File';
res := openDialog.Execute;
SetWindowPos(dchandle, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); // return to DataCAD ... for some reason it doesn't do this automatically
David Henderson
dhSoftware - Add-on Macros for DataCAD
dhSoftware - Add-on Macros for DataCAD