Added support from disable trimming
[TortoiseGit.git] / src / Utils / MiscUI / BaseWindow.h
blob08e22d6467d14d95a87b877535328c6bd38c642b
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2007, 2010 - 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.
19 #pragma once
20 #include <string>
23 /**
24 * \ingroup Utils
25 * Loads a string from the application resources.
27 class ResString
29 enum { MAX_RESSTRING = 1024 };
30 public:
31 ResString (HINSTANCE hInst, int resId);
32 operator TCHAR const * () const { return _buf; }
33 private:
34 TCHAR _buf [MAX_RESSTRING + 1];
37 /**
38 * \ingroup Utils
39 * A base window class.
40 * Provides separate window message handlers for every window object based on
41 * this class.
43 class CWindow
45 public:
46 virtual bool RegisterWindow(UINT style, HICON hIcon, HCURSOR hCursor, HBRUSH hbrBackground,
47 LPCTSTR lpszMenuName, LPCTSTR lpszClassName, HICON hIconSm);
48 virtual bool RegisterWindow(CONST WNDCLASSEX* wcx);
50 /// static message handler to put in WNDCLASSEX structure
51 static LRESULT CALLBACK stWinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
53 /**
54 * Sets the window title.
56 void SetWindowTitle(const std::wstring& sTitle)
58 sWindowTitle = sTitle;
61 void SetRegistryPath(const std::wstring& sPath)
63 size_t slashPos = sPath.find_last_of('\\');
64 sRegistryPath = sPath.substr(0, slashPos);
65 sRegistryValue = sPath.substr(slashPos+1);
68 /**
69 * Sets the transparency of the window.
70 * \remark note that this also sets the WS_EX_LAYERED style!
72 void SetTransparency(BYTE alpha, COLORREF color = 0xFF000000);
74 virtual bool Create();
75 virtual bool Create(DWORD dwStyles, HWND hParent = NULL, RECT* rect = NULL);
76 virtual bool CreateEx(DWORD dwExStyles, DWORD dwStyles, HWND hParent = NULL, RECT* rect = NULL);
78 //void MsgLoop();
79 bool IsWindowClosed() const { return bWindowClosed; };
81 operator HWND() const {return m_hwnd;}
82 protected:
83 HINSTANCE hResource;
84 HWND m_hwnd;
85 bool bWindowClosed;
86 std::wstring sClassName;
87 std::wstring sWindowTitle;
88 std::wstring sRegistryPath;
89 std::wstring sRegistryValue;
90 bool bWindowRestored;
92 //constructor
93 CWindow(HINSTANCE hInst, CONST WNDCLASSEX* wcx = NULL) : m_hwnd(NULL)
94 , hResource(NULL)
95 , bWindowClosed(FALSE)
96 , bWindowRestored(false)
98 hResource = hInst;
99 if (wcx != NULL)
100 RegisterWindow(wcx);
103 // the real message handler
104 virtual LRESULT CALLBACK WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) = 0;
106 // returns a pointer the window (stored as the WindowLong)
107 inline static CWindow * GetObjectFromWindow(HWND hWnd)
109 return (CWindow *)GetWindowLongPtr(hWnd, GWLP_USERDATA);