Thanks Peter,
Your suggestion on how to approach finding the OpenFileDialog's count of
items displayed in the listbox was most helpful.
Here is the solution I came up with just in case someone else wants to know
how to do this.
There is also an article in MSDN Magazine, January 2002, "C++ Q&A", by Paul
DiLascia, which shows how to work with the innards of the OpenFileDialog
using MFC.
Additional research indicates I could acces the count via the Accessibility
interface too.
Regards,
Bill Rogers
Explanation for my solution:
The goal is to get the count of items in the listbox shown in the
OpenFileDialog
The listbox of interest is actually a SyslistView32 contianed in a
SHELLDLL_DefView, contained in the OpenFileDialog
You can see this by opening the OpenFileDialog from a program and then
examining it with Spy++
First, using FindWindowEx, find the OpenFileDialog's main window (it must be
on the screen to do this)
The first argument to FindWindowEx is null, so it starts at the desktop
level - this is what you want because the
OpenFileDialog comes up as a top level window, not a child window of your
application
The ATOM specified here was found with Spy++
Next, find the SHELLDLL_DefView within this dialog, again using FindWindowEx
This time the first argument to FindWindowEx is the hWnd of the
OpenFileDialog so we limit the search to within just this dialog
The thing we are looking for has no caption so the only way we can find it
is by its ATOM - which was found via Spy++
The next step is to again use FindWindowEx to get the window handle of the
listbox (actually a SysListView32)
Again, the ATOM and caption were found using Spy++
Finally you get the count from the SyslistView32 by sending it a message via
SendMessage
I used the ListView_GetItemCount macro defined in Commctrl.h to do this
Error checking in this example is minimal...
#include <Commctrl.h>
hWnd hwnd1, hwnd2, hwnd3;
int count;
//...
//find the listbox in the file open dialog
//captions and atoms found with spy++
if (!(hwnd1 = FindWindowEx(0, 0, MAKEINTATOM(0x8002), L"Open"))) return
false; \\the file open dialog
if (!(hwnd2 = FindWindowEx(hwnd1, 0, MAKEINTATOM(0xC0CB), 0))) return false;
\\SHELLDLL_DefView
if (!(hwnd3 = FindWindowEx(hwnd2, 0, MAKEINTATOM(0xC043), L"FolderView")))
return false; \\SysListView32
count = ListView_GetItemCount(hwnd3);