Solved

Hot to control the size of tOpenDialog and tSaveDialog

Posted on 2004-08-02
15
481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 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