1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016 - TortoiseGit
4 // Copyright (C) 2003-2007, 2010, 2013-2015 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "ResString.h"
29 * A base window class.
30 * Provides separate window message handlers for every window object based on
36 virtual bool RegisterWindow(UINT style
, HICON hIcon
, HCURSOR hCursor
,
37 HBRUSH hbrBackground
, LPCTSTR lpszMenuName
,
38 LPCTSTR lpszClassName
, HICON hIconSm
);
39 virtual bool RegisterWindow(CONST WNDCLASSEX
* wcx
);
41 /// static message handler to put in WNDCLASSEX structure
42 static LRESULT CALLBACK
stWinMsgHandler(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
45 * Sets the window title.
47 void SetWindowTitle(const std::wstring
& sTitle
)
49 sWindowTitle
= sTitle
;
52 void SetRegistryPath(const std::wstring
& sPath
)
54 size_t slashPos
= sPath
.find_last_of('\\');
55 sRegistryPath
= sPath
.substr(0, slashPos
);
56 sRegistryValue
= sPath
.substr(slashPos
+1);
60 * Sets the transparency of the window.
61 * \remark note that this also sets the WS_EX_LAYERED style!
63 void SetTransparency(BYTE alpha
, COLORREF color
= 0xFF000000);
65 virtual bool Create();
66 virtual bool Create(DWORD dwStyles
, HWND hParent
= nullptr, RECT
* rect
= nullptr);
67 virtual bool CreateEx(DWORD dwExStyles
, DWORD dwStyles
, HWND hParent
= nullptr, RECT
* rect
= nullptr, LPCTSTR classname
= nullptr);
70 bool IsWindowClosed() const { return bWindowClosed
; };
72 operator HWND() const {return m_hwnd
;}
78 std::wstring sClassName
;
79 std::wstring sWindowTitle
;
80 std::wstring sRegistryPath
;
81 std::wstring sRegistryValue
;
85 CWindow(HINSTANCE hInstance
, CONST WNDCLASSEX
* wcx
= nullptr)
89 , bWindowClosed(FALSE
)
90 , bWindowRestored(false)
92 hResource
= hInstance
;
97 // the real message handler
98 virtual LRESULT CALLBACK
WinMsgHandler(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
) = 0;
100 // returns a pointer the window (stored as the WindowLong)
101 inline static CWindow
* GetObjectFromWindow(HWND hWnd
)
103 return reinterpret_cast<CWindow
*>(GetWindowLongPtr(hWnd
, GWLP_USERDATA
));