FindWindow 带有部分窗口标题(Windows,C)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1268314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FindWindow with partial window title (Windows, C)
提问by wonderer
Is there any API similar to FindWindow() but that searches the windows by partial title? The reason is that I need to the handle to a window that has a fix part on the title but the other part changes constantly. So for example the window title could be:
是否有任何类似于 FindWindow() 的 API,但它通过部分标题搜索窗口?原因是我需要处理标题上有固定部分但另一部分不断变化的窗口的句柄。例如,窗口标题可以是:
DataBase read: XYDB
数据库读取:XYDB
or
或者
DataBase read: WZDB
数据库读取:WZDB
in the examples the fix part is "DataBase read:"
在示例中,修复部分是“数据库读取:”
Code appreciated. Thanks
代码赞赏。谢谢
回答by arul
An example using EnumWindows:
使用 EnumWindows 的示例:
BOOL CALLBACK WorkerProc(HWND hwnd, LPARAM lParam) {
static TCHAR buffer[50];
GetWindowText(hwnd, buffer, 50);
if(_tcsstr(buffer, "window name goes here")) {
// do something with hwnd here
return FALSE;
}
return TRUE;
}
And then call it like this:
然后像这样调用它:
EnumWindows(WorkerProc, NULL);