Keep a single real implementation of SetWindowSubclassIfNeeded()

Don't duplicate it for the special case of passing 0 as data, the
compiler should be able to optimize out the trivial lambda and doing it
like this reduces code duplication.

No real changes.
This commit is contained in:
Vadim Zeitlin
2026-06-10 16:34:31 +02:00
parent af620105cf
commit bbb3fc78bb
+10 -17
View File
@@ -964,23 +964,6 @@ TDRadioButtonSubclassProc(HWND hwnd,
// Helper which calls SetWindowSubclass() only if the subclass is not already
// set.
//
// This is a simple overload when we don't need to pass any reference data to
// the subclass procedure.
void
SetWindowSubclassIfNeeded(HWND hwnd,
SUBCLASSPROC proc,
UINT_PTR uId)
{
DWORD_PTR dwRef = 0;
if ( ::GetWindowSubclass(hwnd, proc, uId, &dwRef) )
return;
if ( !::SetWindowSubclass(hwnd, proc, uId, 0) )
{
wxLogLastError("SetWindowSubclass");
}
}
// This overload takes a lambda as the last parameter which is called to create
// the reference data if the subclass needs to be set and to avoid creating any
// resources passed to the subclass procedure unnecessarily.
@@ -1002,6 +985,16 @@ SetWindowSubclassIfNeeded(HWND hwnd,
}
}
// This is a simple overload when we don't need to pass any reference data to
// the subclass procedure.
void
SetWindowSubclassIfNeeded(HWND hwnd,
SUBCLASSPROC proc,
UINT_PTR uId)
{
return SetWindowSubclassIfNeeded(hwnd, proc, uId, []() { return 0; });
}
// Remove the subclass if it was installed.
//
// Return false if it wasn't.