Solved

Hot to control the size of tOpenDialog and tSaveDialog

Posted on 2004-08-02
15
468 Views
Last Modified: 2011-09-20
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
Comment
Question by:Treppenmeister
  • 9
  • 5
15 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11695289
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
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 11696297
Something like this?

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

Author Comment

by:Treppenmeister
ID: 11701047
@ 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
 
LVL 14

Accepted Solution

by:
DragonSlayer earned 500 total points
ID: 11702166
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
 

Author Comment

by:Treppenmeister
ID: 11703831
@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
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 11707807
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
 

Author Comment

by:Treppenmeister
ID: 11712587
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Treppenmeister
ID: 11712656
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
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 11712710
Delphi 5 Ent, English version.

Which doesn't work? The EditBox or the ComboBox???
0
 

Author Comment

by:Treppenmeister
ID: 11712813
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
 

Author Comment

by:Treppenmeister
ID: 11712893
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
 

Author Comment

by:Treppenmeister
ID: 11712929
The problem is solved. Using Delphi 7 then I have to replace edt1 with cmb13. then all works fine. Thanks for the help.
0
 

Author Comment

by:Treppenmeister
ID: 11713147
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
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 11713441
u mean, u want the dialog box to be of a smaller size than the original dialog box?
0
 

Author Comment

by:Treppenmeister
ID: 11714759
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now