From 29f311ddc76b42ae611d0664b732b7adad4e1689 Mon Sep 17 00:00:00 2001 From: narzoul Date: Sun, 27 Sep 2020 23:03:55 +0200 Subject: [PATCH] Improved logging of wParam/lParam for window messages --- DDrawCompat/Common/Log.h | 11 + DDrawCompat/Gdi/PaintHandlers.cpp | 4 +- DDrawCompat/Gdi/WinProc.cpp | 2 +- DDrawCompat/Gdi/Window.cpp | 4 +- DDrawCompat/Win32/Log.cpp | 578 ++++++++++++++++++++++++++++-- DDrawCompat/Win32/Log.h | 57 ++- 6 files changed, 628 insertions(+), 28 deletions(-) diff --git a/DDrawCompat/Common/Log.h b/DDrawCompat/Common/Log.h index c899d0d..8c1e6e1 100644 --- a/DDrawCompat/Common/Log.h +++ b/DDrawCompat/Common/Log.h @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -39,12 +40,22 @@ std::ostream& operator<<(std::ostream& os, const char* str); std::ostream& operator<<(std::ostream& os, const unsigned char* data); std::ostream& operator<<(std::ostream& os, const WCHAR* wstr); +template +std::ostream& operator<<(std::ostream & os, const std::pair & pair) +{ + return Compat::LogStruct(os) + << pair.first + << pair.second; +} + namespace Compat { using ::operator<<; namespace detail { + using ::operator<<; + template struct Hex { diff --git a/DDrawCompat/Gdi/PaintHandlers.cpp b/DDrawCompat/Gdi/PaintHandlers.cpp index 201cf67..3f723ea 100644 --- a/DDrawCompat/Gdi/PaintHandlers.cpp +++ b/DDrawCompat/Gdi/PaintHandlers.cpp @@ -156,7 +156,7 @@ namespace LRESULT defPaintProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, WNDPROC origWndProc, [[maybe_unused]] const char* origWndProcName) { - LOG_FUNC(origWndProcName, hwnd, Compat::logWm(msg), Compat::hex(wParam), Compat::hex(lParam)); + LOG_FUNC(origWndProcName, Compat::WindowMessageStruct(hwnd, msg, wParam, lParam)); return LOG_RESULT(defPaintProc(hwnd, msg, wParam, lParam, origWndProc)); } @@ -427,7 +427,7 @@ namespace LRESULT CALLBACK user32WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, [[maybe_unused]] const std::string& procName, WndProcHook wndProcHook, WNDPROC oldWndProcTrampoline) { - LOG_FUNC(procName.c_str(), hwnd, Compat::logWm(uMsg), Compat::hex(wParam), Compat::hex(lParam)); + LOG_FUNC(procName.c_str(), Compat::WindowMessageStruct(hwnd, uMsg, wParam, lParam)); return LOG_RESULT(wndProcHook(hwnd, uMsg, wParam, lParam, oldWndProcTrampoline)); } diff --git a/DDrawCompat/Gdi/WinProc.cpp b/DDrawCompat/Gdi/WinProc.cpp index 9f12a13..d6aef58 100644 --- a/DDrawCompat/Gdi/WinProc.cpp +++ b/DDrawCompat/Gdi/WinProc.cpp @@ -52,7 +52,7 @@ namespace LRESULT CALLBACK ddcWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, decltype(&CallWindowProcA) callWindowProc, WNDPROC wndProc) { - LOG_FUNC("ddcWindowProc", hwnd, Compat::logWm(uMsg), Compat::hex(wParam), Compat::hex(lParam)); + LOG_FUNC("ddcWindowProc", Compat::WindowMessageStruct(hwnd, uMsg, wParam, lParam)); LRESULT result = callWindowProc(wndProc, hwnd, uMsg, wParam, lParam); switch (uMsg) diff --git a/DDrawCompat/Gdi/Window.cpp b/DDrawCompat/Gdi/Window.cpp index 7a25d04..b8b8802 100644 --- a/DDrawCompat/Gdi/Window.cpp +++ b/DDrawCompat/Gdi/Window.cpp @@ -20,7 +20,7 @@ namespace LRESULT CALLBACK messageWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - LOG_FUNC("messageWindowProc", hwnd, Compat::logWm(uMsg), Compat::hex(wParam), Compat::hex(lParam)); + LOG_FUNC("messageWindowProc", Compat::WindowMessageStruct(hwnd, uMsg, wParam, lParam)); switch (uMsg) { case WM_CREATEPRESENTATIONWINDOW: @@ -69,7 +69,7 @@ namespace LRESULT CALLBACK presentationWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - LOG_FUNC("presentationWindowProc", hwnd, Compat::logWm(uMsg), Compat::hex(wParam), Compat::hex(lParam)); + LOG_FUNC("presentationWindowProc", Compat::WindowMessageStruct(hwnd, uMsg, wParam, lParam)); switch (uMsg) { diff --git a/DDrawCompat/Win32/Log.cpp b/DDrawCompat/Win32/Log.cpp index 46139e1..88eaca2 100644 --- a/DDrawCompat/Win32/Log.cpp +++ b/DDrawCompat/Win32/Log.cpp @@ -6,6 +6,24 @@ namespace { + template + std::ostream& logCreateStruct(std::ostream& os, const CreateStruct& cs) + { + return Compat::LogStruct(os) + << Compat::hex(cs.dwExStyle) + << cs.lpszClass + << cs.lpszName + << Compat::hex(cs.style) + << cs.x + << cs.y + << cs.cx + << cs.cy + << cs.hwndParent + << cs.hMenu + << cs.hInstance + << cs.lpCreateParams; + } + template std::ostream& logDevMode(std::ostream& os, const DevMode& dm) { @@ -16,27 +34,77 @@ namespace << dm.dmDisplayFrequency << dm.dmDisplayFlags; } + + template + std::ostream& logMdiCreateStruct(std::ostream& os, const MdiCreateStruct& mcs) + { + return Compat::LogStruct(os) + << mcs.szClass + << mcs.szTitle + << mcs.hOwner + << mcs.x + << mcs.y + << mcs.cx + << mcs.cy + << Compat::hex(mcs.style) + << Compat::hex(mcs.lParam); + } } -std::ostream& operator<<(std::ostream& os, const CWPSTRUCT& cwrp) +std::ostream& operator<<(std::ostream& os, const COMPAREITEMSTRUCT& cis) { return Compat::LogStruct(os) - << Compat::logWm(cwrp.message) - << cwrp.hwnd - << Compat::hex(cwrp.wParam) - << Compat::hex(cwrp.lParam); + << cis.CtlType + << cis.CtlID + << cis.hwndItem + << cis.itemID1 + << Compat::hex(cis.itemData1) + << cis.itemID2 + << Compat::hex(cis.itemData2) + << Compat::hex(cis.dwLocaleId); +} + +std::ostream& operator<<(std::ostream& os, const COPYDATASTRUCT& cds) +{ + return Compat::LogStruct(os) + << Compat::hex(cds.dwData) + << cds.cbData + << cds.lpData; +} + +std::ostream& operator<<(std::ostream& os, const CREATESTRUCTA& cs) +{ + return logCreateStruct(os, cs); +} + +std::ostream& operator<<(std::ostream& os, const CREATESTRUCTW& cs) +{ + return logCreateStruct(os, cs); +} + +std::ostream& operator<<(std::ostream& os, const CWPSTRUCT& cwp) +{ + return Compat::LogStruct(os) + << Compat::WindowMessageStruct(cwp.hwnd, cwp.message, cwp.wParam, cwp.lParam); } std::ostream& operator<<(std::ostream& os, const CWPRETSTRUCT& cwrp) { return Compat::LogStruct(os) - << Compat::logWm(cwrp.message) - << cwrp.hwnd - << Compat::hex(cwrp.wParam) - << Compat::hex(cwrp.lParam) + << Compat::WindowMessageStruct(cwrp.hwnd, cwrp.message, cwrp.wParam, cwrp.lParam) << Compat::hex(cwrp.lResult); } +std::ostream& operator<<(std::ostream& os, const DELETEITEMSTRUCT& dis) +{ + return Compat::LogStruct(os) + << dis.CtlType + << dis.CtlID + << dis.itemID + << dis.hwndItem + << Compat::hex(dis.itemData); +} + std::ostream& operator<<(std::ostream& os, const DEVMODEA& dm) { return logDevMode(os, dm); @@ -47,6 +115,30 @@ std::ostream& operator<<(std::ostream& os, const DEVMODEW& dm) return logDevMode(os, dm); } +std::ostream& operator<<(std::ostream& os, const DRAWITEMSTRUCT& dis) +{ + return Compat::LogStruct(os) + << dis.CtlType + << dis.CtlID + << dis.itemID + << Compat::hex(dis.itemAction) + << Compat::hex(dis.itemState) + << dis.hwndItem + << dis.hDC + << dis.rcItem + << Compat::hex(dis.itemData); +} + +std::ostream& operator<<(std::ostream& os, const GESTURENOTIFYSTRUCT& gns) +{ + return Compat::LogStruct(os) + << gns.cbSize + << Compat::hex(gns.dwFlags) + << gns.hwndTarget + << gns.ptsLocation + << gns.dwInstanceID; +} + std::ostream& operator<<(std::ostream& os, HDC dc) { os << "DC"; @@ -59,6 +151,39 @@ std::ostream& operator<<(std::ostream& os, HDC dc) << CALL_ORIG_FUNC(WindowFromDC)(dc); } +std::ostream& operator<<(std::ostream& os, const HELPINFO& hi) +{ + Compat::LogStruct log(os); + log << hi.cbSize + << hi.iContextType + << hi.iCtrlId; + + if (HELPINFO_WINDOW == hi.iContextType) + { + log << static_cast(hi.hItemHandle); + } + else + { + log << static_cast(hi.hItemHandle); + } + + return log + << hi.dwContextId + << hi.MousePos; +} + +std::ostream& operator<<(std::ostream& os, HFONT font) +{ + LOGFONT lf = {}; + if (font) + { + GetObject(font, sizeof(lf), &lf); + } + return Compat::LogStruct(os) + << static_cast(font) + << (font ? &lf : nullptr); +} + std::ostream& operator<<(std::ostream& os, HRGN rgn) { os << "RGN"; @@ -110,6 +235,54 @@ std::ostream& operator<<(std::ostream& os, HWND hwnd) << Compat::hex(CALL_ORIG_FUNC(GetWindowLongA)(hwnd, GWL_EXSTYLE)); } +std::ostream& operator<<(std::ostream& os, const LOGFONT& lf) +{ + return Compat::LogStruct(os) + << lf.lfHeight + << lf.lfWidth + << lf.lfEscapement + << lf.lfOrientation + << lf.lfWeight + << static_cast(lf.lfItalic) + << static_cast(lf.lfUnderline) + << static_cast(lf.lfStrikeOut) + << static_cast(lf.lfCharSet) + << static_cast(lf.lfOutPrecision) + << static_cast(lf.lfClipPrecision) + << static_cast(lf.lfQuality) + << Compat::hex(lf.lfPitchAndFamily) + << lf.lfFaceName; +} + +std::ostream& operator<<(std::ostream& os, const MDICREATESTRUCTA& mcs) +{ + return logMdiCreateStruct(os, mcs); +} + +std::ostream& operator<<(std::ostream& os, const MDICREATESTRUCTW& mcs) +{ + return logMdiCreateStruct(os, mcs); +} + +std::ostream& operator<<(std::ostream& os, const MDINEXTMENU& mnm) +{ + return Compat::LogStruct(os) + << mnm.hmenuIn + << mnm.hmenuNext + << mnm.hwndNext; +} + +std::ostream& operator<<(std::ostream& os, const MEASUREITEMSTRUCT& mis) +{ + return Compat::LogStruct(os) + << mis.CtlType + << mis.CtlID + << mis.itemID + << mis.itemWidth + << mis.itemHeight + << Compat::hex(mis.itemData); +} + std::ostream& operator<<(std::ostream& os, const MEMORYSTATUS& ms) { return Compat::LogStruct(os) @@ -123,17 +296,56 @@ std::ostream& operator<<(std::ostream& os, const MEMORYSTATUS& ms) << ms.dwAvailVirtual; } +std::ostream& operator<<(std::ostream& os, const MENUGETOBJECTINFO& mgoi) +{ + return Compat::LogStruct(os) + << Compat::hex(mgoi.dwFlags) + << mgoi.uPos + << mgoi.hmenu + << static_cast(mgoi.riid) + << mgoi.pvObj; +} + +std::ostream& operator<<(std::ostream& os, const MINMAXINFO& mmi) +{ + return Compat::LogStruct(os) + << mmi.ptReserved + << mmi.ptMaxSize + << mmi.ptMaxPosition + << mmi.ptMinTrackSize + << mmi.ptMaxTrackSize; +} + std::ostream& operator<<(std::ostream& os, const MSG& msg) { return Compat::LogStruct(os) - << msg.hwnd - << Compat::logWm(msg.message) - << Compat::hex(msg.wParam) - << Compat::hex(msg.lParam) + << Compat::WindowMessageStruct(msg.hwnd, msg.message, msg.wParam, msg.lParam) << msg.time << msg.pt; } +std::ostream& operator<<(std::ostream& os, const NCCALCSIZE_PARAMS& nccs) +{ + return Compat::LogStruct(os) + << Compat::array(nccs.rgrc, sizeof(nccs.rgrc) / sizeof(nccs.rgrc[0])) + << nccs.lppos; +} + +std::ostream& operator<<(std::ostream& os, const NMHDR& nm) +{ + return Compat::LogStruct(os) + << nm.hwndFrom + << nm.idFrom + << Compat::hex(nm.code); +} + +std::ostream& operator<<(std::ostream& os, const POINTS& p) +{ + return Compat::LogStruct(os) + << p.x + << p.y; +} + std::ostream& operator<<(std::ostream& os, const RECT& rect) { return Compat::LogStruct(os) @@ -143,12 +355,57 @@ std::ostream& operator<<(std::ostream& os, const RECT& rect) << rect.bottom; } +std::ostream& operator<<(std::ostream& os, const SIZE& size) +{ + return Compat::LogStruct(os) + << size.cx + << size.cy; +} + +std::ostream& operator<<(std::ostream& os, const STYLESTRUCT& ss) +{ + return Compat::LogStruct(os) + << Compat::hex(ss.styleOld) + << Compat::hex(ss.styleNew); +} + +std::ostream& operator<<(std::ostream& os, const TITLEBARINFOEX& tbi) +{ + return Compat::LogStruct(os) + << tbi.cbSize + << tbi.rcTitleBar + << Compat::array(tbi.rgstate, sizeof(tbi.rgstate) / sizeof(tbi.rgstate[0])) + << Compat::array(tbi.rgrect, sizeof(tbi.rgrect) / sizeof(tbi.rgrect[0])); +} + +std::ostream& operator<<(std::ostream& os, const TOUCH_HIT_TESTING_INPUT& thti) +{ + return Compat::LogStruct(os) + << thti.pointerId + << thti.point + << thti.boundingBox + << thti.nonOccludedBoundingBox + << thti.orientation; +} + +std::ostream& operator<<(std::ostream& os, const WINDOWPOS& wp) +{ + return Compat::LogStruct(os) + << wp.hwnd + << wp.hwndInsertAfter + << wp.x + << wp.y + << wp.cx + << wp.cy + << Compat::hex(wp.flags); +} + namespace Compat { - std::string logWm(UINT msg) + std::ostream& operator<<(std::ostream& os, WindowMessage msg) { -#define LOG_WM_CASE(msg) case msg: return #msg; - switch (msg) +#define LOG_WM_CASE(msg) case msg: return os << #msg; + switch (msg.msg) { LOG_WM_CASE(WM_NULL); LOG_WM_CASE(WM_CREATE); @@ -395,10 +652,289 @@ namespace Compat }; #undef LOG_WM_CASE - std::ostringstream oss; - oss.width(4); - oss.fill('0'); - oss << "WM_" << std::hex << msg; - return oss.str(); + os.width(4); + os.fill('0'); + os << "WM_" << std::hex << msg.msg << std::dec; + return os; + } + + std::ostream& operator<<(std::ostream& os, WindowMessage16 msg) + { + return os << WindowMessage(msg.msg); + } + + std::ostream& operator<<(std::ostream& os, WindowMessageStruct wm) + { + os << '{' << wm.hwnd << ',' << wm.msg << ','; + +#define LOG_PARAM_CASE_1(param, msg, ...) \ + case msg: \ + static_assert(sizeof(__VA_ARGS__) == sizeof(param)); \ + os << *reinterpret_cast(¶m); \ + break + +#define LOG_PARAM_CASE_2(param, msg, TypeA, TypeW) \ + case msg: \ + if (IsWindowUnicode(wm.hwnd)) \ + os << reinterpret_cast(param); \ + else \ + os << reinterpret_cast(param); \ + break; + +#define LOG_WPARAM_CASE_1(msg, ...) LOG_PARAM_CASE_1(wm.wParam, msg, __VA_ARGS__) +#define LOG_WPARAM_CASE_2(msg, TypeA, TypeW) LOG_PARAM_CASE_2(wm.wParam, msg, TypeA, TypeW) + + switch (wm.msg.msg) + { + LOG_WPARAM_CASE_1(WM_ACTIVATE, std::pair); + LOG_WPARAM_CASE_1(WM_APPCOMMAND, HWND); + LOG_WPARAM_CASE_1(WM_ASKCBFORMATNAME, DWORD); + LOG_WPARAM_CASE_1(WM_CHANGECBCHAIN, HWND); + LOG_WPARAM_CASE_1(WM_CHANGEUISTATE, std::pair>); + LOG_WPARAM_CASE_1(WM_CHARTOITEM, std::pair); + LOG_WPARAM_CASE_1(WM_CTLCOLORMSGBOX, HDC); + LOG_WPARAM_CASE_1(WM_CTLCOLOREDIT, HDC); + LOG_WPARAM_CASE_1(WM_CTLCOLORLISTBOX, HDC); + LOG_WPARAM_CASE_1(WM_CTLCOLORBTN, HDC); + LOG_WPARAM_CASE_1(WM_CTLCOLORDLG, HDC); + LOG_WPARAM_CASE_1(WM_CTLCOLORSCROLLBAR, HDC); + LOG_WPARAM_CASE_1(WM_CTLCOLORSTATIC, HDC); + LOG_WPARAM_CASE_1(WM_COMMAND, std::pair, WORD>); + LOG_WPARAM_CASE_1(WM_CONTEXTMENU, HWND); + LOG_WPARAM_CASE_1(WM_COPYDATA, HWND); + LOG_WPARAM_CASE_1(WM_DISPLAYCHANGE, INT); + LOG_WPARAM_CASE_1(WM_DPICHANGED, std::pair); + LOG_WPARAM_CASE_1(WM_DRAWITEM, HWND); + LOG_WPARAM_CASE_1(WM_ERASEBKGND, HDC); + LOG_WPARAM_CASE_1(WM_GETDPISCALEDSIZE, DWORD); + LOG_WPARAM_CASE_1(WM_GETTEXT, DWORD); + LOG_WPARAM_CASE_1(WM_HOTKEY, INT); + LOG_WPARAM_CASE_1(WM_HSCROLL, std::pair); + LOG_WPARAM_CASE_1(WM_HSCROLLCLIPBOARD, HWND); + LOG_WPARAM_CASE_1(WM_ICONERASEBKGND, HDC); + LOG_WPARAM_CASE_1(WM_INITDIALOG, HWND); + LOG_WPARAM_CASE_1(WM_KILLFOCUS, HWND); + LOG_WPARAM_CASE_1(WM_MDIACTIVATE, HWND); + LOG_WPARAM_CASE_1(WM_MDIDESTROY, HWND); + LOG_WPARAM_CASE_1(WM_MDIMAXIMIZE, HWND); + LOG_WPARAM_CASE_1(WM_MDINEXT, HWND); + LOG_WPARAM_CASE_1(WM_MDIRESTORE, HWND); + LOG_WPARAM_CASE_1(WM_MENUCHAR, std::pair, Compat::detail::Hex>); + LOG_WPARAM_CASE_1(WM_MENUCOMMAND, DWORD); + LOG_WPARAM_CASE_1(WM_MENUDRAG, DWORD); + LOG_WPARAM_CASE_1(WM_MENURBUTTONUP, DWORD); + LOG_WPARAM_CASE_1(WM_MENUSELECT, std::pair>); + LOG_WPARAM_CASE_1(WM_MOUSEACTIVATE, HWND); + LOG_WPARAM_CASE_1(WM_MOUSEHWHEEL, std::pair, SHORT>); + LOG_WPARAM_CASE_1(WM_MOUSEWHEEL, std::pair, SHORT>); + LOG_WPARAM_CASE_1(WM_NCLBUTTONDBLCLK, INT); + LOG_WPARAM_CASE_1(WM_NCLBUTTONDOWN, INT); + LOG_WPARAM_CASE_1(WM_NCLBUTTONUP, INT); + LOG_WPARAM_CASE_1(WM_NCMBUTTONDBLCLK, INT); + LOG_WPARAM_CASE_1(WM_NCMBUTTONDOWN, INT); + LOG_WPARAM_CASE_1(WM_NCMBUTTONUP, INT); + LOG_WPARAM_CASE_1(WM_NCMOUSEHOVER, INT); + LOG_WPARAM_CASE_1(WM_NCMOUSEMOVE, INT); + LOG_WPARAM_CASE_1(WM_NCPAINT, HRGN); + LOG_WPARAM_CASE_1(WM_NCPOINTERDOWN, std::pair); + LOG_WPARAM_CASE_1(WM_NCPOINTERUP, std::pair); + LOG_WPARAM_CASE_1(WM_NCPOINTERUPDATE, std::pair); + LOG_WPARAM_CASE_1(WM_NCXBUTTONDBLCLK, std::pair, WORD>); + LOG_WPARAM_CASE_1(WM_NCXBUTTONDOWN, std::pair, WORD>); + LOG_WPARAM_CASE_1(WM_NCXBUTTONUP, std::pair, WORD>); + LOG_WPARAM_CASE_1(WM_NOTIFYFORMAT, HWND); + LOG_WPARAM_CASE_1(WM_PALETTECHANGED, HWND); + LOG_WPARAM_CASE_1(WM_PALETTEISCHANGING, HWND); + LOG_WPARAM_CASE_1(WM_PARENTNOTIFY, std::pair>); + LOG_WPARAM_CASE_1(WM_POINTERACTIVATE, std::pair); + LOG_WPARAM_CASE_1(WM_POINTERDOWN, std::pair>); + LOG_WPARAM_CASE_1(WM_POINTERENTER, std::pair>); + LOG_WPARAM_CASE_1(WM_POINTERHWHEEL, std::pair); + LOG_WPARAM_CASE_1(WM_POINTERLEAVE, std::pair>); + LOG_WPARAM_CASE_1(WM_POINTERUP, std::pair>); + LOG_WPARAM_CASE_1(WM_POINTERUPDATE, std::pair>); + LOG_WPARAM_CASE_1(WM_POINTERWHEEL, std::pair); + LOG_WPARAM_CASE_1(WM_PRINT, HDC); + LOG_WPARAM_CASE_1(WM_PRINTCLIENT, HDC); + LOG_WPARAM_CASE_1(WM_SETFOCUS, HWND); + LOG_WPARAM_CASE_1(WM_SETFONT, HFONT); + LOG_WPARAM_CASE_1(WM_SETHOTKEY, std::pair, Compat::detail::Hex>); + LOG_WPARAM_CASE_1(WM_SETTEXT, DWORD); + LOG_WPARAM_CASE_1(WM_SIZECLIPBOARD, HWND); + LOG_WPARAM_CASE_1(WM_STYLECHANGED, INT); + LOG_WPARAM_CASE_1(WM_STYLECHANGING, INT); + LOG_WPARAM_CASE_1(WM_UPDATEUISTATE, std::pair>); + LOG_WPARAM_CASE_1(WM_VKEYTOITEM, std::pair, WORD>); + LOG_WPARAM_CASE_1(WM_VSCROLL, std::pair); + LOG_WPARAM_CASE_1(WM_VSCROLLCLIPBOARD, HWND); + LOG_WPARAM_CASE_1(WM_XBUTTONDBLCLK, std::pair, WORD>); + LOG_WPARAM_CASE_1(WM_XBUTTONDOWN, std::pair, WORD>); + LOG_WPARAM_CASE_1(WM_XBUTTONUP, std::pair, WORD>); + + case WM_NEXTDLGCTL: + if (wm.lParam) + { + os << reinterpret_cast(wm.wParam); + } + else + { + os << wm.wParam; + } + break; + + default: + os << Compat::hex(wm.wParam); + break; + } + +#undef LOG_WPARAM_CASE_1 +#undef LOG_WPARAM_CASE_2 + +#define LOG_LPARAM_CASE_1(msg, ...) LOG_PARAM_CASE_1(wm.lParam, msg, __VA_ARGS__) +#define LOG_LPARAM_CASE_2(msg, TypeA, TypeW) LOG_PARAM_CASE_2(wm.lParam, msg, TypeA, TypeW) + + os << ','; + + switch (wm.msg.msg) + { + LOG_LPARAM_CASE_1(WM_ACTIVATE, HWND); + LOG_LPARAM_CASE_2(WM_ASKCBFORMATNAME, LPCSTR, LPCWSTR); + LOG_LPARAM_CASE_1(WM_CAPTURECHANGED, HWND); + LOG_LPARAM_CASE_1(WM_CHANGECBCHAIN, HWND); + LOG_LPARAM_CASE_1(WM_CHARTOITEM, HWND); + LOG_LPARAM_CASE_1(WM_CTLCOLORMSGBOX, HWND); + LOG_LPARAM_CASE_1(WM_CTLCOLOREDIT, HWND); + LOG_LPARAM_CASE_1(WM_CTLCOLORLISTBOX, HWND); + LOG_LPARAM_CASE_1(WM_CTLCOLORBTN, HWND); + LOG_LPARAM_CASE_1(WM_CTLCOLORDLG, HWND); + LOG_LPARAM_CASE_1(WM_CTLCOLORSCROLLBAR, HWND); + LOG_LPARAM_CASE_1(WM_CTLCOLORSTATIC, HWND); + LOG_LPARAM_CASE_1(WM_COMMAND, HWND); + LOG_LPARAM_CASE_1(WM_COMPAREITEM, COMPAREITEMSTRUCT*); + LOG_LPARAM_CASE_1(WM_CONTEXTMENU, POINTS); + LOG_LPARAM_CASE_1(WM_COPYDATA, COPYDATASTRUCT*); + LOG_LPARAM_CASE_2(WM_CREATE, CREATESTRUCTA*, CREATESTRUCTW*); + LOG_LPARAM_CASE_2(WM_DEVMODECHANGE, LPCSTR, LPCWSTR); + LOG_LPARAM_CASE_1(WM_DELETEITEM, DELETEITEMSTRUCT*); + LOG_LPARAM_CASE_1(WM_DISPLAYCHANGE, std::pair); + LOG_LPARAM_CASE_1(WM_DPICHANGED, RECT*); + LOG_LPARAM_CASE_1(WM_DRAWITEM, DRAWITEMSTRUCT*); + LOG_LPARAM_CASE_1(WM_DWMSENDICONICTHUMBNAIL, std::pair); + LOG_LPARAM_CASE_1(WM_ENTERIDLE, HWND); + LOG_LPARAM_CASE_1(WM_GESTURENOTIFY, GESTURENOTIFYSTRUCT*); + LOG_LPARAM_CASE_1(WM_GETDLGCODE, MSG*); + LOG_LPARAM_CASE_1(WM_GETDPISCALEDSIZE, SIZE*); + LOG_LPARAM_CASE_1(WM_GETICON, DWORD); + LOG_LPARAM_CASE_1(WM_GETMINMAXINFO, MINMAXINFO*); + LOG_LPARAM_CASE_2(WM_GETTEXT, LPCSTR, LPCWSTR); + LOG_LPARAM_CASE_1(WM_HELP, HELPINFO*); + LOG_LPARAM_CASE_1(WM_HOTKEY, std::pair, Compat::detail::Hex>); + LOG_LPARAM_CASE_1(WM_HSCROLL, HWND); + LOG_LPARAM_CASE_1(WM_HSCROLLCLIPBOARD, std::pair); + LOG_LPARAM_CASE_1(WM_INITMENUPOPUP, std::pair); + LOG_LPARAM_CASE_1(WM_LBUTTONDBLCLK, POINTS); + LOG_LPARAM_CASE_1(WM_LBUTTONDOWN, POINTS); + LOG_LPARAM_CASE_1(WM_LBUTTONUP, POINTS); + LOG_LPARAM_CASE_1(WM_MBUTTONDBLCLK, POINTS); + LOG_LPARAM_CASE_1(WM_MBUTTONDOWN, POINTS); + LOG_LPARAM_CASE_1(WM_MBUTTONUP, POINTS); + LOG_LPARAM_CASE_2(WM_MDICREATE, MDICREATESTRUCTA*, MDICREATESTRUCTW*); + LOG_LPARAM_CASE_1(WM_MDIGETACTIVE, BOOL*); + LOG_LPARAM_CASE_1(WM_MEASUREITEM, MEASUREITEMSTRUCT*); + LOG_LPARAM_CASE_1(WM_MENUGETOBJECT, MENUGETOBJECTINFO*); + LOG_LPARAM_CASE_1(WM_MOUSEACTIVATE, std::pair>); + LOG_LPARAM_CASE_1(WM_MOUSEHOVER, POINTS); + LOG_LPARAM_CASE_1(WM_MOUSEHWHEEL, POINTS); + LOG_LPARAM_CASE_1(WM_MOUSEMOVE, POINTS); + LOG_LPARAM_CASE_1(WM_MOUSEWHEEL, POINTS); + LOG_LPARAM_CASE_1(WM_MOVE, POINTS); + LOG_LPARAM_CASE_1(WM_MOVING, RECT*); + LOG_LPARAM_CASE_2(WM_NCCREATE, CREATESTRUCTA*, CREATESTRUCTW*); + LOG_LPARAM_CASE_1(WM_NCHITTEST, POINTS); + LOG_LPARAM_CASE_1(WM_NCLBUTTONDBLCLK, POINTS); + LOG_LPARAM_CASE_1(WM_NCLBUTTONDOWN, POINTS); + LOG_LPARAM_CASE_1(WM_NCLBUTTONUP, POINTS); + LOG_LPARAM_CASE_1(WM_NCMBUTTONDBLCLK, POINTS); + LOG_LPARAM_CASE_1(WM_NCMBUTTONDOWN, POINTS); + LOG_LPARAM_CASE_1(WM_NCMBUTTONUP, POINTS); + LOG_LPARAM_CASE_1(WM_NCMOUSEHOVER, POINTS); + LOG_LPARAM_CASE_1(WM_NCMOUSEMOVE, POINTS); + LOG_LPARAM_CASE_1(WM_NCPOINTERDOWN, POINTS); + LOG_LPARAM_CASE_1(WM_NCPOINTERUP, POINTS); + LOG_LPARAM_CASE_1(WM_NCPOINTERUPDATE, POINTS); + LOG_LPARAM_CASE_1(WM_NCRBUTTONDBLCLK, POINTS); + LOG_LPARAM_CASE_1(WM_NCRBUTTONDOWN, POINTS); + LOG_LPARAM_CASE_1(WM_NCRBUTTONUP, POINTS); + LOG_LPARAM_CASE_1(WM_NCXBUTTONDBLCLK, POINTS); + LOG_LPARAM_CASE_1(WM_NCXBUTTONDOWN, POINTS); + LOG_LPARAM_CASE_1(WM_NCXBUTTONUP, POINTS); + LOG_LPARAM_CASE_1(WM_NEXTMENU, MDINEXTMENU*); + LOG_LPARAM_CASE_1(WM_NOTIFY, NMHDR*); + LOG_LPARAM_CASE_1(WM_PARENTNOTIFY, POINTS); + LOG_LPARAM_CASE_1(WM_POINTERACTIVATE, HWND); + LOG_LPARAM_CASE_1(WM_POINTERCAPTURECHANGED, HWND); + LOG_LPARAM_CASE_1(WM_POINTERDOWN, POINTS); + LOG_LPARAM_CASE_1(WM_POINTERENTER, POINTS); + LOG_LPARAM_CASE_1(WM_POINTERHWHEEL, POINTS); + LOG_LPARAM_CASE_1(WM_POINTERLEAVE, POINTS); + LOG_LPARAM_CASE_1(WM_POINTERUP, POINTS); + LOG_LPARAM_CASE_1(WM_POINTERUPDATE, POINTS); + LOG_LPARAM_CASE_1(WM_POINTERWHEEL, POINTS); + LOG_LPARAM_CASE_1(WM_RBUTTONDBLCLK, POINTS); + LOG_LPARAM_CASE_1(WM_RBUTTONDOWN, POINTS); + LOG_LPARAM_CASE_1(WM_RBUTTONUP, POINTS); + LOG_LPARAM_CASE_1(WM_SETCURSOR, std::pair>); + LOG_LPARAM_CASE_2(WM_SETTEXT, LPCSTR, LPCWSTR); + LOG_LPARAM_CASE_2(WM_SETTINGCHANGE, LPCSTR, LPCWSTR); + LOG_LPARAM_CASE_1(WM_SIZE, POINTS); + LOG_LPARAM_CASE_1(WM_SIZING, RECT*); + LOG_LPARAM_CASE_1(WM_STYLECHANGED, STYLESTRUCT*); + LOG_LPARAM_CASE_1(WM_STYLECHANGING, STYLESTRUCT*); + LOG_LPARAM_CASE_1(WM_SYSCOMMAND, POINTS); + LOG_LPARAM_CASE_1(WM_GETTITLEBARINFOEX, TITLEBARINFOEX*); + LOG_LPARAM_CASE_1(WM_TOUCHHITTESTING, TOUCH_HIT_TESTING_INPUT*); + LOG_LPARAM_CASE_1(WM_VKEYTOITEM, HWND); + LOG_LPARAM_CASE_1(WM_VSCROLL, HWND); + LOG_LPARAM_CASE_1(WM_VSCROLLCLIPBOARD, std::pair); + LOG_LPARAM_CASE_1(WM_WINDOWPOSCHANGED, WINDOWPOS*); + LOG_LPARAM_CASE_1(WM_WINDOWPOSCHANGING, WINDOWPOS*); + LOG_LPARAM_CASE_1(WM_XBUTTONDBLCLK, POINTS); + LOG_LPARAM_CASE_1(WM_XBUTTONDOWN, POINTS); + LOG_LPARAM_CASE_1(WM_XBUTTONUP, POINTS); + + case WM_NCACTIVATE: + if (-1 == wm.lParam) + { + os << "-1"; + } + else + { + os << reinterpret_cast(wm.lParam); + } + break; + + case WM_NCCALCSIZE: + if (wm.wParam) + { + os << reinterpret_cast(wm.lParam); + } + else + { + os << reinterpret_cast(wm.lParam); + } + break; + + default: + os << Compat::hex(wm.lParam); + break; + } + +#undef LOG_LPARAM_CASE_1 +#undef LOG_LPARAM_CASE_2 +#undef LOG_PARAM_CASE_1 +#undef LOG_PARAM_CASE_2 + + os << '}'; + return os; } } diff --git a/DDrawCompat/Win32/Log.h b/DDrawCompat/Win32/Log.h index ca0f5ca..90b8f75 100644 --- a/DDrawCompat/Win32/Log.h +++ b/DDrawCompat/Win32/Log.h @@ -5,18 +5,71 @@ #include -std::ostream& operator<<(std::ostream& os, const CWPSTRUCT& cwrp); +std::ostream& operator<<(std::ostream& os, const COMPAREITEMSTRUCT& cis); +std::ostream& operator<<(std::ostream& os, const COPYDATASTRUCT& cds); +std::ostream& operator<<(std::ostream& os, const CREATESTRUCTA& cs); +std::ostream& operator<<(std::ostream& os, const CREATESTRUCTW& cs); +std::ostream& operator<<(std::ostream& os, const CWPSTRUCT& cwp); std::ostream& operator<<(std::ostream& os, const CWPRETSTRUCT& cwrp); +std::ostream& operator<<(std::ostream& os, const DELETEITEMSTRUCT& dis); std::ostream& operator<<(std::ostream& os, const DEVMODEA& dm); std::ostream& operator<<(std::ostream& os, const DEVMODEW& dm); +std::ostream& operator<<(std::ostream& os, const DRAWITEMSTRUCT& dis); +std::ostream& operator<<(std::ostream& os, const GESTURENOTIFYSTRUCT& gns); std::ostream& operator<<(std::ostream& os, HDC dc); +std::ostream& operator<<(std::ostream& os, const HELPINFO& hi); +std::ostream& operator<<(std::ostream& os, HFONT font); std::ostream& operator<<(std::ostream& os, HRGN rgn); std::ostream& operator<<(std::ostream& os, HWND hwnd); +std::ostream& operator<<(std::ostream& os, const LOGFONT& lf); +std::ostream& operator<<(std::ostream& os, const MDICREATESTRUCTA& mcs); +std::ostream& operator<<(std::ostream& os, const MDICREATESTRUCTW& mcs); +std::ostream& operator<<(std::ostream& os, const MDINEXTMENU& mnm); +std::ostream& operator<<(std::ostream& os, const MEASUREITEMSTRUCT& mis); std::ostream& operator<<(std::ostream& os, const MEMORYSTATUS& ms); +std::ostream& operator<<(std::ostream& os, const MENUGETOBJECTINFO& mgoi); +std::ostream& operator<<(std::ostream& os, const MINMAXINFO& mmi); std::ostream& operator<<(std::ostream& os, const MSG& msg); +std::ostream& operator<<(std::ostream& os, const NCCALCSIZE_PARAMS& nccs); +std::ostream& operator<<(std::ostream& os, const NMHDR& nm); +std::ostream& operator<<(std::ostream& os, const POINTS& p); std::ostream& operator<<(std::ostream& os, const RECT& rect); +std::ostream& operator<<(std::ostream& os, const SIZE& size); +std::ostream& operator<<(std::ostream& os, const STYLESTRUCT& ss); +std::ostream& operator<<(std::ostream& os, const TITLEBARINFOEX& tbi); +std::ostream& operator<<(std::ostream& os, const TOUCH_HIT_TESTING_INPUT& thti); +std::ostream& operator<<(std::ostream& os, const WINDOWPOS& wp); namespace Compat { - std::string logWm(UINT msg); + struct WindowMessage + { + UINT msg; + + WindowMessage(UINT msg) : msg(msg) {} + }; + + struct WindowMessage16 + { + UINT16 msg; + + WindowMessage16(UINT16 msg) : msg(msg) {} + }; + + struct WindowMessageStruct + { + HWND hwnd; + WindowMessage msg; + WPARAM wParam; + LPARAM lParam; + + WindowMessageStruct(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) + : hwnd(hwnd), msg(msg), wParam(wParam), lParam(lParam) + { + } + }; + + std::ostream& operator<<(std::ostream& os, WindowMessage msg); + std::ostream& operator<<(std::ostream& os, WindowMessage16 msg); + std::ostream& operator<<(std::ostream& os, WindowMessageStruct wm); }