1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2008 - TortoiseSVN
\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
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
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
20 #include "BaseWindow.h"
\r
23 ResString::ResString (HINSTANCE hInst, int resId)
\r
25 if (!::LoadString (hInst, resId, _buf, MAX_RESSTRING + 1))
\r
27 SecureZeroMemory(_buf, sizeof(_buf));
\r
32 bool CWindow::RegisterWindow(UINT style, HICON hIcon, HCURSOR hCursor, HBRUSH hbrBackground,
\r
33 LPCTSTR lpszMenuName, LPCTSTR lpszClassName, HICON hIconSm)
\r
37 // Fill in the window class structure with default parameters
\r
39 wcx.cbSize = sizeof(WNDCLASSEX); // size of structure
\r
40 wcx.style = style; // redraw if size changes
\r
41 wcx.lpfnWndProc = CWindow::stWinMsgHandler; // points to window procedure
\r
42 wcx.cbClsExtra = 0; // no extra class memory
\r
43 wcx.cbWndExtra = 0; // no extra window memory
\r
44 wcx.hInstance = hResource; // handle to instance
\r
45 wcx.hIcon = hIcon; // predefined app. icon
\r
46 wcx.hCursor = hCursor; // predefined arrow
\r
47 wcx.hbrBackground = hbrBackground; // white background brush
\r
48 wcx.lpszMenuName = lpszMenuName; // name of menu resource
\r
49 wcx.lpszClassName = lpszClassName; // name of window class
\r
50 wcx.hIconSm = hIconSm; // small class icon
\r
52 // Register the window class.
\r
53 return RegisterWindow(&wcx);
\r
56 bool CWindow::RegisterWindow(CONST WNDCLASSEX* wcx)
\r
58 // Register the window class.
\r
59 sClassName = std::wstring(wcx->lpszClassName);
\r
61 if (RegisterClassEx(wcx) == 0)
\r
67 LRESULT CALLBACK CWindow::stWinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
71 if (uMsg == WM_NCCREATE)
\r
73 // get the pointer to the window from lpCreateParams which was set in CreateWindow
\r
74 SetWindowLongPtr(hwnd, GWLP_USERDATA, (long)((LPCREATESTRUCT(lParam))->lpCreateParams));
\r
77 // get the pointer to the window
\r
78 pWnd = GetObjectFromWindow(hwnd);
\r
80 // if we have the pointer, go to the message handler of the window
\r
81 // else, use DefWindowProc
\r
83 return pWnd->WinMsgHandler(hwnd, uMsg, wParam, lParam);
\r
85 return DefWindowProc(hwnd, uMsg, wParam, lParam);
\r
88 bool CWindow::Create()
\r
90 // Create the window
\r
98 return Create(WS_OVERLAPPEDWINDOW | WS_VISIBLE, NULL, &rect);
\r
101 bool CWindow::Create(DWORD dwStyles, HWND hParent /* = NULL */, RECT* rect /* = NULL */)
\r
103 return CreateEx(0, dwStyles, hParent, rect);
\r
106 bool CWindow::CreateEx(DWORD dwExStyles, DWORD dwStyles, HWND hParent /* = NULL */, RECT* rect /* = NULL */)
\r
108 // send the this pointer as the window creation parameter
\r
110 m_hwnd = CreateWindowEx(dwExStyles, sClassName.c_str(), sWindowTitle.c_str(), dwStyles, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hParent, NULL, hResource, (void *)this);
\r
113 m_hwnd = CreateWindowEx(dwExStyles, sClassName.c_str(), sWindowTitle.c_str(), dwStyles, rect->left, rect->top,
\r
114 rect->right - rect->left, rect->bottom - rect->top, hParent, NULL, hResource,
\r
117 return (m_hwnd != NULL);
\r
120 void CWindow::SetTransparency(BYTE alpha, COLORREF color /* = 0xFF000000 */)
\r
124 LONG_PTR exstyle = GetWindowLongPtr(*this, GWL_EXSTYLE);
\r
125 exstyle &= ~WS_EX_LAYERED;
\r
126 SetWindowLongPtr(*this, GWL_EXSTYLE, exstyle);
\r
130 LONG_PTR exstyle = GetWindowLongPtr(*this, GWL_EXSTYLE);
\r
131 exstyle |= WS_EX_LAYERED;
\r
132 SetWindowLongPtr(*this, GWL_EXSTYLE, exstyle);
\r
134 COLORREF col = color;
\r
135 DWORD flags = LWA_ALPHA;
\r
136 if (col & 0xFF000000)
\r
138 col = RGB(255, 255, 255);
\r
143 flags = LWA_COLORKEY;
\r
145 SetLayeredWindowAttributes(*this, col, alpha, flags);
\r