简体   繁体   English

如何从HWND句柄获取可读的类名和标题? 在WinApi c ++中

[英]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. 我使用以下enumchild proc获取每个窗口的hwnd,问题是我无法以某种方式检测每个hwnd的任何信息,所以我可以做我想要的那些被检测为我需要的那些。

For example, how could i get window class name and the title of each window in the enum bellow? 例如,我怎么能得到窗口类名称和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? 它只返回十六进制句柄信息,并且每次都相同,GetClassName func不应该每次都将cName更改为新句柄吗?

Also GetClassName function returns number of chars written to cName, i dont really see how this is useful to me? 另外GetClassName函数返回写入cName的字符数,我真的不知道这对我有用吗? I need to get my cName in some readable format so i can do something like 我需要以一些可读的格式获取我的cName,这样我就可以做类似的事情

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

But all i get here is hexadec mess. 但我得到的只是十六进制混乱。

Isn't it Unicode build? 是不是Unicode构建?

Check again with below: 再次检查以下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM