Solved

Save window position and settings of a TOpenDialog

Posted on 2002-04-08
18
451 Views
Last Modified: 2010-04-04
I am looking for an example or some source on how I can save the window position/size, and ListView style of a TOpenDialog.

Each time the TOpenDialog is executed it resets this information and I would like for it to remember it.

Surely there must be a way?
0
Comment
Question by:krazy6284
  • 6
  • 5
  • 5
  • +2
18 Comments
 
LVL 4

Expert Comment

by:jsweby
ID: 6925222
This is from the borland.public.delphi.winapi group:

-----------------------------------
The problem here is that the VCL code responsible for centering the dialog is executed after the DoShow method (which fires the OnShow event). You did not mention where you have placed the code to change the window dimensions, but with a standard TOpenDialog the following works in the OnShow event:

procedure TForm1.OpenDialog1Show(Sender: TObject);
var
  r: TRect;
begin
  with sender as topendialog do begin
    GetWIndowRect( GetParent( handle ), r );
    MOveWindow( GetParent( handle ),
                10, 10, r.right-r.left,
                r.bottom-r.top, true );
    Abort;
  end;
end;

The Abort prevents the WM_NOTIFY message that triggered the OnShow event from reaching the dialogs original window proc, which would pass it to the ExplorerHook function in dialogs.pas, which does the centering if the
notification is CBN_INITDONE.
-----------------------------------

You can save your settings in an INI file and then use them to set the rectangle's position.

I haven't yet found how to change the View.

J.
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6925242
From the same newsgroup:

You can change the ViewStyle after OnShow (OnShow is to early, the
ListView isn't yet created at that time). Note that this does _not_
change to Toolbar buttons accordingly.
type
  TForm1 = class(TForm)
    OpenDialog1: TOpenDialog;
    procedure OpenDialog1Show(Sender: TObject);
  private
    procedure WMUser(var Message: TMessage); message WM_USER;
  end;

procedure TForm1.OpenDialog1Show(Sender: TObject);
var
  Dlg: HWND;
begin
  Dlg := GetParent((Sender as TOpenDialog).Handle);
  PostMessage(Handle, WM_USER, Dlg, 0);
end;

procedure TForm1.WMUser(var Message: TMessage);
var
  Dlg: HWND;
  Ctrl: HWND;
  Style: Cardinal;
begin
  Dlg := Message.WParam;
  Ctrl := FindWindowEx(Dlg, 0, 'SHELLDLL_DefView', nil);
  if Ctrl = 0 then exit;
  Ctrl := FindWindowEx(Ctrl, 0, 'SysListView32', nil);
  if Ctrl = 0 then exit;
  Style := GetWindowLong(Ctrl, GWL_STYLE);
  Style := (Style and not LVS_TYPEMASK) or LVS_REPORT;
  SetWindowLong(Ctrl, GWL_STYLE, Style);
end;

J.
0
 

Author Comment

by:krazy6284
ID: 6925347
Hello jsweby,

Thanks for the information.

The first part seems to work fairly well, Though if I use MoveWindow() to resize the dialog the controls on the dialog are not resized.

Setting the listview style to LVS_REPORT does not appear to work correctly, setting it to LVS_ICON seems works so I suspect there's more to it then that.
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6925356
OK, I hadn't actually tried it, just found the articles that appeared to be of most use to you. I've looked for some more on this but couldn't find anything else

J.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6925682
listening
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6925700
If the suggestion for changing the view of the files in nearly right, try running WinSight that comes with Delphi to determine the Windows messages and control names that you might need to do this.

J.
0
 

Author Comment

by:krazy6284
ID: 6926581
Hello jsweby,

Thanks for the information.

The first part seems to work fairly well, Though if I use MoveWindow() to resize the dialog the controls on the dialog are not resized.

Setting the listview style to LVS_REPORT does not appear to work correctly, setting it to LVS_ICON seems works so I suspect there's more to it then that.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 6926598
try the IniOut property manager from Robert Vivrette on the UNDU site:
http://www.undu.com/LIBS/IniOutD6.zip
0
 

Author Comment

by:krazy6284
ID: 6927582
Hrmm that is odd. I wonder how my reply ended up twice.

Anyways.. I tried to try that component but I cant get it to work. I use Delphi 4 :)
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

 
LVL 45

Expert Comment

by:aikimark
ID: 6928041
Here is the link to the D4-compatable IniOut component:
http://www.undu.com/LIBS/Inioutsc.zip
0
 

Author Comment

by:krazy6284
ID: 6930843
I installed InOut and and got it working. Though it doesn't look like it will help me. It only saves the published properties of a component. I'm trying to save/restore properties that are not part of the component.
0
 
LVL 4

Assisted Solution

by:jsweby
jsweby earned 150 total points
ID: 6930906
Have you tried looking in the Win API help under the section "List View Window Styles" to see if there any other params that you need to set with LVS_xxx?

J.
0
 

Author Comment

by:krazy6284
ID: 6931360
I can set the style/position when creating the window. Thanks to the code posted by jsweby.

However I need a way to get the listview style when the window is closing the problem is that by the time onClose is triggered the listview no longer exists.

I've been messing around with subclassing the listview but it would appear that when you change folders the listview re-created, which causes problems.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 6931386
I've asked the IniOut component author, Robert Vivrette, about these properties.
0
 
LVL 45

Accepted Solution

by:
aikimark earned 150 total points
ID: 6934498
Robert Vivrette replied:
"Yep... That was a limitation on the component. I would recommend using the FormStorage component in rxLib. Much more robust."

Robert is the former editor of the UNDU website and is a master component builder.  I trust his recommendations.
0
 

Author Comment

by:krazy6284
ID: 6934925
Well this isn't a standard delphi form, it's a windows dialog, Open dialog to be specific. I am familar with rxlib and I really don't see FormStorage will solve my problem.
0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 150 total points
ID: 6935336
I think what you will need to do is inspect the properties of the dialog control and save them to the INI file.  Later you can read the contents of the INI file and set the associated dialog property values before showing the dialog.
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9002990
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split between aikimark and jsweby

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

12 Experts available now in Live!

Get 1:1 Help Now