⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drag_edit.shtml.htm

📁 一套比较全的编辑框控制教程。。。附源代码。
💻 HTM
字号:
<html>

<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="zafir anjum">
<title>edit controls - table of contents</title>
<meta name="description" content="source code for various windows controls">
<meta name="keywords" content="mfc source code edit controls">
</head>

<body background="../di2001.jpg"
tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#ffffff">

<h3 align="center"><font color="#aoao99">drag text between edit controls</font></h3>

<hr>

<p>this article was contributed by <a href="mailto:ysl@springsoft.com.tw">sam lu</a>. </p>

<p>recently, i completed a cdragedit class. with this class, user can copy/move string
between edit controls or other editors just by drag-and-drop. </p>

<p>the <a href="drag_edit_src.zip"
tppabs="http://www.codeguru.com/editctrl/drag_edit_src.zip">drag_edit_src.zip</a> is the
source code of cdragedit and the <a href="drag_edit_test.zip"
tppabs="http://www.codeguru.com/editctrl/drag_edit_test.zip">drag_edit_test.zip</a> is the
test program, including its source code also, of cdragedit. both of zip files have one
readme.txt. in this file, i have described how to use it and how it works. for your
convenience, i also listed the content of readme.txt at the bottom of this mail. </p>

<p>in the past time, if you want to copy/move string from one edit control to another edit
control or copy/move string from one edit window of foreign application to a edit control,
only you can do is copy, cut, and paste via clipboard. for such a inconvenience, i
implemented a cdragedit control which is based on the standard cedit control so that you
can override the existent application's edit control as a drag-drop enabled control very
easily. besides that the cdragedit's drag-drop capability is implemented via ole's udt
(uniform data transfer) so you can use its drag-drop to share data with most applications.
e.g. visual c++, wordpad, word, ...,etc. </p>

<p>if you have any question about the cdragedit, don't hesitate to e-mail to me. </p>

<pre><tt>
* class hierarchy of cdragedit

cobject
|
+-ccmdtarget
&nbsp; |
&nbsp; +-cwnd
&nbsp;&nbsp;&nbsp; |
&nbsp;&nbsp;&nbsp; +-cedit
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
&nbsp;&nbsp;    +-cdragedit
</tt></pre>

<h3>* how to use the cdragedit ?</h3>

<h4>to use a drag edit control in an existing dialog box</h4>

<p>in your dialog definition file, you need to include the &quot;cdragedit.h&quot; first,
and then declare cdragedit member variable corresponding to each edit control that you
want it become a drag-drop enabled control. after you have declared the cdragedit
variables, you have to use ddx_control() to subclass the standard edit control as a
cdragedit control in dodataexchange() and call cdragedit::init(), in oninitialdialog(), to
initiate the cdragedit and enable its drag-drop capability. </p>

<h4>to use a drag edit control in toolbar</h4>

<p>calling cdragedit::create() to create a drag edit control and then call
cdragedit::init() to initiate this edit control and enable its drag-drop capability. </p>

<p>for example, you want to use two drag edit controls in the ctestdrageditdlg. you need
to add some codes in your xxxdlg.h and xxxdlg.cpp as below: </p>

<pre><tt><font color="#990000">
////////////////////// //testdrageditdlg.h ////////////////////// #include
&quot;cdragedit.h&quot; //include it in your xxxdlg.h

class ctestdrageditdlg : public cdialog
{
	...
	// dialog data
	//{{afx_data(ctestdrageditdlg)
	enum { idd = idd_dragedit };
	cdragedit m_edit2; //declare a cdragedit variable 
	cdragedit m_edit1; //for each edit control
	//}}afx_data
	...
}

//////////////////////
//testdrageditdlg.cpp
//////////////////////
void ctestdrageditdlg::dodataexchange(cdataexchange* pdx)
{
	cdialog::dodataexchange(pdx);
	//{{afx_data_map(ctestdrageditdlg)
	ddx_control(pdx, idc_edit2, m_edit2); //subclass the standard edit
	ddx_control(pdx, idc_edit1, m_edit1); //control as a cdragedit
	//}}afx_data_map
}

bool ctestdrageditdlg::oninitdialog() 
{
	...
	&nbsp;&nbsp;&nbsp; //you need to initiate cdragedit first 
	m_edit1.init();
	&nbsp;&nbsp;&nbsp; m_edit2.init();
	...
}
</font></tt></pre>

<h4>how the cdragedit works ?</h4>

<p>as i mentioned, the drag-drop of cdragedit is implemented via ole drag-and-drop. so, i
implemented a cdedroptarget, which is based on coledroptarget, and a cdedatasource, which
is based on coledatasource. the cdedroptaregt serves the cdragedit as a data comsumer and
the ccdedatasource serves the cdragedit as a data producer. drag-drop data transfers
usually begin when the user press the left button of mouse. so, in cdragedit, simply
handle the wm_lbuttondown messagem, coping selected string into a cdedatasource object
using cacheglobaldata(), and call cdedatasource::dodragdrop() to tranfer string to a drop
target. </p>

<p>in cdragedit::init(), i register this window as a drop target by calling
cdedroptarget::register(). once a cdragedit is registered with ole to be a drop target, it
becomes eligible to receive ondropenter(), ondropover(), ondropleave(), and ondrop()
notifications from ole. in ondrop(), the cdragedit will retrieve data with cf_text format
from coledataobject and place at the dropped point. </p>

<p>for more information, please refer to the comment of source code. </p>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -