#pragma once
|
#include "afxwin.h"
|
|
class CInputDialog :public CDialogEx
|
{
|
DECLARE_DYNAMIC(CInputDialog)
|
public:
|
LPDLGTEMPLATE dltt; //ÉùÃ÷½á¹¹±äÁ¿Ö¸Õë
|
LPDLGITEMTEMPLATE dlit; //¿Ø¼þ½á¹¹±äÁ¿Ö¸Õë
|
BYTE *hbl;
|
CStatic m_static_prompt;
|
CEdit m_edit_input;
|
CString TitleStr;
|
CString PromptStr;
|
CString InputStr;
|
int IsPassword;
|
int bInited;
|
int LeftMargin, RightMargin, TopMargin, BottomMargin;
|
|
CInputDialog(CWnd* pParent = NULL)
|
{
|
IsPassword=0;
|
bInited = 0;
|
LeftMargin = 0;
|
TopMargin = 0;
|
RightMargin = 0;
|
BottomMargin = 0;
|
|
|
hbl=new BYTE[1024];
|
|
int n,m;
|
dltt=(LPDLGTEMPLATE)hbl;
|
dltt->style=WS_CHILD|WS_BORDER|WS_SYSMENU|DS_MODALFRAME|
|
WS_CAPTION|DS_SETFONT|WS_SIZEBOX;
|
dltt->dwExtendedStyle=0;
|
dltt->cdit=1;
|
dltt->x=10;
|
dltt->y=10;
|
dltt->cx=160;
|
dltt->cy=80;
|
/* ¶Ô»°¿ò±ß³¤Êý×é */;
|
LPWORD lpw=(LPWORD)(dltt+1);
|
*lpw++=0x0000; //ûÓв˵¥
|
*lpw++=0x0000; //ʹÓÃϵͳĬÈÏÀà
|
n = MultiByteToWideChar(CP_ACP,0,"¶Ô»°¿ò±êÌâÃû³Æ",-1,(LPWSTR)lpw,50);
|
lpw+=n;
|
*lpw++=8; //×ÖÌå´óС
|
m = MultiByteToWideChar(CP_ACP,0,"ËÎÌå",-1,(LPWSTR)lpw,50);
|
lpw++;
|
lpw+=m;
|
|
/* °´Å¥¿Ø¼þ */
|
lpw=(LPWORD)((((ULONG)lpw+3)>>2)<<2);
|
dlit=(LPDLGITEMTEMPLATE)lpw;
|
dlit->dwExtendedStyle=0;
|
dlit->x=10;
|
dlit->y=50;
|
dlit->cx=80;
|
dlit->cy=20;
|
dlit->id=IDOK; //OK°´Å¥±êʶ
|
dlit->style=WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON;//°´Å¥¿Ø¼þ´°¿Ú·ç¸ñ
|
lpw=(LPWORD)(dlit+1); //Òƶ¯Ö¸Õ룬ʹÆäÖ¸ÏòDLGITEMTEMPPLATE½á¹¹µÄÏÂÒ»¸öÄÚ´æµ¥Ôª
|
/* ¿Ø¼þ±ä³¤Êý×é */
|
*lpw++ = 0xffff;
|
*lpw++ = 0x0080;
|
n=MultiByteToWideChar(CP_ACP,0,"È·¶¨",-1,(LPWSTR)lpw,10);
|
// HINSTANCE hinst = theApp.m_hInstance;
|
/* ´´½¨¶Ô»°¿ò´°¿Ú */
|
// CDialog dialog1;
|
|
// LRESULT ret = DialogBoxIndirect(hinst,(LPDLGTEMPLATE)hbl,NULL,(DLGPROC)DlgProc);
|
// dialog1.DoModal();
|
/* ÊÍ·Å×ÊÔ´ */
|
dltt=(LPDLGTEMPLATE)hbl;
|
|
// return ret;
|
}
|
|
|
CInputDialog::~CInputDialog(void)
|
{
|
delete [] hbl;
|
hbl = NULL;
|
}
|
|
virtual INT_PTR DoModal()
|
{
|
dltt->style=WS_POPUP|WS_BORDER|WS_SYSMENU|DS_MODALFRAME|
|
WS_CAPTION|DS_SETFONT|WS_SIZEBOX;
|
InitModalIndirect((LPDLGTEMPLATE)hbl);
|
return CDialogEx::DoModal();
|
}
|
|
DECLARE_MESSAGE_MAP()
|
BOOL OnInitDialog()
|
{
|
|
CDialog::OnInitDialog();
|
|
// TODO: ÔÚ´ËÌí¼Ó¶îÍâµÄ³õʼ»¯
|
RECT rect1;
|
rect1.left=10;
|
rect1.top=10;
|
rect1.right=180;
|
rect1.bottom=26;
|
//STATIC style 0x50020000 ExStyle 0x4
|
//EDIT style 0x50010080 ExStyle 0x204
|
//Button style 0x50010000 ExStyle 0x4
|
|
DWORD staticstyle,staticexstyle;
|
DWORD editstyle,editexstyle;
|
staticstyle=0x50020000; staticexstyle=0x4;
|
editstyle=0x50010080; editexstyle=0x204;
|
// m_static_hint.Create(HintStr,staticstyle,rect1,this);
|
m_static_prompt.CreateEx(staticexstyle,_T("STATIC"),PromptStr,staticstyle,rect1,this,998);
|
|
|
rect1.left=10;
|
rect1.top=40;
|
rect1.right=180;
|
rect1.bottom=64;
|
|
if (IsPassword) {editstyle|=ES_PASSWORD;}
|
// m_edit_input.Create(editstyle,rect1,this,999);
|
m_edit_input.CreateEx(editexstyle,_T("EDIT"),InputStr,editstyle,rect1,this,999);
|
m_edit_input.SetFocus();
|
bInited = 1;
|
return false;
|
return TRUE; // return TRUE unless you set the focus to a control
|
// Òì³£: OCX ÊôÐÔÒ³Ó¦·µ»Ø FALSE
|
}
|
void OnOK()
|
{
|
// TODO: ÔÚ´ËÌí¼ÓרÓôúÂëºÍ/»òµ÷ÓûùÀà
|
m_edit_input.GetWindowText(InputStr);
|
|
CDialog::OnOK();
|
}
|
void OnSize(UINT nType, int cx, int cy)
|
{
|
CString s1;
|
//s1.Format(_T("ItemShow OnSize Type %d cx %d cy %d \r\n"),nType, cx, cy);
|
//SysLog(s1);
|
|
CDialogEx::OnSize(nType, cx, cy);
|
if (!this->IsWindowVisible() && !bInited) { return; }
|
switch (nType)
|
{
|
case SIZE_MAXHIDE:
|
case SIZE_MAXSHOW:
|
case SIZE_MINIMIZED:
|
return;
|
}
|
if (nType == SIZE_MAXIMIZED || nType == SIZE_RESTORED)
|
{
|
CRect rect0;
|
GetClientRect(&rect0);
|
int w = rect0.Width();
|
int h = rect0.Height();
|
|
int effw = (w - LeftMargin - RightMargin);
|
int effh = (h - TopMargin - BottomMargin);
|
// int x, y;
|
CString s1;
|
m_edit_input.GetWindowText(s1);
|
s1.Append(_T("S"));
|
m_edit_input.SetWindowText(s1);
|
}
|
}
|
void OnLButtonDown(UINT nFlags, CPoint point)
|
{
|
// TODO: ÔÚ´ËÌí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂëºÍ/»òµ÷ÓÃĬÈÏÖµ
|
CString s1;
|
m_edit_input.GetWindowText(s1);
|
s1.Append(_T("LD"));
|
m_edit_input.SetWindowText(s1);
|
CDialogEx::OnLButtonDown(nFlags, point);
|
}
|
|
void OnLButtonUp(UINT nFlags, CPoint point)
|
{
|
// TODO: ÔÚ´ËÌí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂëºÍ/»òµ÷ÓÃĬÈÏÖµ
|
CString s1;
|
m_edit_input.GetWindowText(s1);
|
s1.Append(_T("LU"));
|
m_edit_input.SetWindowText(s1);
|
CDialogEx::OnLButtonDown(nFlags, point);
|
}
|
void OnPaint()
|
{
|
if (IsIconic())
|
{
|
CPaintDC dc(this); // ÓÃÓÚ»æÖƵÄÉ豸ÉÏÏÂÎÄ
|
|
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
|
|
// ʹͼ±êÔÚ¹¤×÷Çø¾ØÐÎÖоÓÖÐ
|
int cxIcon = GetSystemMetrics(SM_CXICON);
|
int cyIcon = GetSystemMetrics(SM_CYICON);
|
CRect rect;
|
GetClientRect(&rect);
|
int x = (rect.Width() - cxIcon + 1) / 2;
|
int y = (rect.Height() - cyIcon + 1) / 2;
|
|
// »æÖÆͼ±ê
|
// dc.DrawIcon(x, y, m_hIcon);
|
}
|
else
|
{
|
CDialogEx::OnPaint();
|
CString s1;
|
m_edit_input.GetWindowText(s1);
|
s1.Append(_T("P"));
|
m_edit_input.SetWindowText(s1);
|
}
|
}
|
|
};
|
IMPLEMENT_DYNAMIC(CInputDialog, CDialogEx)
|
|
|
BEGIN_MESSAGE_MAP(CInputDialog, CDialogEx)
|
ON_WM_SIZE()
|
ON_WM_LBUTTONDOWN()
|
ON_WM_LBUTTONUP()
|
ON_WM_PAINT()
|
END_MESSAGE_MAP()
|
|