>it relies on timing
The code in TimerProc function is executed asynchronously after the SetTimer call, which means that the TimerProc function is executed only after the file dialog is created, initialized and displayed on screen, no matter how long does it take.
>and worse yet "hopes" that only one dialog is open on the user's system at the time.
This will not make any difference. You can have any number of file open / save dialogs open on your system. The code targets the correct dialog belonging to the current application using GetActiveWindow function which is just created and displayed.
Further, the scope of the GetActiveWindow function is restricted to the calling thread by design, which further ensures that the function will not pick any wrong dialog box from other applications. I checked it with 10 file dialogs open in 10 different application and it worked fine.
As for FindWindow function, most of the flaws highlighted in the article, don't apply here due to the following reasons.
[li]We are using FindWindowEx, instead of FindWindow, with our search scope limited to a dialog box with known window hierarchy, instead of the whole desktop.[/li][li]We are not searching by window title, but class name, with only one window belonging to that class in the search scope.[/li]
There are chances in which the above code might fail.
For example, if in some future version of Windows, Microsoft do some extensive overhauling of File Open/Save dialog UI, or control class names or message arguments are changed. In such cases, FindWindowEx function or SendMessage function will fail.
I have already indicated that possibility in the original thread.
>it may not work on all versions of Windows.
However, it will not happen atleast under WinXP. In my opinion, the code is fairly safe to use for practical purposes.