?? controls.html
字號:
<html>
<head>
<title>Controls</title>
<meta name="description" content="Reliable Software Win32 Tutorial: Window Controls">
<meta name="keywords" content="reliable, software, windows, cplusplus, source code, example, tutorial, controls, dialog box, edit control, object oriented">
</head>
<body background="../images/grid.gif" bgcolor="white" text="black">
<script language="JAVASCRIPT">
<!--
if (navigator.onLine){
document.write("<!-- Spidersoft WebZIP Ad Banner Insert -->");
document.write("<TABLE width=100% border=0 cellpadding=0 cellspacing=0>");
document.write("<TR>");
document.write("<TD>");
document.write("<ILAYER id=ad1 visibility=hidden height=60></ILAYER>");
document.write("<NOLAYER>");
document.write("<IFRAME SRC='http://www.spidersoft.com/ads/bwz468_60.htm' width=100% height=60 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no></IFRAME>");
document.write("</NOLAYER>");
document.write("</TD>");
document.write("</TR>");
document.write("</TABLE>");
document.write("<!-- End of Spidersoft WebZIP Ad Banner Insert-->");
}
//-->
</script>
<table cellpadding=10 width="100%">
<tr>
<td width=100 align=center valign=middle>
<a href="../index.htm">
<img src="../images/rsbullet.gif" alt="RS" border=0 width=39 height=39>
<br>Home</a>
<td><font face="arial" color="#009966">
<h1 align=center>Window Controls</h1>
</font>
</table>
<p>
<table width="100%">
<tr>
<td width=80> <!-- Left margin -->
<td> <!-- Middle column, there is also the right margin at the end -->
<table cellpadding=10 cellspacing=0 width="100%">
<tr>
<td bgcolor="#ffffff">
<hr>
<font size="+1"><b>Controls can be added</b></font> to the main Window or to any dialog box in your program. Controls are best picked and positioned using a graphical resource editor. Such an editor will also let you pick names or symbolic id's for your controls. You will then use these id's to identify the controls in your program.
<p>Most controls can be encapsulated in objects that are either embedded in the appropriate Controller (you can have a separate Controller objects for every dialog box in your program) or, for static controls, in the View.
<p>Controller objects are created in response to WM_CREATE or, for dialog boxes, WM_INITDIALOG messages. Constructors of controls embedded in these Controllers are executed at that time.
<p>The base class for most controls is SimpleControl. It obtains and stores the window handle of the particular control. To obtain this handle, you need the parent window handle and the control's id.
<hr>
<pre><font face="courier">class <font color="#cc0066"><b>SimpleControl</b></font>
{
public:
SimpleControl (HWND hwndParent, int id)
: _hWnd (<font color="#000099"><b>GetDlgItem</b></font> (hwndParent, id))
{}
void SetFocus ()
{
<font color="#000099"><b>::SetFocus</b></font> (_hWnd);
}
HWND Hwnd () const { return _hWnd; }
protected:
HWND _hWnd;
};
</font></pre>
<hr>
Here's an example of an edit control
<hr>
<pre><font face="courier">class <font color="#cc0066"><b>Edit</b></font>: public <font color="#cc0066"><b>SimpleControl</b></font>
{
public:
Edit (HWND hwndParent, int id)
: SimpleControl (hwndParent, id)
{}
void SetString (char* buf)
{
<font color="#000099"><b>SendMessage</b></font> (Hwnd (), WM_SETTEXT, 0, (LPARAM) buf);
}
// code is the HIWORD (wParam)
static BOOL IsChanged (int code)
{
return code == EN_CHANGE;
}
int GetLen ()
{
return <font color="#000099"><b>SendMessage</b></font> (Hwnd (), WM_GETTEXTLENGTH, 0, 0);
}
void GetString (char* buf, int len)
{
<font color="#000099"><b>SendMessage</b></font> (Hwnd (), WM_GETTEXT,
(WPARAM) len, (LPARAM) buf);
}
void Select ()
{
<font color="#000099"><b>SendMessage</b></font> (Hwnd (), EM_SETSEL, 0, -1);
}
};</font></pre>
<hr>
This is how the edit control may be used:
<hr>
<pre><font face="courier">class <font color="#cc0066"><b>Controller</b></font>
{
public:
Controller(HWND hwnd);
...
private:
Edit _edit;
char _string [maxLen];
};
<font color="#cc0066"><b>Controller::Controller</b></font> (HWND hwnd)
: _edit (hwnd, IDC_EDIT)
{
_edit.SetFocus ();
...
}
void <font color="#cc0066"><b>Controller::Command</b></font> (HWND hwnd, WPARAM wParam, LPARAM lParam)
{
switch (LOWORD(wParam))
{
case IDC_EDIT:
if (_edit.IsChanged(HIWORD (wParam)))
{
_edit.GetString (_string, maxLen);
}
break;
...
}
}
</font></pre>
<hr>
But, of course, the most likely place to use controls is in a <a href="windlg.html">Dialog Box</a>.
<hr>
</table>
<td width=60>
</table>
<layer src="http://www.spidersoft.com/ads/bwz468_60.htm" visibility=hidden id=a1 width=600 onload="moveToAbsolute(ad1.pageX,ad1.pageY); a1.clip.height=60;visibility='show';"></layer>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -