Diaglib: Fix and extend dumping of native windows (Windows).
When recursing over the windows, the code did not take into account that EnumChildWindow enumerates grand children as well. Exclude those by checking for the direct parent in the recursion so that the hierarchy is printed correctly. Add more information about class and module and rearrange the output a bit so that the window title is more prominent. Task-number: QTBUG-50206 Change-Id: Iffb12c44eda9d09da5eb14a8405aee52ed3aa849 Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
This commit is contained in:
parent
89293e6b19
commit
f186c4a819
@ -48,9 +48,10 @@
|
||||
namespace QtDiag {
|
||||
|
||||
struct DumpContext {
|
||||
DumpContext() : indentation(0) {}
|
||||
DumpContext() : indentation(0), parent(0) {}
|
||||
|
||||
int indentation;
|
||||
HWND parent;
|
||||
QSharedPointer<QTextStream> stream;
|
||||
};
|
||||
|
||||
@ -64,11 +65,19 @@ static void formatNativeWindow(HWND hwnd, QTextStream &str)
|
||||
RECT rect;
|
||||
if (GetWindowRect(hwnd, &rect)) {
|
||||
str << ' ' << (rect.right - rect.left) << 'x' << (rect.bottom - rect.top)
|
||||
<< '+' << rect.left << '+' << rect.top;
|
||||
<< forcesign << rect.left << rect.top << noforcesign;
|
||||
}
|
||||
if (IsWindowVisible(hwnd))
|
||||
str << " [visible]";
|
||||
|
||||
wchar_t buf[512];
|
||||
if (GetWindowText(hwnd, buf, sizeof(buf)/sizeof(buf[0])) && buf[0])
|
||||
str << " title=\"" << QString::fromWCharArray(buf) << "\"/";
|
||||
else
|
||||
str << ' ';
|
||||
if (GetClassName(hwnd, buf, sizeof(buf)/sizeof(buf[0])))
|
||||
str << '"' << QString::fromWCharArray(buf) << '"';
|
||||
|
||||
str << hex << showbase;
|
||||
if (const LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE)) {
|
||||
str << " style=" << style;
|
||||
@ -121,13 +130,31 @@ static void formatNativeWindow(HWND hwnd, QTextStream &str)
|
||||
debugWinStyle(str, exStyle, WS_EX_COMPOSITED)
|
||||
debugWinStyle(str, exStyle, WS_EX_NOACTIVATE)
|
||||
}
|
||||
|
||||
if (const ULONG_PTR classStyle = GetClassLongPtr(hwnd, GCL_STYLE)) {
|
||||
str << " classStyle=" << classStyle;
|
||||
debugWinStyle(str, classStyle, CS_BYTEALIGNCLIENT)
|
||||
debugWinStyle(str, classStyle, CS_BYTEALIGNWINDOW)
|
||||
debugWinStyle(str, classStyle, CS_CLASSDC)
|
||||
debugWinStyle(str, classStyle, CS_DBLCLKS)
|
||||
debugWinStyle(str, classStyle, CS_DROPSHADOW)
|
||||
debugWinStyle(str, classStyle, CS_GLOBALCLASS)
|
||||
debugWinStyle(str, classStyle, CS_HREDRAW)
|
||||
debugWinStyle(str, classStyle, CS_NOCLOSE)
|
||||
debugWinStyle(str, classStyle, CS_OWNDC)
|
||||
debugWinStyle(str, classStyle, CS_PARENTDC)
|
||||
debugWinStyle(str, classStyle, CS_SAVEBITS)
|
||||
debugWinStyle(str, classStyle, CS_VREDRAW)
|
||||
}
|
||||
|
||||
if (const ULONG_PTR wndProc = GetClassLongPtr(hwnd, GCLP_WNDPROC))
|
||||
str << " wndProc=" << wndProc;
|
||||
|
||||
str << noshowbase << dec;
|
||||
|
||||
wchar_t buf[512];
|
||||
if (GetWindowText(hwnd, buf, sizeof(buf)/sizeof(buf[0])))
|
||||
str << " title=\"" << QString::fromWCharArray(buf) << '"';
|
||||
if (GetClassName(hwnd, buf, sizeof(buf)/sizeof(buf[0])))
|
||||
str << " class=\"" << QString::fromWCharArray(buf) << '"';
|
||||
if (GetWindowModuleFileName(hwnd, buf, sizeof(buf)/sizeof(buf[0])))
|
||||
str << " module=\"" << QString::fromWCharArray(buf) << '"';
|
||||
|
||||
str << '\n';
|
||||
}
|
||||
|
||||
@ -135,7 +162,11 @@ static void dumpNativeWindowRecursion(HWND hwnd, DumpContext *dc);
|
||||
|
||||
BOOL CALLBACK dumpWindowEnumChildProc(HWND hwnd, LPARAM lParam)
|
||||
{
|
||||
dumpNativeWindowRecursion(hwnd, reinterpret_cast<DumpContext *>(lParam));
|
||||
DumpContext *dumpContext = reinterpret_cast<DumpContext *>(lParam);
|
||||
// EnumChildWindows enumerates grand children as well, skip these to
|
||||
// get the hierarchical formatting right.
|
||||
if (GetAncestor(hwnd, GA_PARENT) == dumpContext->parent)
|
||||
dumpNativeWindowRecursion(hwnd, dumpContext);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -145,6 +176,7 @@ static void dumpNativeWindowRecursion(HWND hwnd, DumpContext *dc)
|
||||
formatNativeWindow(hwnd, *dc->stream);
|
||||
DumpContext nextLevel = *dc;
|
||||
nextLevel.indentation += 2;
|
||||
nextLevel.parent = hwnd;
|
||||
EnumChildWindows(hwnd, dumpWindowEnumChildProc, reinterpret_cast<LPARAM>(&nextLevel));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user