Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[r5083]: tags / V3_03 / ControlExtns.cpp Maximize Restore History

Download this file

ControlExtns.cpp    159 lines (130 with data), 3.3 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// ControlExtns.cpp
//
#include "stdafx.h"
#include "ControlExtns.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const COLORREF crefInFocus = (RGB(222,255,222)); // Light green
const COLORREF crefNoFocus = (RGB(255,255,255)); // White
/////////////////////////////////////////////////////////////////////////////
// CEditExtn
CEditExtn::CEditExtn()
{
brInFocus.CreateSolidBrush(crefInFocus);
brNoFocus.CreateSolidBrush(crefNoFocus);
}
CEditExtn::~CEditExtn()
{
}
BEGIN_MESSAGE_MAP(CEditExtn, CEdit)
//{{AFX_MSG_MAP(CEditExtn)
ON_WM_SETFOCUS()
ON_WM_KILLFOCUS()
ON_WM_CTLCOLOR_REFLECT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEditExtn message handlers
void CEditExtn::OnSetFocus(CWnd* pOldWnd)
{
m_bIsFocused = TRUE;
CEdit::OnSetFocus(pOldWnd);
Invalidate(TRUE);
}
void CEditExtn::OnKillFocus(CWnd* pNewWnd)
{
m_bIsFocused = FALSE;
CEdit::OnKillFocus(pNewWnd);
Invalidate(TRUE);
}
HBRUSH CEditExtn::CtlColor(CDC* pDC, UINT /* nCtlColor */)
{
if (m_bIsFocused == TRUE) {
pDC->SetBkColor(crefInFocus);
return brInFocus;
} else {
pDC->SetBkColor(crefNoFocus);
return brNoFocus;
}
}
/////////////////////////////////////////////////////////////////////////////
// CListBoxExtn
CListBoxExtn::CListBoxExtn()
{
brInFocus.CreateSolidBrush(crefInFocus);
brNoFocus.CreateSolidBrush(crefNoFocus);
}
CListBoxExtn::~CListBoxExtn()
{
}
BEGIN_MESSAGE_MAP(CListBoxExtn, CListBox)
//{{AFX_MSG_MAP(CListBoxExtn)
ON_WM_SETFOCUS()
ON_WM_KILLFOCUS()
ON_WM_CTLCOLOR_REFLECT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListBoxExtn message handlers
void CListBoxExtn::OnSetFocus(CWnd* pOldWnd)
{
m_bIsFocused = TRUE;
CListBox::OnSetFocus(pOldWnd);
Invalidate(TRUE);
}
void CListBoxExtn::OnKillFocus(CWnd* pNewWnd)
{
m_bIsFocused = FALSE;
CListBox::OnKillFocus(pNewWnd);
Invalidate(TRUE);
}
HBRUSH CListBoxExtn::CtlColor(CDC* pDC, UINT /* nCtlColor */)
{
if (m_bIsFocused == TRUE) {
pDC->SetBkColor(crefInFocus);
return brInFocus;
} else {
pDC->SetBkColor(crefNoFocus);
return brNoFocus;
}
}
/////////////////////////////////////////////////////////////////////////////
// CComboBoxExtn
BEGIN_MESSAGE_MAP(CComboBoxExtn, CComboBox)
//{{AFX_MSG_MAP(CComboBoxExtn)
ON_WM_CTLCOLOR()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CComboBoxExt message handlers
HBRUSH CComboBoxExtn::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if (nCtlColor == CTLCOLOR_EDIT) {
// Extended Edit control
if (m_edit.GetSafeHwnd() == NULL)
m_edit.SubclassWindow(pWnd->GetSafeHwnd());
}
else if (nCtlColor == CTLCOLOR_LISTBOX) {
// Extended ListBox control
if (m_listbox.GetSafeHwnd() == NULL)
m_listbox.SubclassWindow(pWnd->GetSafeHwnd());
}
return CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
}
void CComboBoxExtn::OnDestroy()
{
if (m_edit.GetSafeHwnd() != NULL)
m_edit.UnsubclassWindow();
if (m_listbox.GetSafeHwnd() != NULL)
m_listbox.UnsubclassWindow();
CComboBox::OnDestroy();
}
void CComboBoxExtn::ChangeColour()
{
m_edit.ChangeColour();
m_listbox.ChangeColour();
}