?
Solved

Save window position and settings of a TOpenDialog

Posted on 2002-04-08
18
Medium Priority
?
505 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
[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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 46

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
 
LVL 46

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 600 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 46

Expert Comment

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

Accepted Solution

by:
aikimark earned 600 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 46

Assisted Solution

by:aikimark
aikimark earned 600 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 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