From a6a767d9ff581e94649ff8fe4ab1586d77f2082c Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Mon, 14 Nov 2011 07:53:19 +0000 Subject: [PATCH] Switched to using SetWindowLongPtr/GetWindowLongPtr instead of SetProp/GetProp for faster retrieval of window pointer. --- Library/MeterWindow.cpp | 67 +++++++++++++++-------------------------- Library/MeterWindow.h | 9 +++--- 2 files changed, 28 insertions(+), 48 deletions(-) diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 7662be23..097277f4 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -246,7 +246,7 @@ int CMeterWindow::Initialize(CRainmeter& Rainmeter) // Register the windowclass WNDCLASSEX wc = {sizeof(WNDCLASSEX)}; wc.style = CS_NOCLOSE | CS_DBLCLKS; - wc.lpfnWndProc = WndProc; + wc.lpfnWndProc = InitialWndProc; wc.hInstance = m_Rainmeter->GetInstance(); wc.hCursor = NULL; // The cursor should be controlled by using SetCursor() when needed. wc.lpszClassName = METERWINDOW_CLASS_NAME; @@ -3529,17 +3529,6 @@ LRESULT CMeterWindow::OnMouseLeave(UINT uMsg, WPARAM wParam, LPARAM lParam) return 0; } -/* -** OnCreate -** -** During window creation we do nothing. -** -*/ -LRESULT CMeterWindow::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - return 0; -} - /* ** OnCommand ** @@ -4077,17 +4066,6 @@ void CMeterWindow::SnapToWindow(CMeterWindow* window, LPWINDOWPOS wp) } } -/* -** OnDestroy -** -** During destruction of the window do nothing. -** -*/ -LRESULT CMeterWindow::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - return 0; -} - /* ** OnDwmColorChange ** @@ -4826,34 +4804,16 @@ LRESULT CMeterWindow::OnMove(UINT uMsg, WPARAM wParam, LPARAM lParam) /* ** WndProc ** -** The window procedure for the Meter +** The main window procedure for the meter window. ** */ LRESULT CALLBACK CMeterWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - CMeterWindow* Window = NULL; - - if (uMsg == WM_CREATE) - { - // Fetch this window-object from the CreateStruct - Window=(CMeterWindow*)((LPCREATESTRUCT)lParam)->lpCreateParams; - - SetProp(hWnd, L"RAINMETER", Window); - } - else if (uMsg == WM_DESTROY) - { - RemoveProp(hWnd, L"RAINMETER"); - } - else - { - Window = (CMeterWindow*)GetProp(hWnd, L"RAINMETER"); - } + CMeterWindow* window = (CMeterWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA); BEGIN_MESSAGEPROC MESSAGE(OnPaint, WM_PAINT) MESSAGE(OnMove, WM_MOVE) - MESSAGE(OnCreate, WM_CREATE) - MESSAGE(OnDestroy, WM_DESTROY) MESSAGE(OnTimer, WM_TIMER) MESSAGE(OnCommand, WM_COMMAND) MESSAGE(OnSysCommand, WM_SYSCOMMAND) @@ -4897,6 +4857,27 @@ LRESULT CALLBACK CMeterWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR END_MESSAGEPROC } +/* +** InitialWndProc +** +** The initial window procedure for the meter window. Passes control to WndProc after initial setup. +** +*/ +LRESULT CALLBACK CMeterWindow::InitialWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + if (uMsg == WM_NCCREATE) + { + CMeterWindow* window = (CMeterWindow*)((LPCREATESTRUCT)lParam)->lpCreateParams; + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG)window); + + // Change the window procedure over to MainWndProc now that GWLP_USERDATA is set + SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG)WndProc); + return TRUE; + } + + return DefWindowProc(hWnd, uMsg, wParam, lParam); +} + /* ** OnDelayedExecute ** diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index 344411a0..fe4b6803 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -27,10 +27,10 @@ #include "ConfigParser.h" #include "Group.h" -#define BEGIN_MESSAGEPROC if (Window) { switch (uMsg) { -#define MESSAGE(handler, msg) case msg: return Window->handler(uMsg, wParam, lParam); +#define BEGIN_MESSAGEPROC switch (uMsg) { +#define MESSAGE(handler, msg) case msg: return window->handler(uMsg, wParam, lParam); #define REJECT_MESSAGE(msg) case msg: return 0; -#define END_MESSAGEPROC } } return DefWindowProc(hWnd, uMsg, wParam, lParam); +#define END_MESSAGEPROC } return DefWindowProc(hWnd, uMsg, wParam, lParam); #define WM_DELAYED_EXECUTE WM_APP + 0 #define WM_DELAYED_REFRESH WM_APP + 1 @@ -254,11 +254,10 @@ public: protected: static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + static LRESULT CALLBACK InitialWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnMove(UINT uMsg, WPARAM wParam, LPARAM lParam); - LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam); - LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam);