c 获取 windows 显示的窗口列表


#include <Windows.h>

HWND list[200] = {0};
INT length = 0;

BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
{
	if(IsWindowVisible(hwnd))
	{
		list[length] = hwnd;
		length++;
	}
	return TRUE;
}

int main()
{
	int i;
	CHAR buffer[256] = {0};
	CHAR text[2046] = {0};

	// 获取桌面的句柄
	HWND hExplorer = FindWindow("explorer.exe", NULL);
	// 获取子窗口
	EnumChildWindows(
		hExplorer ,		// 桌面的句柄
		EnumChildProc,	// 获取到某个窗口句柄时的回调函数
		NULL			// 传给回调函数的值
	);

	for (i = 0; i < length; i++)
	{
		ZeroMemory(buffer, 256);
		// 获取标题
		GetWindowText(list[i], buffer, 256);
		wsprintf(text, "%s%d.%sn", text, i, buffer);				
	}	
	// 显示
	MessageBox(NULL, text, NULL, MB_OK);
}

window_list

Advertisements

2 thoughts on “c 获取 windows 显示的窗口列表

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

w

Connecting to %s