OSDN Git Service

Show Ignore Sub Menu
[tortoisegit/TortoiseGitJp.git] / src / Utils / MiscUI / BaseWindow.h
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2007 - Stefan Kueng\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #pragma once\r
20 #include <string>\r
21 \r
22 \r
23 /**\r
24  * \ingroup Utils\r
25  * Loads a string from the application resources.\r
26  */\r
27 class ResString\r
28 {\r
29         enum { MAX_RESSTRING = 1024 };\r
30 public:\r
31         ResString (HINSTANCE hInst, int resId);\r
32         operator TCHAR const * () const { return _buf; }\r
33 private:\r
34         TCHAR _buf [MAX_RESSTRING + 1];\r
35 };\r
36 \r
37 /**\r
38  * \ingroup Utils\r
39  * A base window class.\r
40  * Provides separate window message handlers for every window object based on\r
41  * this class.\r
42  */\r
43 class CWindow\r
44 {\r
45 public:\r
46         virtual bool RegisterWindow(UINT style, HICON hIcon, HCURSOR hCursor, HBRUSH hbrBackground, \r
47                 LPCTSTR lpszMenuName, LPCTSTR lpszClassName, HICON hIconSm);\r
48         virtual bool RegisterWindow(CONST WNDCLASSEX* wcx);\r
49 \r
50         /// static message handler to put in WNDCLASSEX structure\r
51         static LRESULT CALLBACK stWinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);\r
52 \r
53         /**\r
54          * Sets the window title. \r
55          */\r
56         void SetWindowTitle(const std::wstring& sTitle) \r
57         {\r
58                 sWindowTitle = sTitle;\r
59         };\r
60 \r
61         /**\r
62          * Sets the transparency of the window.\r
63          * \remark note that this also sets the WS_EX_LAYERED style!\r
64          */\r
65         void SetTransparency(BYTE alpha, COLORREF color = 0xFF000000);\r
66 \r
67         virtual bool Create();\r
68         virtual bool Create(DWORD dwStyles, HWND hParent = NULL, RECT* rect = NULL);\r
69         virtual bool CreateEx(DWORD dwExStyles, DWORD dwStyles, HWND hParent = NULL, RECT* rect = NULL);\r
70 \r
71         //void MsgLoop();\r
72         bool IsWindowClosed() { return bWindowClosed; };\r
73 \r
74         operator HWND() {return m_hwnd;}\r
75 protected:\r
76         HINSTANCE hResource;\r
77         HWND m_hwnd;\r
78         bool bWindowClosed;\r
79         std::wstring sClassName;\r
80         std::wstring sWindowTitle;\r
81 \r
82         //constructor \r
83         CWindow(HINSTANCE hInst, CONST WNDCLASSEX* wcx = NULL) : m_hwnd(NULL)\r
84                 , hResource(NULL)\r
85                 , bWindowClosed(FALSE)\r
86         {\r
87                 hResource = hInst; \r
88                 if (wcx != NULL)\r
89                         RegisterWindow(wcx);\r
90         };\r
91 \r
92         // the real message handler\r
93         virtual LRESULT CALLBACK WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) = 0;\r
94 \r
95         // returns a pointer the window (stored as the WindowLong)\r
96         inline static CWindow * GetObjectFromWindow(HWND hWnd)\r
97         {\r
98                 return (CWindow *)GetWindowLongPtr(hWnd, GWLP_USERDATA);\r
99         }\r
100 };\r
101 \r