QuakeGod
2024-12-24 61deef5cdf96cbfdd6ad45be49e80d597c00ca65
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#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()