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
|
// DiskBox.cpp : implementation file
//
#include "stdafx.h"
#include "DiskBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDiskBox
CDiskBox::CDiskBox()
{
m_nID = IDC_PROPERTY_DEVICE;
m_nLeft = 10;
m_nSize = 80;
}
CDiskBox::~CDiskBox()
{
}
BEGIN_MESSAGE_MAP(CDiskBox, CButton)
//{{AFX_MSG_MAP(CDiskBox)
ON_WM_SETFOCUS()
ON_CBN_SELCHANGE(IDC_PROPERTY_DEVICE, OnSelectChanged)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDiskBox message handlers
void CDiskBox::OnSelectChanged()
{
GetParent()->SendMessage(WM_GROUP_BOX_UPDATED, 'GB', 'DVLU');
}
void CDiskBox::PreSubclassWindow()
{
//
// Make sure that this control has the BS_ICON style set.
// If not, it behaves very strangely:
// It erases itself if the user TABs to controls in the dialog,
// unless the user first clicks it. Very strange!!
//
ModifyStyle(0, BS_ICON|WS_TABSTOP|WS_GROUP);
CString strTitle;
GetWindowText(strTitle);
int nWidth = AssemblingTitle();
CRect r;
GetWindowRect(&r);
ScreenToClient(r);
r.OffsetRect(m_nLeft, 0);
r.bottom = r.top + m_nSize;
r.right = r.left + m_nSize + nWidth;
m_ComboBox.Create(WS_CHILD | CBS_DROPDOWN | WS_VSCROLL |
CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST,
r, this, m_nID);
m_ComboBox.SetFont(GetFont(), true);
m_ComboBox.ShowWindow(SW_SHOW);
SetListboxHeight(m_ComboBox.m_hWnd);
}
void CDiskBox::SetListboxHeight(HWND hWnd)
{
RECT rc;
::SendMessage(hWnd, LB_GETITEMRECT, 0, (LPARAM)&rc);
::GetClientRect(hWnd, &rc);
int cyClient= rc.bottom - rc.top;
::GetWindowRect(hWnd, &rc);
int cxListbox = rc.right - rc.left;
int cyListbox = rc.bottom - rc.top;
if (g_nDisks + g_nCdroms > 8) {
cyListbox = 18*8;
} else if (g_nDisks + g_nCdroms > 4) {
cyListbox = max(80, 18 * (g_nDisks + g_nCdroms));
} else {
cyListbox = 80;
}
::SetWindowPos(hWnd, NULL, 0, 0,
cxListbox, cyListbox,
SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCOPYBITS|
SWP_NOOWNERZORDER|SWP_NOZORDER
);
}
int CDiskBox::AssemblingTitle()
{
//
// The group box title needs to be erased, but I need to keep
// the border away from the check box text. I create a string
// of spaces (' ') that is the same length as the title was
// plus the size of the checkbox. plus a little more.
//
CString strOldTitle, strNewTitle;
GetWindowText(strOldTitle);
CClientDC dc(this);
CFont* pOldFont = dc.SelectObject(GetFont());
CSize czText = dc.GetTextExtent(strOldTitle);
int nRet = czText.cx;
int nTarget = czText.cx + m_nSize;
while(czText.cx < nTarget)
{
strNewTitle.Insert(0, ' ');
czText = dc.GetTextExtent(strNewTitle);
}
dc.SelectObject(pOldFont);
SetWindowText(strNewTitle);
return nRet;
}
void CDiskBox::OnSetFocus(CWnd* pOldWnd)
{
CButton::OnSetFocus(pOldWnd);
m_ComboBox.SetFocus();
}
|