-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDlgEditText.cpp
More file actions
129 lines (110 loc) · 2.77 KB
/
DlgEditText.cpp
File metadata and controls
129 lines (110 loc) · 2.77 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
// DlgEditText.cpp : implementation file
//
#include "stdafx.h"
#include "krs.h"
#include "DlgEditText.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DlgEditText dialog
DlgEditText::DlgEditText(CString text, CRect rect, bool bold, int alignment, CWnd* pParent /*=NULL*/)
: CDialog(DlgEditText::IDD, pParent), m_bold(bold), m_alignment(alignment), m_bold_font(NULL), m_main_font(NULL)
{
m_rect = rect;
//{{AFX_DATA_INIT(DlgEditText)
m_text_centered = _T(text);
m_text_left = _T(text);
m_text_right = _T(text);
//}}AFX_DATA_INIT
}
void DlgEditText::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgEditText)
DDX_Text(pDX, IDC_EDIT_TEXT_CENTERED, m_text_centered);
DDX_Text(pDX, IDC_EDIT_TEXT_LEFT, m_text_left);
DDX_Text(pDX, IDC_EDIT_TEXT_RIGHT, m_text_right);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DlgEditText, CDialog)
//{{AFX_MSG_MAP(DlgEditText)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_USER+1, OnEnforceFlose)
ON_WM_WINDOWPOSCHANGING()
ON_WM_CANCELMODE()
END_MESSAGE_MAP()
void DlgEditText::OnCloseDialog()
{
if (m_bold_font)
{
m_bold_font->DeleteObject();
delete m_bold_font;
}
}
void DlgEditText::OnCancel()
{
m_res = IDCANCEL;
OnCloseDialog();
CDialog::OnCancel();
}
void DlgEditText::OnOK()
{
m_res = IDOK;
OnCloseDialog();
CDialog::OnOK();
}
BOOL DlgEditText::OnInitDialog()
{
CDialog::OnInitDialog();
m_res = -1;
CEdit* edit = (CEdit*)GetDlgItem((m_alignment == 0) ? IDC_EDIT_TEXT_CENTERED : ((m_alignment == -1)?IDC_EDIT_TEXT_LEFT:IDC_EDIT_TEXT_RIGHT));
int w = m_rect.right - m_rect.left;
int h = m_rect.bottom - m_rect.top;
int y = m_rect.top;
int x = m_rect.left;
SetWindowPos(NULL, x, y, w, h, SWP_NOZORDER);
x = 1;
y = 1;
w -= 4;
h -= 4;
edit->SetWindowPos(NULL, x, y, w, h, SWP_NOZORDER);
edit->ShowWindow(SW_NORMAL);
if (m_main_font)
edit->SetFont(m_main_font, FALSE);
if (m_bold)
{
CFont *fnt = edit->GetFont();
LOGFONT lf;
fnt->GetLogFont(&lf);
lf.lfWeight = FW_BOLD;
m_bold_font = new CFont();
m_bold_font->CreateFontIndirect(&lf);
edit->SetFont(m_bold_font);
}
return TRUE;
}
void DlgEditText::OnWindowPosChanging(WINDOWPOS* lpwndpos)
{
CDialog::OnWindowPosChanging(lpwndpos);
// TRACE1("%08X\n", lpwndpos->flags);
if (lpwndpos != NULL && lpwndpos->flags == (SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE))
{
if (m_res == -1)
{
m_res = IDCANCEL;
PostMessage(WM_USER+1, 0, NULL);
}
}
}
LRESULT DlgEditText::OnEnforceFlose(WPARAM, LPARAM)
{
EndDialog(IDCANCEL);
return 0;
}
CString DlgEditText::GetText()
{
return (m_alignment == 0)?m_text_centered:((m_alignment == -1)?m_text_left:m_text_right);
}