Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

Save window position and settings of a TOpenDialog

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
krazy6284
Asked:
krazy6284
  • 6
  • 5
  • 5
  • +2
3 Solutions
 
jswebyCommented:
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
 
jswebyCommented:
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
 
krazy6284Author Commented:
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
Technology Partners: 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!

 
jswebyCommented:
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
 
ginsonicCommented:
listening
0
 
jswebyCommented:
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
 
krazy6284Author Commented:
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
 
aikimarkCommented:
try the IniOut property manager from Robert Vivrette on the UNDU site:
http://www.undu.com/LIBS/IniOutD6.zip
0
 
krazy6284Author Commented:
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
 
aikimarkCommented:
Here is the link to the D4-compatable IniOut component:
http://www.undu.com/LIBS/Inioutsc.zip
0
 
krazy6284Author Commented:
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
 
jswebyCommented:
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
 
krazy6284Author Commented:
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
 
aikimarkCommented:
I've asked the IniOut component author, Robert Vivrette, about these properties.
0
 
aikimarkCommented:
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
 
krazy6284Author Commented:
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
 
aikimarkCommented:
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
 
pnh73Commented:
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 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.

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