Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey guys,

i have a problem with the ListView_GetItemCount Macro from Microsoft.
It's just a macro for
C++
::SendMessage((hwnd), LVM_GETITEMCOUNT, 0, 0L)

When i send this message to my SysListView32 it always return 0.

Background:
I want to get the ttemcount from the ListCtrl Displayed in a FileOpenDlg (CCommonDlg).
I use this Code:
C++
HWND hwndParentDlg = ::GetParent( this->m_hWnd );
HWND hwndShellDllDefView = ::FindWindowEx( hwndParentDlg, NULL, "SHELLDLL_DefView", NULL );
HWND hwndSysListView = ::FindWindowEx( hwndShellDllDefView, NULL, "SysListView32", NULL );
INT nCount = ListView_GetItemCount( hwndSysListView );

but nCount is always set to 0.

I also googled and found this article at StackOverflow.
So i checked GetLastError(), but it return zero too.

What i'm doing wrong here?
Can anyone help me please?

Thank you so much guys for your answers!
best regards from Germany :)
Posted
Comments
Jochen Arndt 19-Feb-14 3:23am    
Did you check the returned HWNDs? It seems that you did not get the HWND of the list control.

There is an rather old article on customizing the Open File Dialog:
http://www.codeproject.com/Articles/29/Customizing-the-Windows-Common-File-Open-Dialog
Maybe this helps you to identify the list control window.
C3D1 19-Feb-14 3:35am    
I verifed the HWNDS by setting a breakpoint at the top of my function, stepp trough all relevant lines and copy all HWND values to notepad.
Then i return back to my application and check the handle values using Spy++.
All HWNDs should was ok.

I tested the macro at this sample project: http://www.codeproject.com/Articles/5782/Implementing-a-Read-Only-File-Open-or-File-Save-Co at the CDN_FOLDERCHANGE Message after the HWNDs are detected.
Same here, it return 0.
Jochen Arndt 19-Feb-14 4:12am    
You can try to access the list control by the ID. The IDs of the common dialogs are defined in the dlgs.h SDK header file. The list control has ID lst1 or lst2 (I'm not sure).

Did you use MFC (CFileDialog)?
The implementation of the CFileDialog dialog has been changed with Vista. This may be the reason that old examples written for Win9x/NT/2K/XP will not work anymore.
C3D1 19-Feb-14 4:19am    
Thank's for the advice with the IDs.
I will give it a try!

Yes, i/we use MFC, but not the CFileDialog directly.
It's a CCommonDlg derviated class and in DoModal() the co-worker, who has written the class, call GetSaveFileName() or GetOpenFileName.

The main goal of my modification/customation can be found here: http://www.codeproject.com/Questions/719055/CCommonDlg-how-to-scroll-automaticly
Jochen Arndt 19-Feb-14 4:50am    
For the IDs see 'Explorer-Style Control Identifiers' at:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646960%28v=vs.85%29.aspx

Just a suggestion:
Try if you can use the CFileDialog class or the new IFileDialog class. Then you don't have to deal with the old common dialog.

1 solution

My code works great.
The problem is that i'm trying to get the ItemCount at the wrong place.
When the message CDN_FOLDERCHANGE is sent the ListBox isn't filled.

I have to look for an other place where i can put my code into.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900