/* * Name: Simple Window Information Inspector * Description: * This program shows the window information hierarchy from the current * cursor position one time per second. Press Ctrl+C to quit. * Author: Katayama Hirofumi MZ * License: The MIT License * Copyright (C) 2013 Katayama Hirofumi MZ */ #include #include /* get the depth from a child window */ INT GetDepth(HWND hwnd, INT nLevel) { HWND hwndParent = GetParent(hwnd); if (hwndParent != NULL) { return GetDepth(hwndParent, nLevel + 1); } return nLevel; } /* inspect window information */ VOID InspectWindowInfo(HWND hwnd, INT nDepth) { WCHAR szClass[32], szText[32], szBuff[MAX_PATH]; CHAR szAnsi[MAX_PATH]; DWORD style; HWND hwndParent; INT i; /* recurse the ancestor windows */ hwndParent = GetParent(hwnd); if (hwndParent != NULL) { InspectWindowInfo(hwndParent, nDepth - 1); } /* get class name */ GetClassNameW(hwnd, szClass, 32); szClass[32 - 1] = 0; /* get window text */ GetWindowTextW(hwnd, szText, 32); szText[32 - 1] = 0; /* get window style */ style = GetWindowLong(hwnd, GWL_STYLE); /* indent */ for (i = 0; i < nDepth; i++) { printf(" "); } /* do output */ wsprintfW(szBuff, L"HWND:0x%08X, CLASS:\"%s\", TEXT:\"%s\", STYLE:0x%08X\n", (DWORD)hwnd, szClass, szText, style); WideCharToMultiByte(CP_ACP, 0, szBuff, -1, szAnsi, MAX_PATH, NULL, NULL); printf("%s", szAnsi); } /* the main function */ VOID main(VOID) { /* the position */ POINT pt; /* window handles */ HWND hwnd, hwndChild; /* flags for ChildWindowFromPointEx */ UINT uCWP_ = CWP_SKIPINVISIBLE | CWP_SKIPTRANSPARENT; /* infinite loop */ for (;;) { /* get current cursor position */ GetCursorPos(&pt); /* do output a separator */ printf("--------------------------\n"); /* get the top-level window from the cursor position */ hwnd = WindowFromPoint(pt); /* get the deepest descendant window from the cursor position */ for (;; hwnd = hwndChild) { /* get the child window of the specified window from the position */ hwndChild = ChildWindowFromPointEx(hwnd, pt, uCWP_); /* end if no other child window found */ if (hwndChild == NULL || hwnd == hwndChild) break; /* convert the position */ MapWindowPoints(hwnd, hwndChild, &pt, 1); } /* inspect window information */ InspectWindowInfo(hwnd, GetDepth(hwnd, 0)); /* wait one second */ Sleep(1000); } }