4
#include "PocketPJDlg.h"
9
static char THIS_FILE[] = __FILE__;
16
/////////////////////////////////////////////////////////////////////////////
19
CPopUpWnd::CPopUpWnd(CPocketPJDlg* pParent)
24
CPopUpWnd::~CPopUpWnd()
29
BOOL CPopUpWnd::Create(CPocketPJDlg* pParent)
33
m_ParentWnd = pParent;
35
// Register window class
36
CString csClassName = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,
38
CBrush(::GetSysColor(COLOR_BTNFACE)));
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
55
// Now create the controls
56
CRect TempRect(0,0,10,10);
58
/* |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,
92
memset(&lf, 0, sizeof(LOGFONT));
94
lstrcpy(lf.lfFaceName, _T("Arial"));
95
VERIFY(ft1->CreateFontIndirect(&lf));
96
VERIFY(ft3->CreateFontIndirect(&lf));
99
VERIFY(ft2->CreateFontIndirect(&lf));
101
m_Title1.SetFont(ft1, TRUE);
102
m_Title2.SetFont(ft2, TRUE);
103
m_Title3.SetFont(ft3, TRUE);
108
// Center and show window
116
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);
122
if (content.m_Btn1 != "") {
123
m_Btn1.SetWindowText(content.m_Btn1);
124
m_Btn1.ShowWindow(SW_SHOW);
126
m_Btn1.ShowWindow(SW_HIDE);
129
if (content.m_Btn2 != "") {
130
m_Btn2.SetWindowText(content.m_Btn2);
131
m_Btn2.ShowWindow(SW_SHOW);
133
m_Btn2.ShowWindow(SW_HIDE);
140
void CPopUpWnd::SetWindowSize(int width, int height)
142
enum { H1 = 16, H2 = 40, H3 = 16, S = 5, G = 10, BW=60, BH=20, BG=40};
144
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);
158
void CPopUpWnd::Hide()
160
if (!::IsWindow(GetSafeHwnd()))
163
if (IsWindowVisible())
166
ModifyStyle(WS_VISIBLE, 0);
170
void CPopUpWnd::Show()
172
if (!::IsWindow(GetSafeHwnd()))
175
ModifyStyle(0, WS_VISIBLE);
176
ShowWindow(SW_SHOWNA);
177
RedrawWindow(NULL,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
180
BEGIN_MESSAGE_MAP(CPopUpWnd, CWnd)
181
//{{AFX_MSG_MAP(CPopUpWnd)
184
ON_BN_CLICKED(IDC_BTN1, OnCancel1)
185
ON_BN_CLICKED(IDC_BTN2, OnCancel2)
189
/////////////////////////////////////////////////////////////////////////////
190
// CPopUpWnd message handlers
192
BOOL CPopUpWnd::OnEraseBkgnd(CDC* pDC)
195
backBrush.CreateSolidBrush(RGB(255,255,255));
196
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);
206
void CPopUpWnd::OnCancel1()
208
m_ParentWnd->OnPopUpButton(1);
212
void CPopUpWnd::OnCancel2()
214
m_ParentWnd->OnPopUpButton(2);
218
BOOL CPopUpWnd::DestroyWindow()
220
return CWnd::DestroyWindow();
223
void CPopUpWnd::PeekAndPump()
226
while (::PeekMessage(&msg, NULL,0,0,PM_NOREMOVE))
228
if (!AfxGetApp()->PumpMessage())
230
::PostQuitMessage(0);