How to reset the starting position of FileDialog

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?

Thanks,
     Michael
gem56Asked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
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...
0
 
Meir RivkinFull stack Software EngineerCommented:
u can create a custom openfile dialog in vb6 and pass in the ctor starting position of the dialog.
0
 
Meir RivkinFull stack Software EngineerCommented:
check this code: http://ccrp.mvps.org/index.html?controls/ccrpfiledlg6.htm

just download and twick the code for your needs.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
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);
0
 
Meir RivkinFull stack Software EngineerCommented:
to see what parameters to pass to SetWindowPos, check http://www.pinvoke.net/default.aspx/user32.SetWindowPos
0
 
gem56Author Commented:
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.
0
 
gem56Author Commented:
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.

Thanks
0
 
gem56Author Commented:
Thanks a lot.
0
All Courses

From novice to tech pro — start learning today.