Fixed issue #1741: Push / Pull Dialog URL combo box should not be filled unless enabled
[TortoiseGit.git] / src / Utils / MiscUI / BaseWindow.h
blobe12ea43612dc1324390f4c5527e682044b817d6e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2007, 2010, 2013 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
21 #include "ResString.h"
23 #include <string>
26 /**
27 * \ingroup Utils
28 * A base window class.
29 * Provides separate window message handlers for every window object based on
30 * this class.
32 class CWindow
34 public:
35 virtual bool RegisterWindow(UINT style, HICON hIcon, HCURSOR hCursor,
36 HBRUSH hbrBackground, LPCTSTR lpszMenuName,
37 LPCTSTR lpszClassName, HICON hIconSm);
38 virtual bool RegisterWindow(CONST WNDCLASSEX* wcx);
40 /// static message handler to put in WNDCLASSEX structure
41 static LRESULT CALLBACK stWinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
43 /**
44 * Sets the window title.
46 void SetWindowTitle(const std::wstring& sTitle)
48 sWindowTitle = sTitle;
51 void SetRegistryPath(const std::wstring& sPath)
53 size_t slashPos = sPath.find_last_of('\\');
54 sRegistryPath = sPath.substr(0, slashPos);
55 sRegistryValue = sPath.substr(slashPos+1);
58 /**
59 * Sets the transparency of the window.
60 * \remark note that this also sets the WS_EX_LAYERED style!
62 void SetTransparency(BYTE alpha, COLORREF color = 0xFF000000);
64 virtual bool Create();
65 virtual bool Create(DWORD dwStyles, HWND hParent = NULL, RECT* rect = NULL);
66 virtual bool CreateEx(DWORD dwExStyles, DWORD dwStyles, HWND hParent = NULL, RECT* rect = NULL, LPCTSTR classname = NULL);
68 //void MsgLoop();
69 bool IsWindowClosed() { return bWindowClosed; };
71 operator HWND() {return m_hwnd;}
72 operator HWND() const {return m_hwnd;}
73 protected:
74 HINSTANCE hResource;
75 HWND m_hwnd;
76 HWND m_hParent;
77 bool bWindowClosed;
78 std::wstring sClassName;
79 std::wstring sWindowTitle;
80 std::wstring sRegistryPath;
81 std::wstring sRegistryValue;
82 bool bWindowRestored;
84 //constructor
85 CWindow(HINSTANCE hInst, CONST WNDCLASSEX* wcx = NULL)
86 : m_hwnd(NULL)
87 , hResource(NULL)
88 , m_hParent(NULL)
89 , bWindowClosed(FALSE)
90 , bWindowRestored(false)
92 hResource = hInst;
93 if (wcx != NULL)
94 RegisterWindow(wcx);
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 (CWindow *)GetWindowLongPtr(hWnd, GWLP_USERDATA);