Marko29
Marko29

Reputation: 1005

How to get readable classname and title from HWND handle? in WinApi c++

I am using the following enumchild proc to get hwnd of each window, the problem is that i am unable to somehow detect any info from each hwnd so i can do what i want with the ones that are detected as the ones i need.

For example, how could i get window class name and the title of each window in the enum bellow?

I tried something like..

EDITED: copy pasted(if that helps)

TCHAR cName[MAX_PATH];

BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) {


 TCHAR cName[MAX_PATH];
 GetClassName(hwnd, cName, _countof(cName));
  cout << cName << endl;

     return TRUE; 
}

int _tmain(int argc, _TCHAR* argv[])
{


    HWND hwnd = FindWindow(0, TEXT("reference"));
    EnumChildWindows(hwnd, EnumChildProc, 0);

    system("PAUSE");
 return 0;
}

It just returns the hexadec handle info and every single time it is same, shouldnt the GetClassName func change the cName into new handle each time?

Also GetClassName function returns number of chars written to cName, i dont really see how this is useful to me? I need to get my cName in some readable format so i can do something like

if(className == TEXT("classnameiamlookingfor" && hwndtitle = TEXT("thetitlethatinterestsme") DOSOMETHINGWITHIT();

But all i get here is hexadec mess.

Upvotes: 3

Views: 11330

Answers (1)

9dan
9dan

Reputation: 4272

Isn't it Unicode build?

Check again with below:

TCHAR className[MAX_PATH];
GetClassName(hwnd, className, _countof(cName));
_tprintf(cName);

Upvotes: 7

Related Questions