29
BOOL CPopUpWnd::Create(CPocketPJDlg* pParent)
29
BOOL CPopUpWnd::Create (CPocketPJDlg* pParent)
33
33
m_ParentWnd = pParent;
35
35
// Register window class
36
CString csClassName = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,
38
CBrush(::GetSysColor(COLOR_BTNFACE)));
36
CString csClassName = AfxRegisterWndClass (CS_HREDRAW|CS_VREDRAW,
38
CBrush (::GetSysColor (COLOR_BTNFACE)));
40
40
// Create popup window
41
bSuccess = CreateEx(WS_EX_DLGMODALFRAME|WS_EX_TOPMOST, // Extended style
42
csClassName, // Classname
43
_T("PocketPJ"), // Title
44
WS_POPUP|WS_BORDER|WS_CAPTION, // style
45
0,0, // position - updated soon.
46
1,1, // Size - updated soon
47
pParent->GetSafeHwnd(), // handle to parent
41
bSuccess = CreateEx (WS_EX_DLGMODALFRAME|WS_EX_TOPMOST, // Extended style
42
csClassName, // Classname
43
_T ("PocketPJ"), // Title
44
WS_POPUP|WS_BORDER|WS_CAPTION, // style
45
0,0, // position - updated soon.
46
1,1, // Size - updated soon
47
pParent->GetSafeHwnd(), // handle to parent
55
56
// Now create the controls
56
CRect TempRect(0,0,10,10);
57
CRect TempRect (0,0,10,10);
58
59
/* |SS_LEFTNOWORDWRAP */
59
bSuccess = m_Title1.Create(_T("Title1"), WS_CHILD|WS_VISIBLE|SS_NOPREFIX,
60
TempRect, this, IDC_TITLE1);
64
bSuccess = m_Title2.Create(_T("Title2"), WS_CHILD|WS_VISIBLE|SS_NOPREFIX,
65
TempRect, this, IDC_TITLE2);
69
bSuccess = m_Title3.Create(_T("Title3"), WS_CHILD|WS_VISIBLE|SS_NOPREFIX,
70
TempRect, this, IDC_TITLE3);
74
bSuccess = m_Btn1.Create(_T("Button1"),
75
WS_CHILD|WS_VISIBLE|WS_TABSTOP| BS_PUSHBUTTON,
76
TempRect, this, IDC_BTN1);
80
bSuccess = m_Btn2.Create(_T("Button2"),
81
WS_CHILD|WS_VISIBLE|WS_TABSTOP| BS_PUSHBUTTON,
82
TempRect, this, IDC_BTN2);
86
CFont *ft1 = new CFont,
60
bSuccess = m_Title1.Create (_T ("Title1"), WS_CHILD|WS_VISIBLE|SS_NOPREFIX,
61
TempRect, this, IDC_TITLE1);
66
bSuccess = m_Title2.Create (_T ("Title2"), WS_CHILD|WS_VISIBLE|SS_NOPREFIX,
67
TempRect, this, IDC_TITLE2);
72
bSuccess = m_Title3.Create (_T ("Title3"), WS_CHILD|WS_VISIBLE|SS_NOPREFIX,
73
TempRect, this, IDC_TITLE3);
78
bSuccess = m_Btn1.Create (_T ("Button1"),
79
WS_CHILD|WS_VISIBLE|WS_TABSTOP| BS_PUSHBUTTON,
80
TempRect, this, IDC_BTN1);
85
bSuccess = m_Btn2.Create (_T ("Button2"),
86
WS_CHILD|WS_VISIBLE|WS_TABSTOP| BS_PUSHBUTTON,
87
TempRect, this, IDC_BTN2);
92
CFont *ft1 = new CFont,
92
memset(&lf, 0, sizeof(LOGFONT));
98
memset (&lf, 0, sizeof (LOGFONT));
94
lstrcpy(lf.lfFaceName, _T("Arial"));
95
VERIFY(ft1->CreateFontIndirect(&lf));
96
VERIFY(ft3->CreateFontIndirect(&lf));
100
lstrcpy (lf.lfFaceName, _T ("Arial"));
101
VERIFY (ft1->CreateFontIndirect (&lf));
102
VERIFY (ft3->CreateFontIndirect (&lf));
99
VERIFY(ft2->CreateFontIndirect(&lf));
105
VERIFY (ft2->CreateFontIndirect (&lf));
101
m_Title1.SetFont(ft1, TRUE);
102
m_Title2.SetFont(ft2, TRUE);
103
m_Title3.SetFont(ft3, TRUE);
107
m_Title1.SetFont (ft1, TRUE);
108
m_Title2.SetFont (ft2, TRUE);
109
m_Title3.SetFont (ft3, TRUE);
116
void CPopUpWnd::SetContent(const CPopUpContent &content)
122
void CPopUpWnd::SetContent (const CPopUpContent &content)
118
m_Title1.SetWindowText(content.m_Title1);
119
m_Title2.SetWindowText(content.m_Title2);
120
m_Title3.SetWindowText(content.m_Title3);
124
m_Title1.SetWindowText (content.m_Title1);
125
m_Title2.SetWindowText (content.m_Title2);
126
m_Title3.SetWindowText (content.m_Title3);
122
128
if (content.m_Btn1 != "") {
123
m_Btn1.SetWindowText(content.m_Btn1);
124
m_Btn1.ShowWindow(SW_SHOW);
129
m_Btn1.SetWindowText (content.m_Btn1);
130
m_Btn1.ShowWindow (SW_SHOW);
126
m_Btn1.ShowWindow(SW_HIDE);
132
m_Btn1.ShowWindow (SW_HIDE);
129
135
if (content.m_Btn2 != "") {
130
m_Btn2.SetWindowText(content.m_Btn2);
131
m_Btn2.ShowWindow(SW_SHOW);
136
m_Btn2.SetWindowText (content.m_Btn2);
137
m_Btn2.ShowWindow (SW_SHOW);
133
m_Btn2.ShowWindow(SW_HIDE);
139
m_Btn2.ShowWindow (SW_HIDE);
143
ShowWindow (SW_SHOW);
140
void CPopUpWnd::SetWindowSize(int width, int height)
146
void CPopUpWnd::SetWindowSize (int width, int height)
142
148
enum { H1 = 16, H2 = 40, H3 = 16, S = 5, G = 10, BW=60, BH=20, BG=40};
144
CRect rootRect(0, 0, 320, 240);
150
CRect rootRect (0, 0, 320, 240);
147
MoveWindow((rootRect.Width() - width)/2, (rootRect.Height() - height)/2,
150
m_Title1.MoveWindow(10, Y=S, width-20, H1);
151
m_Title2.MoveWindow(10, Y+=H1+G, width-20, H2);
152
m_Title3.MoveWindow(10, Y+=H2+G, width-20, H3);
154
m_Btn1.MoveWindow((width-2*BW-BG)/2, Y+=H3+G, BW, BH);
155
m_Btn2.MoveWindow((width-2*BW-BG)/2+BW+BG, Y, BW, BH);
153
MoveWindow ( (rootRect.Width() - width) /2, (rootRect.Height() - height) /2,
156
m_Title1.MoveWindow (10, Y=S, width-20, H1);
157
m_Title2.MoveWindow (10, Y+=H1+G, width-20, H2);
158
m_Title3.MoveWindow (10, Y+=H2+G, width-20, H3);
160
m_Btn1.MoveWindow ( (width-2*BW-BG) /2, Y+=H3+G, BW, BH);
161
m_Btn2.MoveWindow ( (width-2*BW-BG) /2+BW+BG, Y, BW, BH);
158
void CPopUpWnd::Hide()
160
if (!::IsWindow(GetSafeHwnd()))
164
void CPopUpWnd::Hide()
166
if (!::IsWindow (GetSafeHwnd()))
163
if (IsWindowVisible())
166
ModifyStyle(WS_VISIBLE, 0);
169
if (IsWindowVisible()) {
170
ShowWindow (SW_HIDE);
171
ModifyStyle (WS_VISIBLE, 0);
170
void CPopUpWnd::Show()
172
if (!::IsWindow(GetSafeHwnd()))
175
void CPopUpWnd::Show()
177
if (!::IsWindow (GetSafeHwnd()))
175
ModifyStyle(0, WS_VISIBLE);
176
ShowWindow(SW_SHOWNA);
177
RedrawWindow(NULL,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
180
ModifyStyle (0, WS_VISIBLE);
181
ShowWindow (SW_SHOWNA);
182
RedrawWindow (NULL,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
180
BEGIN_MESSAGE_MAP(CPopUpWnd, CWnd)
185
BEGIN_MESSAGE_MAP (CPopUpWnd, CWnd)
181
186
//{{AFX_MSG_MAP(CPopUpWnd)
182
187
ON_WM_ERASEBKGND()
184
ON_BN_CLICKED(IDC_BTN1, OnCancel1)
185
ON_BN_CLICKED(IDC_BTN2, OnCancel2)
189
ON_BN_CLICKED (IDC_BTN1, OnCancel1)
190
ON_BN_CLICKED (IDC_BTN2, OnCancel2)
186
191
END_MESSAGE_MAP()
189
194
/////////////////////////////////////////////////////////////////////////////
190
195
// CPopUpWnd message handlers
192
BOOL CPopUpWnd::OnEraseBkgnd(CDC* pDC)
197
BOOL CPopUpWnd::OnEraseBkgnd (CDC* pDC)
194
199
CBrush backBrush;
195
backBrush.CreateSolidBrush(RGB(255,255,255));
196
CBrush* pOldBrush = pDC->SelectObject(&backBrush);
200
backBrush.CreateSolidBrush (RGB (255,255,255));
201
CBrush* pOldBrush = pDC->SelectObject (&backBrush);
199
pDC->GetClipBox(&rect); // Erase the area needed
200
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
201
pDC->SelectObject(pOldBrush);
204
pDC->GetClipBox (&rect); // Erase the area needed
205
pDC->PatBlt (rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
206
pDC->SelectObject (pOldBrush);
206
void CPopUpWnd::OnCancel1()
208
m_ParentWnd->OnPopUpButton(1);
212
void CPopUpWnd::OnCancel2()
214
m_ParentWnd->OnPopUpButton(2);
218
BOOL CPopUpWnd::DestroyWindow()
211
void CPopUpWnd::OnCancel1()
213
m_ParentWnd->OnPopUpButton (1);
217
void CPopUpWnd::OnCancel2()
219
m_ParentWnd->OnPopUpButton (2);
223
BOOL CPopUpWnd::DestroyWindow()
220
225
return CWnd::DestroyWindow();