Skip to content

Commit

Permalink
Add tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
dechamps committed Mar 12, 2022
1 parent b7ed292 commit 160a9b9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,17 @@ address. However, RudeWindowFixer is unlikely to help with Rude Window Manager
bugs that do not involve transparent windows (as defined above) nor shell hook
message race conditions.

## Tracing

RudeWindowFixer logs every event through an [Event Tracing for Windows (ETW)][]
provider. This can be used to troubleshoot RudeWindowFixer operation.

The provider GUID is `F7A4605A-5EBA-46A2-8A75-D7E2FECC8D62`. You can enter that
GUID directly in [TraceView][] for real time logging, or you can load the
included [`RudeWindowFixer.wprp`][] [recording profile][] into the [Windows
Performance Recorder (WPR)][] for a more thorough analysis. The Provider Name
will appear as `RudeWindowFixer`.

## See also

- This [SuperUser question][superuser1] and [this one][superuser2] discuss
Expand All @@ -492,6 +503,7 @@ There are no dependencies besides the Windows SDK.
[eclipse]: https://bugs.eclipse.org/bugs/show_bug.cgi?id=24052
[Etienne Dechamps]: mailto:[email protected]
[extended window style]: https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles
[Event Tracing for Windows (ETW)]: https://docs.microsoft.com/en-us/windows/win32/etw/about-event-tracing
[file an issue]: https://github.com/dechamps/RudeWindowFixer/issues
[`GetClientRect()`]: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclientrect
[`GetWindowRect()`]: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowrect
Expand All @@ -509,7 +521,10 @@ There are no dependencies besides the Windows SDK.
[WindowInvestigator]: https://github.com/dechamps/WindowInvestigator
[public Microsoft symbols]: https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/microsoft-public-symbols
[race]: https://en.wikipedia.org/wiki/Race_condition
[recording profile]: https://docs.microsoft.com/en-us/windows-hardware/test/wpt/authoring-recording-profiles
[reverse engineering]: https://en.wikipedia.org/wiki/Reverse_engineering#Binary_software
[TraceView]: https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/traceview
[`RudeWindowFixer.wprp`]: RudeWindowFixer.wprp
[`SetLayeredWindowAttributes()`]: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setlayeredwindowattributes
[shell hook messages]: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registershellhookwindow
[superuser1]: https://superuser.com/questions/1163969/windows-10-taskbar-is-not-always-on-top
Expand All @@ -519,5 +534,6 @@ There are no dependencies besides the Windows SDK.
[window property]: https://docs.microsoft.com/en-us/windows/win32/winmsg/window-properties
[run on startup]: https://www.howtogeek.com/228467/how-to-make-a-program-run-at-startup-on-any-computer/
[Z-order]: https://docs.microsoft.com/en-us/windows/win32/winmsg/window-features#z-order
[Windows Performance Recorder (WPR)]: https://docs.microsoft.com/en-us/windows-hardware/test/wpt/windows-performance-recorder
[`WM_WINDOWPOSCHANGING`]: https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-windowposchanging
[WindowInvestigator]: https://github.com/dechamps/WindowInvestigator
14 changes: 14 additions & 0 deletions RudeWindowFixer.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#include <Windows.h>
#include <TraceLoggingProvider.h>

TRACELOGGING_DEFINE_PROVIDER(RudeWindowFixer_traceloggingProvider, "RudeWindowFixer", (0xf7a4605a, 0x5eba, 0x46a2, 0x8a, 0x75, 0xd7, 0xe2, 0xfe, 0xcc, 0x8d, 0x62));

static UINT RudeWindowFixer_shellhookMessage;

#define HSHELL_UNDOCUMENTED_FULLSCREEN_ENTER 0x35
#define HSHELL_UNDOCUMENTED_FULLSCREEN_EXIT 0x36

