How to reset the starting position of FileDialog

Posted on 2010-01-11
Medium Priority
Last Modified: 2012-05-08
Hi guys,

I have a VB6 application that interacts with a VB.NET application by sending it 'MOUSEMOVE, BUTTONDOWN, etc.' events and all is working OK except for one thing.

Sometimes the sent events result in VB.NET application opening a FileDialog and my problem is that dialog position & size can change, depending on whether user had altered those manually. If that happens then subsequent mouse movement and button clicks could be misdirected due to FileDialog being in wrong place.

To resolve that issue I'd like to restore FileDialog default opening position & size at the start of those event so when opened it will always be in a known position and (default) size. So my question is how can I get & set opening position of a FileDialog to default values from the VB6 application?

Question by:gem56
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
  • 4
  • 3
LVL 42

Expert Comment

ID: 26293006
u can create a custom openfile dialog in vb6 and pass in the ctor starting position of the dialog.
LVL 42

Expert Comment

ID: 26293020
check this code: http://ccrp.mvps.org/index.html?controls/ccrpfiledlg6.htm

just download and twick the code for your needs.
LVL 86

Accepted Solution

Mike Tomlinson earned 1000 total points
ID: 26293189
Use FindWindow()/FindWindowEx() or EnumWindows() to SEARCH for the dialog.  Then you can pass that to GetWindowRect() and get the actual location of the window.  Now compute location mouse positions/clicks as offsets relative to the upper left of the dialog...

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 42

Assisted Solution

sedgwick earned 1000 total points
ID: 26293727
u can also use SetWindowPos to set the dialog location (and size).
i used GetWindowText to compare with the OpenFileDialog title and when u have the handle, u can set its new location by calling SetWindowPos:

  [DllImport("user32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
SetWindowPos(hDialog, IntPtr.Zero, Screen.PrimaryScreen.Bounds.X + 100, Screen.PrimaryScreen.Bounds.Y + 100, 500, 500, 0x0040);
LVL 42

Expert Comment

ID: 26293743
to see what parameters to pass to SetWindowPos, check http://www.pinvoke.net/default.aspx/user32.SetWindowPos

Author Comment

ID: 26303380
Thank you all for your suggestions.

I find each suggestion usefull, with some pro's and con's for what I'm trying to achieve overall, so I'll just play a bit with what you've suggested and see which combination works out best and award the points (shortly).

P.S. sedgwick, the link you gave above "http://ccrp.mvps.org/index.html?controls/ccrpfiledlg6.htm" doesn't work.

Author Comment

ID: 26346179
Hi guys,

I've incorporated both of your suggestions into my solution (and will split the points) with everything working great except for one thing, for which I've opened another question "http://www.experts-exchange.com/Programming/Misc/Q_25065819.html" and welcome your comments.


Author Closing Comment

ID: 31675960
Thanks a lot.

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 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