| |
| 1 |
// editboxfocusDlg.cpp : implementation file |
| 2 |
// |
| 3 |
|
| 4 |
#include "stdafx.h" |
| 5 |
#include "editboxfocus.h" |
| 6 |
#include "editboxfocusDlg.h" |
| 7 |
|
| 8 |
#ifdef _DEBUG |
| 9 |
#define new DEBUG_NEW |
| 10 |
#endif |
| 11 |
|
| 12 |
|
| 13 |
// CAboutDlg dialog used for App About |
| 14 |
|
| 15 |
class CAboutDlg : public CDialog |
| 16 |
{ |
| 17 |
public: |
| 18 |
CAboutDlg(); |
| 19 |
|
| 20 |
// Dialog Data |
| 21 |
enum { IDD = IDD_ABOUTBOX }; |
| 22 |
|
| 23 |
protected: |
| 24 |
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support |
| 25 |
|
| 26 |
// Implementation |
| 27 |
protected: |
| 28 |
DECLARE_MESSAGE_MAP() |
| 29 |
}; |
| 30 |
|
| 31 |
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) |
| 32 |
{ |
| 33 |
} |
| 34 |
|
| 35 |
void CAboutDlg::DoDataExchange(CDataExchange* pDX) |
| 36 |
{ |
| 37 |
CDialog::DoDataExchange(pDX); |
| 38 |
} |
| 39 |
|
| 40 |
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) |
| 41 |
END_MESSAGE_MAP() |
| 42 |
|
| 43 |
|
| 44 |
// CeditboxfocusDlg dialog |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
CeditboxfocusDlg::CeditboxfocusDlg(CWnd* pParent /*=NULL*/) |
| 50 |
: CDialog(CeditboxfocusDlg::IDD, pParent) |
| 51 |
{ |
| 52 |
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); |
| 53 |
} |
| 54 |
|
| 55 |
void CeditboxfocusDlg::DoDataExchange(CDataExchange* pDX) |
| 56 |
{ |
| 57 |
CDialog::DoDataExchange(pDX); |
| 58 |
DDX_Control(pDX, IDC_EDIT1, m_edit); |
| 59 |
} |
| 60 |
|
| 61 |
BEGIN_MESSAGE_MAP(CeditboxfocusDlg, CDialog) |
| 62 |
ON_WM_SYSCOMMAND() |
| 63 |
ON_WM_PAINT() |
| 64 |
ON_WM_QUERYDRAGICON() |
| 65 |
//}}AFX_MSG_MAP |
| 66 |
ON_EN_CHANGE(IDC_EDIT1, &CeditboxfocusDlg::OnEnChangeEdit1) |
| 67 |
END_MESSAGE_MAP() |
| 68 |
|
| 69 |
|
| 70 |
// CeditboxfocusDlg message handlers |
| 71 |
|
| 72 |
BOOL CeditboxfocusDlg::OnInitDialog() |
| 73 |
{ |
| 74 |
|
| 75 |
CDialog::OnInitDialog(); |
| 76 |
|
| 77 |
// Add "About..." menu item to system menu. |
| 78 |
|
| 79 |
// IDM_ABOUTBOX must be in the system command range. |
| 80 |
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); |
| 81 |
ASSERT(IDM_ABOUTBOX < 0xF000); |
| 82 |
|
| 83 |
CMenu* pSysMenu = GetSystemMenu(FALSE); |
| 84 |
if (pSysMenu != NULL) |
| 85 |
{ |
| 86 |
CString strAboutMenu; |
| 87 |
strAboutMenu.LoadString(IDS_ABOUTBOX); |
| 88 |
if (!strAboutMenu.IsEmpty()) |
| 89 |
{ |
| 90 |
pSysMenu->AppendMenu(MF_SEPARATOR); |
| 91 |
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
// Set the icon for this dialog. The framework does this automatically |
| 96 |
// when the application's main window is not a dialog |
| 97 |
SetIcon(m_hIcon, TRUE); // Set big icon |
| 98 |
SetIcon(m_hIcon, FALSE); // Set small icon |
| 99 |
|
| 100 |
// TODO: Add extra initialization here |
| 101 |
|
| 102 |
//m_edit.UpdateWindow(); |
| 103 |
|
| 104 |
//m_edit.SetFocus(); |
| 105 |
// m_edit.SetSel(2,3); |
| 106 |
//DWORD dwSel = 3;// m_edit.GetSel(); |
| 107 |
//m_edit.SetSel(HIWORD(dwSel), -1); |
| 108 |
return TRUE; // return TRUE unless you set the focus to a control |
| 109 |
} |
| 110 |
|
| 111 |
void CeditboxfocusDlg::OnSysCommand(UINT nID, LPARAM lParam) |
| 112 |
{ |
| 113 |
if ((nID & 0xFFF0) == IDM_ABOUTBOX) |
| 114 |
{ |
| 115 |
CAboutDlg dlgAbout; |
| 116 |
dlgAbout.DoModal(); |
| 117 |
} |
| 118 |
else |
| 119 |
{ |
| 120 |
CDialog::OnSysCommand(nID, lParam); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
// If you add a minimize button to your dialog, you will need the code below |
| 125 |
// to draw the icon. For MFC applications using the document/view model, |
| 126 |
// this is automatically done for you by the framework. |
| 127 |
|
| 128 |
void CeditboxfocusDlg::OnPaint() |
| 129 |
{ |
| 130 |
if (IsIconic()) |
| 131 |
{ |
| 132 |
CPaintDC dc(this); // device context for painting |
| 133 |
|
| 134 |
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); |
| 135 |
|
| 136 |
// Center icon in client rectangle |
| 137 |
int cxIcon = GetSystemMetrics(SM_CXICON); |
| 138 |
int cyIcon = GetSystemMetrics(SM_CYICON); |
| 139 |
CRect rect; |
| 140 |
GetClientRect(&rect); |
| 141 |
int x = (rect.Width() - cxIcon + 1) / 2; |
| 142 |
int y = (rect.Height() - cyIcon + 1) / 2; |
| 143 |
|
| 144 |
// Draw the icon |
| 145 |
dc.DrawIcon(x, y, m_hIcon); |
| 146 |
} |
| 147 |
else |
| 148 |
{ |
| 149 |
CDialog::OnPaint(); |
| 150 |
} |
| 151 |
m_edit.SetWindowTextW(_T("C:\\ABC\\")); |
| 152 |
m_edit.SetFocus(); |
| 153 |
m_edit.SetSel(7,7); |
| 154 |
|
| 155 |
} |
| 156 |
|
| 157 |
// The system calls this function to obtain the cursor to display while the user drags |
| 158 |
// the minimized window. |
| 159 |
HCURSOR CeditboxfocusDlg::OnQueryDragIcon() |
| 160 |
{ |
| 161 |
return static_cast<HCURSOR>(m_hIcon); |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
void CeditboxfocusDlg::OnEnChangeEdit1() |
| 166 |
{ |
| 167 |
// TODO: If this is a RICHEDIT control, the control will not |
| 168 |
// send this notification unless you override the CDialog::OnInitDialog() |
| 169 |
// function and call CRichEditCtrl().SetEventMask() |
| 170 |
// with the ENM_CHANGE flag ORed into the mask. |
| 171 |
|
| 172 |
// TODO: Add your control notification handler code here |
| 173 |
} |
| |