static __declspec(noreturn) void RudeWindowFixer_Error(LPCWSTR text) {
TraceLoggingWrite(RudeWindowFixer_traceloggingProvider, "Error", TraceLoggingWideString(text, "ErrorMessage"));
MessageBoxW(NULL, text, L"RudeWindowFixer error", MB_ICONERROR);
exit(EXIT_FAILURE);
}
Expand Down Expand Up @@ -33,6 +37,8 @@ static BOOL CALLBACK RudeWindowFixer_AdjustWindows_EnumWindowsProc(_In_ HWND win
GetPropW(window, nonRudeProp) == NULL
)) return TRUE;

TraceLoggingWrite(RudeWindowFixer_traceloggingProvider, "SettingNonRudeHWND", TraceLoggingPointer(window, "HWND"), TraceLoggingIntPtr(extendedWindowStyles, "ExtendedWindowStyles"));

const wchar_t* const propComment = L"NonRudeHWND was set by https://github.com/dechamps/RudeWindowFixer";
SetPropW(window, propComment, INVALID_HANDLE_VALUE);
SetPropW(window, nonRudeProp, INVALID_HANDLE_VALUE);
Expand All @@ -49,6 +55,8 @@ static void RudeWindowFixer_AdjustWindows(void) {
}

static LRESULT CALLBACK RudeWindowFixer_WindowProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
TraceLoggingWrite(RudeWindowFixer_traceloggingProvider, "ReceivedMessage", TraceLoggingHexUInt32(uMsg, "uMsg"), TraceLoggingHexUInt64(wParam, "wParam"), TraceLoggingHexUInt64(lParam, "lParam"));

const UINT_PTR timerId = 1;

if (uMsg == WM_TIMER) KillTimer(hWnd, timerId);
Expand All @@ -71,6 +79,8 @@ static LRESULT CALLBACK RudeWindowFixer_WindowProcedure(HWND hWnd, UINT uMsg, WP
RudeWindowFixer_BroadcastShellHookMessage(HSHELL_MONITORCHANGED, 0);
}

TraceLoggingWrite(RudeWindowFixer_traceloggingProvider, "Done");

return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}

Expand All @@ -79,10 +89,14 @@ int APIENTRY WinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hInstPrev, _In_ P
UNREFERENCED_PARAMETER(cmdline);
UNREFERENCED_PARAMETER(cmdshow);

TraceLoggingRegister(RudeWindowFixer_traceloggingProvider);

RudeWindowFixer_shellhookMessage = RegisterWindowMessageW(L"SHELLHOOK");
if (RudeWindowFixer_shellhookMessage == 0)
RudeWindowFixer_Error(L"RegisterWindowMessageW() failed");

TraceLoggingWrite(RudeWindowFixer_traceloggingProvider, "Starting", TraceLoggingHexUInt32(RudeWindowFixer_shellhookMessage, "ShellhookMessage"));

WNDCLASSEXW windowClass = { 0 };
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.lpfnWndProc = RudeWindowFixer_WindowProcedure;
Expand Down
16 changes: 16 additions & 0 deletions RudeWindowFixer.wprp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<WindowsPerformanceRecorder Version="1.0">
<Profiles>
<EventCollector Id="EventCollector_RudeWindowFixer" Name="RudeWindowFixer" />
<Profile Id="RudeWindowFixer.Verbose.File" Name="RudeWindowFixer" Description="RudeWindowFixer" LoggingMode="File" DetailLevel="Verbose">
<Collectors>
<EventCollectorId Value="EventCollector_RudeWindowFixer">
<EventProviders>
<EventProvider Id="EventProvider_RudeWindowFixer" Name="F7A4605A-5EBA-46A2-8A75-D7E2FECC8D62" />
</EventProviders>
</EventCollectorId>
</Collectors>
</Profile>
<Profile Id="RudeWindowFixer.Verbose.Memory" Base="RudeWindowFixer.Verbose.File" LoggingMode="Memory" Name="RudeWindowFixer" Description="RudeWindowFixer" DetailLevel="Verbose" />
</Profiles>
</WindowsPerformanceRecorder>

0 comments on commit 160a9b9

Please sign in to comment.