Menu

[r49]: / trunk / src / BaseWindow.cpp  Maximize  Restore  History

Download this file

128 lines (109 with data), 3.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "stdafx.h"
#include "BaseWindow.h"
ResString::ResString (HINSTANCE hInst, int resId)
{
if (!::LoadString (hInst, resId, _buf, MAX_RESSTRING + 1))
{
ZeroMemory(_buf, sizeof(_buf));
}
}
bool CWindow::RegisterWindow(UINT style, HICON hIcon, HCURSOR hCursor, HBRUSH hbrBackground,
LPCTSTR lpszMenuName, LPCTSTR lpszClassName, HICON hIconSm)
{
WNDCLASSEX wcx;
// Fill in the window class structure with default parameters
wcx.cbSize = sizeof(WNDCLASSEX); // size of structure
wcx.style = style; // redraw if size changes
wcx.lpfnWndProc = CWindow::stWinMsgHandler; // points to window procedure
wcx.cbClsExtra = 0; // no extra class memory
wcx.cbWndExtra = 0; // no extra window memory
wcx.hInstance = hResource; // handle to instance
wcx.hIcon = hIcon; // predefined app. icon
wcx.hCursor = hCursor; // predefined arrow
wcx.hbrBackground = hbrBackground; // white background brush
wcx.lpszMenuName = lpszMenuName; // name of menu resource
wcx.lpszClassName = lpszClassName; // name of window class
wcx.hIconSm = hIconSm; // small class icon
// Register the window class.
return RegisterWindow(&wcx);
}
bool CWindow::RegisterWindow(CONST WNDCLASSEX* wcx)
{
// Register the window class.
sClassName = std::wstring(wcx->lpszClassName);
if (RegisterClassEx(wcx) == 0)
return FALSE;
else
return TRUE;
}
LRESULT CALLBACK CWindow::stWinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CWindow* pWnd;
if (uMsg == WM_NCCREATE)
{
// get the pointer to the window from lpCreateParams which was set in CreateWindow
SetWindowLongPtr(hwnd, GWLP_USERDATA, (long)((LPCREATESTRUCT(lParam))->lpCreateParams));
}
// get the pointer to the window
pWnd = GetObjectFromWindow(hwnd);
// if we have the pointer, go to the message handler of the window
// else, use DefWindowProc
if (pWnd)
return pWnd->WinMsgHandler(hwnd, uMsg, wParam, lParam);
else
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
bool CWindow::Create()
{
// Create the window
RECT rect;
rect.top = 0;
rect.left = 0;
rect.right = 600;
rect.bottom = 400;
return Create(WS_OVERLAPPEDWINDOW | WS_VISIBLE, NULL, &rect);
}
bool CWindow::Create(DWORD dwStyles, HWND hParent /* = NULL */, RECT* rect /* = NULL */)
{
return CreateEx(0, dwStyles, hParent, rect);
}
bool CWindow::CreateEx(DWORD dwExStyles, DWORD dwStyles, HWND hParent /* = NULL */, RECT* rect /* = NULL */)
{
// send the this pointer as the window creation parameter
if (rect == NULL)
m_hwnd = CreateWindowEx(dwExStyles, sClassName.c_str(), sWindowTitle.c_str(), dwStyles, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hParent, NULL, hResource, (void *)this);
else
{
m_hwnd = CreateWindowEx(dwExStyles, sClassName.c_str(), sWindowTitle.c_str(), dwStyles, rect->left, rect->top,
rect->right - rect->left, rect->bottom - rect->top, hParent, NULL, hResource,
(void *)this);
}
return (m_hwnd != NULL);
}
void CWindow::SetTransparency(BYTE alpha, COLORREF color /* = 0xFF000000 */)
{
if (alpha == 255)
{
LONG exstyle = GetWindowLongPtr(*this, GWL_EXSTYLE);
exstyle &= ~WS_EX_LAYERED;
SetWindowLongPtr(*this, GWL_EXSTYLE, exstyle);
}
else
{
LONG exstyle = GetWindowLongPtr(*this, GWL_EXSTYLE);
exstyle |= WS_EX_LAYERED;
SetWindowLongPtr(*this, GWL_EXSTYLE, exstyle);
}
COLORREF col = color;
DWORD flags = LWA_ALPHA;
if (col & 0xFF000000)
{
col = RGB(255, 255, 255);
flags = LWA_ALPHA;
}
else
{
flags = LWA_COLORKEY;
}
SetLayeredWindowAttributes(*this, col, alpha, flags);
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.