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.