EnumChildWindows and a SysListView32

This is a discussion on EnumChildWindows and a SysListView32 within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'm trying to make a program that gets a list of contacts in an instant messenger from a SysListView32 ...

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230

    EnumChildWindows and a SysListView32

    Hi, I'm trying to make a program that gets a list of contacts in an instant messenger from a SysListView32 list box. The problem is:

    #1 My code says there are 4 contacts (items in the list) when in reality there is only 2 (1 contact and a contact group).

    #2 It isn't getting the list text with what I have now, and all the other macros to work with this list box aren't doing anything to the list box or interacting with the messenger in any way, shape, or form.

    I'm relatively new to WinApi, and I've never used EnumChildWindows() or the callback that's used with it before, so chances are I'm doing something wrong. Basically, before you recommend it, a FindWindowEx() child/parent traversal is not an option, and there's a reason for this, this code needs to support multiple messenger versions, and the parent window SysListView32 belongs to is randomly named across different versions.

    So basically, what I'm trying to do is get a handle to the parent window ("TabListManager" - which is a child of "TopWindow"), and pass it to EnumChildWindows(), so it calls the callback, until "SysListView32" is found (and there is only 1 of these that is a child (of a child etc) to TabListManager. Once it's found, a global Window handle is assigned to it, so I can use it.

    Even know the global handle is now a handle to the SysListView32 and there's 2 entries into that (judging on what's said in the messenger and Winspector) it prints 4 with the ListView_GetItemCount macro.

    And the loop to print the items in the list doesn't work either... Just the array's null terminators are printed.

    Any help would be appreciated, I'm sorry if I've left anything out and I'm sorry if I went a bit too in-depth, here's the code:

    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <commctrl.h>
    
    HWND hList;
    
    BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) {
    	
    	hList = FindWindowEx(hwnd, NULL, "SysListView32", NULL);
    
    	if (!hList)
    		return TRUE;
    	
    	MessageBox(NULL, "FOUND SysListView32", "found", MB_ICONINFORMATION);
    	return FALSE;
    }
    
    
    int main() {
    	
    	HWND hMain, hChild;
    	int list = 0;
    	
    	hMain = FindWindow("MainWindow", NULL);
    
    	if (!hMain) {
    		MessageBox(NULL, "not running program", "error", MB_ICONINFORMATION);
    		return 0;
    	}
    	
    	hChild = FindWindowEx(hMain, NULL, "TopWindow", NULL);
    	hChild = FindWindowEx(hChild, NULL, "TabListManager", NULL);
    	
    	EnumChildWindows(hChild, &EnumChildProc, NULL); 
    
    	list = ListView_GetItemCount(hList);
    
    	char buffer[256] = { '\0' };
    
    	for (int i = list; i > 0; i--) {
    		ListView_GetItemText(hList, i - 1, 0, buffer, 255);
    		printf("contact: %s\n", buffer);
    	}
    
    	printf("Number of contacts: %d\n", list);
    
        return 0;
    }
    Thanks for your time!

    P.S I have no idea what lParam is used for. It doesn't really say anything at all on MSDN.
    Last edited by pobri19; 02-01-2009 at 02:57 AM.
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    I'm sorry if I've left anything out and I'm sorry if I went a bit too in-depth,
    How about the name of the instant messenger that you are using?

    I noticed you have this same post on CodeGuru. So, I'll post any relevent code and information on that forum.

  3. #3
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    It's for Yahoo messenger. Oh and yeah, it's kind of urgent so I was looking for answers elsewhere as well. Doesn't seem like many people have a solution for this =)
    Last edited by pobri19; 02-02-2009 at 12:58 AM.
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  4. #4
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Problem solved. Thanks.
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21