|
|
1.1 root 1: // deredit.cpp : C++ derived Edit control example
2: //
3: // This is a part of the Microsoft Foundation Classes C++ library.
4: // Copyright (C) 1992 Microsoft Corporation
5: // All rights reserved.
6: //
7: // This source code is only intended as a supplement to the
8: // Microsoft Foundation Classes Reference and Microsoft
9: // QuickHelp documentation provided with the library.
10: // See these sources for detailed information regarding the
11: // Microsoft Foundation Classes product.
12:
13: #include "ctrltest.h"
14:
15: #include "paredit.h"
16:
17: /////////////////////////////////////////////////////////////////////////////
18:
19: class CDerEditDlg : public CModalDialog
20: {
21: protected:
22: CFont* m_pFont;
23: // construct
24: CParsedEdit edit1, edit2, edit3, edit4;
25: CStatic static1, static2, static3, static4;
26: public:
27: CDerEditDlg()
28: : CModalDialog(IDD_DERIVED_EDIT)
29: { }
30:
31: BOOL OnInitDialog();
32: void OnSetFont(CFont* pFont)
33: { m_pFont = pFont; }
34: void OnOK();
35: };
36:
37: BOOL CDerEditDlg::OnInitDialog()
38: // create children on InitDialog
39: // (not in CDerEditDlg constructor since the dialog has
40: // no attached HWND in the constructor)
41: {
42: // This is an example of the _incorrect_ way to create a dialog
43: // The following code show you what you should _not_ do:
44: // 1) do not use hard coded numbers for coordinates and sizes
45: // (these will break when the font sizes changes and are
46: // hard to edit and maintain).
47: // 2) do not put strings in code, they should be in resources.
48: // 3) as you can see below the programming steps required
49: // to create controls, pass the correct creation parameters,
50: // and set the appropriate font, is complicated and error prone.
51:
52: const int yStart = 8;
53: const int height = 30;
54:
55: CPoint whereLabel(10, yStart);
56: CSize sizeLabel(80, 24);
57:
58: CPoint whereEdit(90, yStart);
59: CSize sizeEdit(140, 24);
60:
61: static1.Create("Letters:", WS_VISIBLE | WS_CHILD | SS_LEFT,
62: CRect(whereLabel, sizeLabel), this, -1);
63: static1.SetFont(m_pFont);
64: whereLabel.y += height;
65: edit1.Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_BORDER |
66: PES_LETTERS,
67: CRect(whereEdit, sizeEdit), this, IDC_EDIT1);
68: edit1.SetFont(m_pFont);
69: whereEdit.y += height;
70:
71: static2.Create("Numbers:", WS_VISIBLE | WS_CHILD | SS_LEFT,
72: CRect(whereLabel, sizeLabel), this, -1);
73: static2.SetFont(m_pFont);
74: whereLabel.y += height;
75: edit2.Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_BORDER |
76: PES_NUMBERS,
77: CRect(whereEdit, sizeEdit), this, IDC_EDIT2);
78: edit2.SetFont(m_pFont);
79: whereEdit.y += height;
80:
81: static3.Create("Either:", WS_VISIBLE | WS_CHILD | SS_LEFT,
82: CRect(whereLabel, sizeLabel), this, -1);
83: static3.SetFont(m_pFont);
84: whereLabel.y += height;
85: edit3.Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_BORDER |
86: PES_LETTERS | PES_NUMBERS,
87: CRect(whereEdit, sizeEdit), this, IDC_EDIT3);
88: edit3.SetFont(m_pFont);
89: whereEdit.y += height;
90:
91: static4.Create("Anything:", WS_VISIBLE | WS_CHILD | SS_LEFT,
92: CRect(whereLabel, sizeLabel), this, -1);
93: static4.SetFont(m_pFont);
94: whereLabel.y += height;
95: edit4.Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_BORDER |
96: PES_ALL,
97: CRect(whereEdit, sizeEdit), this, IDC_EDIT4);
98: edit4.SetFont(m_pFont);
99: whereEdit.y += height;
100:
101: // change the dialog height so everything fits
102: int yBottom = whereEdit.y + height * 2; // extra space
103: CRect rect;
104: GetWindowRect(rect);
105: VERIFY(SetWindowPos(NULL, -1, -1, rect.Width(), yBottom,
106: SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOACTIVATE));
107:
108: // set focus to first one
109: edit1.SetFocus();
110: return FALSE; // focus set
111: }
112:
113: void CDerEditDlg::OnOK()
114: {
115: #ifdef _DEBUG
116: // dump results, normally you would do something with these
117: CString s;
118: edit1.GetWindowText(s);
119: TRACE("edit1 = '%s'\n", (const char*) s);
120: edit2.GetWindowText(s);
121: TRACE("edit2 = '%s'\n", (const char*) s);
122: edit3.GetWindowText(s);
123: TRACE("edit3 = '%s'\n", (const char*) s);
124: edit4.GetWindowText(s);
125: TRACE("edit4 = '%s'\n", (const char*) s);
126: #endif
127:
128: EndDialog(IDOK);
129: }
130:
131: /////////////////////////////////////////////////////////////////////////////
132: // Run the test
133:
134: void CTestWindow::OnTestDerivedEdit()
135: {
136: TRACE("running dialog with special derived CParsedEdit controls in it\n");
137: CDerEditDlg dlg;
138: dlg.DoModal();
139: }
140:
141:
142: /////////////////////////////////////////////////////////////////////////////
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.