提交 | 用户 | age
|
4b03ae
|
1 |
#pragma once
|
Q |
2 |
#include "afxwin.h"
|
|
3 |
|
|
4 |
class CInputDialog :public CDialogEx
|
|
5 |
{
|
|
6 |
DECLARE_DYNAMIC(CInputDialog)
|
|
7 |
public:
|
|
8 |
LPDLGTEMPLATE dltt; //声明结构变量指针
|
|
9 |
LPDLGITEMTEMPLATE dlit; //控件结构变量指针
|
|
10 |
BYTE *hbl;
|
|
11 |
CStatic m_static_prompt;
|
|
12 |
CEdit m_edit_input;
|
|
13 |
CString TitleStr;
|
|
14 |
CString PromptStr;
|
|
15 |
CString InputStr;
|
|
16 |
int IsPassword;
|
|
17 |
int bInited;
|
|
18 |
int LeftMargin, RightMargin, TopMargin, BottomMargin;
|
|
19 |
|
|
20 |
CInputDialog(CWnd* pParent = NULL)
|
|
21 |
{
|
|
22 |
IsPassword=0;
|
|
23 |
bInited = 0;
|
|
24 |
LeftMargin = 0;
|
|
25 |
TopMargin = 0;
|
|
26 |
RightMargin = 0;
|
|
27 |
BottomMargin = 0;
|
|
28 |
|
|
29 |
|
|
30 |
hbl=new BYTE[1024];
|
|
31 |
|
|
32 |
int n,m;
|
|
33 |
dltt=(LPDLGTEMPLATE)hbl;
|
|
34 |
dltt->style=WS_CHILD|WS_BORDER|WS_SYSMENU|DS_MODALFRAME|
|
|
35 |
WS_CAPTION|DS_SETFONT|WS_SIZEBOX;
|
|
36 |
dltt->dwExtendedStyle=0;
|
|
37 |
dltt->cdit=1;
|
|
38 |
dltt->x=10;
|
|
39 |
dltt->y=10;
|
|
40 |
dltt->cx=160;
|
|
41 |
dltt->cy=80;
|
|
42 |
/* 对话框边长数组 */;
|
|
43 |
LPWORD lpw=(LPWORD)(dltt+1);
|
|
44 |
*lpw++=0x0000; //没有菜单
|
|
45 |
*lpw++=0x0000; //使用系统默认类
|
|
46 |
n = MultiByteToWideChar(CP_ACP,0,"对话框标题名称",-1,(LPWSTR)lpw,50);
|
|
47 |
lpw+=n;
|
|
48 |
*lpw++=8; //字体大小
|
|
49 |
m = MultiByteToWideChar(CP_ACP,0,"宋体",-1,(LPWSTR)lpw,50);
|
|
50 |
lpw++;
|
|
51 |
lpw+=m;
|
|
52 |
|
|
53 |
/* 按钮控件 */
|
|
54 |
lpw=(LPWORD)((((ULONG)lpw+3)>>2)<<2);
|
|
55 |
dlit=(LPDLGITEMTEMPLATE)lpw;
|
|
56 |
dlit->dwExtendedStyle=0;
|
|
57 |
dlit->x=10;
|
|
58 |
dlit->y=50;
|
|
59 |
dlit->cx=80;
|
|
60 |
dlit->cy=20;
|
|
61 |
dlit->id=IDOK; //OK按钮标识
|
|
62 |
dlit->style=WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON;//按钮控件窗口风格
|
|
63 |
lpw=(LPWORD)(dlit+1); //移动指针,使其指向DLGITEMTEMPPLATE结构的下一个内存单元
|
|
64 |
/* 控件变长数组 */
|
|
65 |
*lpw++ = 0xffff;
|
|
66 |
*lpw++ = 0x0080;
|
|
67 |
n=MultiByteToWideChar(CP_ACP,0,"确定",-1,(LPWSTR)lpw,10);
|
|
68 |
// HINSTANCE hinst = theApp.m_hInstance;
|
|
69 |
/* 创建对话框窗口 */
|
|
70 |
// CDialog dialog1;
|
|
71 |
|
|
72 |
// LRESULT ret = DialogBoxIndirect(hinst,(LPDLGTEMPLATE)hbl,NULL,(DLGPROC)DlgProc);
|
|
73 |
// dialog1.DoModal();
|
|
74 |
/* 释放资源 */
|
|
75 |
dltt=(LPDLGTEMPLATE)hbl;
|
|
76 |
|
|
77 |
// return ret;
|
|
78 |
}
|
|
79 |
|
|
80 |
|
|
81 |
CInputDialog::~CInputDialog(void)
|
|
82 |
{
|
|
83 |
delete [] hbl;
|
|
84 |
hbl = NULL;
|
|
85 |
}
|
|
86 |
|
|
87 |
virtual INT_PTR DoModal()
|
|
88 |
{
|
|
89 |
dltt->style=WS_POPUP|WS_BORDER|WS_SYSMENU|DS_MODALFRAME|
|
|
90 |
WS_CAPTION|DS_SETFONT|WS_SIZEBOX;
|
|
91 |
InitModalIndirect((LPDLGTEMPLATE)hbl);
|
|
92 |
return CDialogEx::DoModal();
|
|
93 |
}
|
|
94 |
|
|
95 |
DECLARE_MESSAGE_MAP()
|
|
96 |
BOOL OnInitDialog()
|
|
97 |
{
|
|
98 |
|
|
99 |
CDialog::OnInitDialog();
|
|
100 |
|
|
101 |
// TODO: 在此添加额外的初始化
|
|
102 |
RECT rect1;
|
|
103 |
rect1.left=10;
|
|
104 |
rect1.top=10;
|
|
105 |
rect1.right=180;
|
|
106 |
rect1.bottom=26;
|
|
107 |
//STATIC style 0x50020000 ExStyle 0x4
|
|
108 |
//EDIT style 0x50010080 ExStyle 0x204
|
|
109 |
//Button style 0x50010000 ExStyle 0x4
|
|
110 |
|
|
111 |
DWORD staticstyle,staticexstyle;
|
|
112 |
DWORD editstyle,editexstyle;
|
|
113 |
staticstyle=0x50020000; staticexstyle=0x4;
|
|
114 |
editstyle=0x50010080; editexstyle=0x204;
|
|
115 |
// m_static_hint.Create(HintStr,staticstyle,rect1,this);
|
|
116 |
m_static_prompt.CreateEx(staticexstyle,_T("STATIC"),PromptStr,staticstyle,rect1,this,998);
|
|
117 |
|
|
118 |
|
|
119 |
rect1.left=10;
|
|
120 |
rect1.top=40;
|
|
121 |
rect1.right=180;
|
|
122 |
rect1.bottom=64;
|
|
123 |
|
|
124 |
if (IsPassword) {editstyle|=ES_PASSWORD;}
|
|
125 |
// m_edit_input.Create(editstyle,rect1,this,999);
|
|
126 |
m_edit_input.CreateEx(editexstyle,_T("EDIT"),InputStr,editstyle,rect1,this,999);
|
|
127 |
m_edit_input.SetFocus();
|
|
128 |
bInited = 1;
|
|
129 |
return false;
|
|
130 |
return TRUE; // return TRUE unless you set the focus to a control
|
|
131 |
// 异常: OCX 属性页应返回 FALSE
|
|
132 |
}
|
|
133 |
void OnOK()
|
|
134 |
{
|
|
135 |
// TODO: 在此添加专用代码和/或调用基类
|
|
136 |
m_edit_input.GetWindowText(InputStr);
|
|
137 |
|
|
138 |
CDialog::OnOK();
|
|
139 |
}
|
|
140 |
void OnSize(UINT nType, int cx, int cy)
|
|
141 |
{
|
|
142 |
CString s1;
|
|
143 |
//s1.Format(_T("ItemShow OnSize Type %d cx %d cy %d \r\n"),nType, cx, cy);
|
|
144 |
//SysLog(s1);
|
|
145 |
|
|
146 |
CDialogEx::OnSize(nType, cx, cy);
|
|
147 |
if (!this->IsWindowVisible() && !bInited) { return; }
|
|
148 |
switch (nType)
|
|
149 |
{
|
|
150 |
case SIZE_MAXHIDE:
|
|
151 |
case SIZE_MAXSHOW:
|
|
152 |
case SIZE_MINIMIZED:
|
|
153 |
return;
|
|
154 |
}
|
|
155 |
if (nType == SIZE_MAXIMIZED || nType == SIZE_RESTORED)
|
|
156 |
{
|
|
157 |
CRect rect0;
|
|
158 |
GetClientRect(&rect0);
|
|
159 |
int w = rect0.Width();
|
|
160 |
int h = rect0.Height();
|
|
161 |
|
|
162 |
int effw = (w - LeftMargin - RightMargin);
|
|
163 |
int effh = (h - TopMargin - BottomMargin);
|
|
164 |
// int x, y;
|
|
165 |
CString s1;
|
|
166 |
m_edit_input.GetWindowText(s1);
|
|
167 |
s1.Append(_T("S"));
|
|
168 |
m_edit_input.SetWindowText(s1);
|
|
169 |
}
|
|
170 |
}
|
|
171 |
void OnLButtonDown(UINT nFlags, CPoint point)
|
|
172 |
{
|
|
173 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
174 |
CString s1;
|
|
175 |
m_edit_input.GetWindowText(s1);
|
|
176 |
s1.Append(_T("LD"));
|
|
177 |
m_edit_input.SetWindowText(s1);
|
|
178 |
CDialogEx::OnLButtonDown(nFlags, point);
|
|
179 |
}
|
|
180 |
|
|
181 |
void OnLButtonUp(UINT nFlags, CPoint point)
|
|
182 |
{
|
|
183 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
184 |
CString s1;
|
|
185 |
m_edit_input.GetWindowText(s1);
|
|
186 |
s1.Append(_T("LU"));
|
|
187 |
m_edit_input.SetWindowText(s1);
|
|
188 |
CDialogEx::OnLButtonDown(nFlags, point);
|
|
189 |
}
|
|
190 |
void OnPaint()
|
|
191 |
{
|
|
192 |
if (IsIconic())
|
|
193 |
{
|
|
194 |
CPaintDC dc(this); // 用于绘制的设备上下文
|
|
195 |
|
|
196 |
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
|
|
197 |
|
|
198 |
// 使图标在工作区矩形中居中
|
|
199 |
int cxIcon = GetSystemMetrics(SM_CXICON);
|
|
200 |
int cyIcon = GetSystemMetrics(SM_CYICON);
|
|
201 |
CRect rect;
|
|
202 |
GetClientRect(&rect);
|
|
203 |
int x = (rect.Width() - cxIcon + 1) / 2;
|
|
204 |
int y = (rect.Height() - cyIcon + 1) / 2;
|
|
205 |
|
|
206 |
// 绘制图标
|
|
207 |
// dc.DrawIcon(x, y, m_hIcon);
|
|
208 |
}
|
|
209 |
else
|
|
210 |
{
|
|
211 |
CDialogEx::OnPaint();
|
|
212 |
CString s1;
|
|
213 |
m_edit_input.GetWindowText(s1);
|
|
214 |
s1.Append(_T("P"));
|
|
215 |
m_edit_input.SetWindowText(s1);
|
|
216 |
}
|
|
217 |
}
|
|
218 |
|
|
219 |
};
|
|
220 |
IMPLEMENT_DYNAMIC(CInputDialog, CDialogEx)
|
|
221 |
|
|
222 |
|
|
223 |
BEGIN_MESSAGE_MAP(CInputDialog, CDialogEx)
|
|
224 |
ON_WM_SIZE()
|
|
225 |
ON_WM_LBUTTONDOWN()
|
|
226 |
ON_WM_LBUTTONUP()
|
|
227 |
ON_WM_PAINT()
|
|
228 |
END_MESSAGE_MAP()
|
|
229 |
|