2

I open an open file dialog using GetOpenFileName function. I'm making a handler function that will center the dialog window inside the owner window. I center the dialog on CDN_INITDONE notification.

Currently, it seems that Windows remembers last dialog position for desktop apps and overrides my dialog coordinates. How to reset that last remembered position so that I can check centering will work for my users?

I thought about running a test using a different user or virtual machine but this isn't very convenient. Unfortunately, searching in the registry for myexecutable.exe returns nothing.

I'm running Windows 8.

Ivan Nikitin
  • 3,578
  • 27
  • 39
  • 3
    Overriding the user's preference for where the dialog is located isn't exactly a great idea. It is not impossible, call PostMessage() before you show the dialog to post a message back to yourself. When you get it, find the dialog window back and put it where you want it. Sample code in [this answer](http://stackoverflow.com/a/2576220/17034). – Hans Passant Apr 14 '14 at 16:21
  • 1
    A CBT hook would get it done too – David Heffernan Apr 14 '14 at 17:47
  • @HansPassant I tried a similar approach: called SetWindowPos on dialog window after a second after its appearance. It seems that open file dialog ignores both SetWindowPos and MoveWindow method calls. Window handles (hwnd) are correct - checked their titles with GetWindowText. – Ivan Nikitin Apr 15 '14 at 10:43

1 Answers1

2

I'm about a year late, but I just had to deal with this issue. What worked for me was supplying an OFNHookProc to GetOpenFileName(), then subclassing the parent of the HWND passed to the OFNHookProc.

After subclassing, I handle WM_WINDOWPOSCHANGED, and if the coordinates aren't where I think they should be, I do a SetWindowPos(), undo the subclass and return 0.

Edit: I should say that other methods, such as WM_INITDIALOG in the hook proc or CDN_INITDONE did not work for me whatsoever.

Mark
  • 2,380
  • 11
  • 29
  • 49
aremmell
  • 1,151
  • 1
  • 10
  • 15