Drag text between edit controls
The drag_edit_src.zip is the source code of CDragEdit and the drag_edit_test.zip 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.
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.
* Class hierarchy of CDragEdit CObject | +-CCmdTarget | +-CWnd | +-CEdit | +-CDragEdit
* How to use the CDragEdit ?
To use a drag edit control in an existing dialog box
In your dialog definition file, you need to include the "CDragEdit.h" 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.To use a drag edit control in toolbar
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.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:
////////////////////// //TestDragEditDlg.h ////////////////////// #include "CDragEdit.h" //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() { ... //You need to initiate CDragEdit first m_edit1.Init(); m_edit2.Init(); ... }
How the CDragEdit works ?
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.
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.
For more information, please refer to the comment of source code.
Comments
How do I swap contents from one edit box to another
Posted by Legacy on 02/19/2004 12:00amOriginally posted by: Chris
I am new at this programming stuff and seen some good stuff on this site. Just wondering if someone could give me an example of how to swap the contents of one edit box to another edit box?
Please Help !!
Chris
ReplyHow do i apply it in borland c++ builder?
Posted by Legacy on 10/13/2002 12:00amOriginally posted by: Tony
How do i apply it in borland c++ builder?
ReplyCould you post a example using bcb?
Property pages
Posted by Legacy on 08/12/2002 12:00amOriginally posted by: Wendell Peeples
How do I drag a row of text from one application and make it an image in the other another
Posted by Legacy on 06/17/2002 12:00amOriginally posted by: Ryan
I was just wondering if any of you knew how to drag text from one application to another. I know how to drag images I just do not know how to drag and drop text from one application and drop it as an image.
Thanks
ReplyRyan Henry
How do I append a text in Edit control.
Posted by Legacy on 03/21/2002 12:00amOriginally posted by: S.R.Krishnan
The eg you put was great.My need is as follows.I have got a huge list of texts to be appended to the existing text control.This might happen at regular intervals of time.Iam also forced to use Edit control only.(Though Richedit provied better alternative).
How will I add a text.
Is there any message like LB_ADDSTRING for a listbox.
Krishnan.S.R.
ReplyExEditors Library
Posted by Legacy on 03/19/2002 12:00amOriginally posted by: Mike Philips
CListBox Drag and Drop
Posted by Legacy on 03/07/2002 12:00amOriginally posted by: amit khera
How do I drag a list item from one CListBox to another?
Replyusing hot key to copy.....
Posted by Legacy on 09/08/2001 12:00amOriginally posted by: jonse
How to get the string marked by me by using hot key ??
I want to copy string from any application(just as like txt,words and IE) to IDC_EDIT2 by using hot key .....
Can you help me...??
ReplyDisplay a text file in an edit Control when an open and save button is pressed
Posted by Legacy on 05/11/2001 12:00amOriginally posted by: sharon
I am very happy to see that your code and commants are nice
ReplyI want to know more about edit control.Any Text file has to be Opened or Saved on an Edit control. when ever I press an Open Button it has to open a text file and when pressed on save it has to be save the text file. Please kindly let me know about it.
thanks
sharon.
Correct your PosFromChar Function
Posted by Legacy on 03/23/2001 12:00amOriginally posted by: Qing
Loading, Please Wait ...