[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 489
  • Last Modified:

Hot to control the size of tOpenDialog and tSaveDialog

Hi,
When I am using tOpenDialog and tSaveDialog in my application then the dialogs have a standard size the first time I use them. After resizing one of them to a new size then they open with that 'user defined size' as long as the application is running. Unfortunately Windows makes no difference between Open and Save.
I want to have for instance an OpenDialog with a preview with a size of 800x600 and a SaveDialog of 600x350.
How I can set the size of the Dialogs? I have in mind to set the size while the application is running.
0
Treppenmeister
Asked:
Treppenmeister
  • 9
  • 5
1 Solution
 
Wim ten BrinkCommented:
AFAIK, these are Windows-specific controls that don't allow much modifications from the outside. The easiest solution is simple: build your own dialogs to open/safe files. Delphi has enough useful controls to do this.
The other option is to go deep in the Windows API, trying to find which message you must send to the dialog handle, hoping that such a message even exists...

Basically, I'd say: Create a new form, drop the nice Shell components on it that Delphi 7 provides, with a nice edit-box and a few lables and you're done...
0
 
DragonSlayerCommented:
Something like this?

procedure TForm1.OpenDialog1Show(Sender: TObject);
begin
  SetWindowPos(GetParent(OpenDialog1.Handle), 0, 1, 1, 800, 600, SWP_DRAWFRAME);
end;
0
 
TreppenmeisterAuthor Commented:
@ DragonSlayer:

It is possible to change the size of the DialogWindow with SetWindowPos or MoveWindow - but the problem with these functions is, that the components within the dialogbox aren't changing the size according to the new dialogbox size.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DragonSlayerCommented:
Ok, here's a quick and dirty example. Notice the -22 padding to the Y pos. I guess it's the offset for the toolbar height of the open dialog, but I don't have time to investigate further. Perhaps you would want to look into getting the toolbar height dynamically as well.

uses
  dlgs;

procedure TForm1.OpenDialog1Show(Sender: TObject);
const
  iControlCount = 7;
  childControl: array [0 .. iControlCount - 1] of Integer = (
    stc3, stc2,
    edt1, cmb1,
    IDOK, IDCANCEL,
    lst1
  );
var
  hOpenDlg: HWND;
  hDlgChild: HWND;
  Rect1: TRect;
  i: Integer;
  ExtraWidth, ExtraHeight: Integer;
begin
  hOpenDlg := GetParent(OpenDialog1.Handle);
  GetWindowRect(hOpenDlg, Rect1);
  ExtraWidth := 800 - (Rect1.Right - Rect1.Left);
  ExtraHeight := 600 - (Rect1.Bottom - Rect1.Top);
  SetWindowPos(GetParent(OpenDialog1.Handle),
    0, 1, 1, 800, 600, SWP_NOREPOSITION);

  for i := 0 to iControlCount - 1 do
  begin
    hDlgChild := GetDlgItem(hOpenDlg, childControl[i]);
    GetWindowRect(hDlgChild, Rect1);
    if (childControl[i] = stc2) or (childControl[i] = stc3) then
    begin
      // labels... only change the Y pos
      SetWindowPos(hDlgChild, 0,
        Rect1.Left, Rect1.Top + ExtraHeight - 22,
        0, 0, SWP_NOSIZE);
    end else
    if (childControl[i] = IDOK) or (childControl[i] = IDCANCEL) then
    begin
      // as for the buttons, we need to change X and Y pos
      SetWindowPos(hDlgChild, 0,
        Rect1.Left + ExtraWidth,
        Rect1.Top + ExtraHeight - 22,
        0, 0, SWP_NOSIZE);
    end else
    if (childControl[i] = edt1) or (childControl[i] = cmb1) then
    begin
      // textbox and combobox, need to change Y pos
      // as well as change the width
      SetWindowPos(hDlgChild, 0,
        Rect1.Left, Rect1.Top + ExtraHeight - 22,
        Rect1.Right - Rect1.Left + ExtraWidth,
        Rect1.Bottom - Rect1.Top,
        SWP_FRAMECHANGED);
    end else
    if (childControl[i] = lst1) then
    begin
      // listview will need both the height and width
      // extended, but need not be moved
      SetWindowPos(hDlgChild, 0,
        0, 0,
        Rect1.Right - Rect1.Left + ExtraWidth,
        Rect1.Bottom - Rect1.Top + ExtraHeight,
        SWP_NOMOVE);
    end;
  end;
end;


DragonSlayer.
0
 
TreppenmeisterAuthor Commented:
@DragonSlayer:
That works so far after some custom changes - but I have the problem, that I cannot change the position of the editbox1. All other components are at the right position now.
SetWindowPos gives me as an result a false. I also changed from  SWP_FRAMECHANGED to SWP_NOSIZE (since I have only problems with the positioning in the height.Thats why I had to modify all a little bit).
 
0
 
DragonSlayerCommented:
it works well for me... did you copy and paste my code exactly? Perhaps there were some errors while you were retyping the code...
0
 
TreppenmeisterAuthor Commented:
I copied it as it is. All works fine except the Editbox (Combobox) with the selected filename. What operation system you are working with? I have here Windows 2000. I will check later whether it would work with XP.
0
 
TreppenmeisterAuthor Commented:
So - I checked now all also with Windows XP. The same problem. What could be the reason?
The program was compiled with a german Delphi 7 and running under a german Win2k SP4 and WinXP SP1. What did you use?
0
 
DragonSlayerCommented:
Delphi 5 Ent, English version.

Which doesn't work? The EditBox or the ComboBox???
0
 
TreppenmeisterAuthor Commented:
The Combobox with the filetyp-filter works (its a combobox with csDropDownList style). But the Combobox for the filename (its a combobox with csDropDown style) does not want to move. In your code you write about an editbox - but in my opinion it is a combobox. But I tried to move edt1, edt2 as far as cmb1, cmb2, cmb3, cmb4 - but no change. How is the windows-logic - if there is no cmb3 - can there be a cmb4?
0
 
TreppenmeisterAuthor Commented:
I installed now an english Delphi 5 Pro. Now there is an Editbox in the OpenDialog for the filename and your code is working.
Why there is such a damned difference in the Dialogs between Delphi 5 and 7 ?
0
 
TreppenmeisterAuthor Commented:
The problem is solved. Using Delphi 7 then I have to replace edt1 with cmb13. then all works fine. Thanks for the help.
0
 
TreppenmeisterAuthor Commented:
Unfortunately the problem is not really solved. The positioning works fine - but the resizing of the components and also the dialogwindow works only, when I increase the size.  SetWindowPos does not want to decrease the size of the ListBox or the mainwindow of the tOpenDialog.
0
 
DragonSlayerCommented:
u mean, u want the dialog box to be of a smaller size than the original dialog box?
0
 
TreppenmeisterAuthor Commented:
I opened the opendialog box and set it to a size of 800x600. When I resize it with the mouse (as the user) to 1000x800
and close the dialogbox and open it again, then I get the 1000x800 and not the 800x600 as I wanted.  
The same happens, when I open at first the bigger OpenDialog and open later the smaller SaveDialog.

It looks so whether the Dialog will be resized after the onShow to the bigger size.

So I defined now a timer and I get the size I want (the one I set in the OnShow):

procedure tForm1.Timer_RepositionSaveDialogTimer(Sender: TObject);
begin
  Timer_RepositionSaveDialog.Enabled := false;
  SetWindowPos( GetParent( SaveDialog.Handle ), 0,
                1, 1, 1, 1, SWP_NOMOVE      );
end;

It is not very elegant - but I have no idea how to solve it otherwiese.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now