 |
|
 |
I found that this works well in a CFormView if I change one of your steps from:
m_dropEdit.SubclassDlgItem(IDC_YOUR_EDIT_ID, this);
to
m_dropEdit.SubclassDlgItem(IDC_YOUR_EDIT_ID, AfxGetMainWnd());
Probably most already know this but I so rarely do this kind of thing that it took me 1/2 hour to figure it out.
Good article. Thanks!
|
|
|
|
 |
|
 |
how to install a numeric editor component
like the one in windows date and time wizard
edit with two pointers to increase & decrease time
|
|
|
|
 |
|
 |
When I put CDropEdit inside a groupbox (CStatic element with property "AcceptFiles" to "true") it doesn't accept dropped files or folders. When I set groupbox property "Dissabled" to "true" it works, but the groupbox title becomes gray. Is there another way to fix this problem?
Thanks.
Vadim
|
|
|
|
 |
|
 |
oh man, did you ever figure out a way to get around this? It's funny that I ran into this problem only a day after you. I was going nuts making sure I covered everything in the example, and I was beginning to think my problem was the fact that the dialog with my CDropEdit is in a tab control. But then I read your comment, disabled the group box, and it worked perfectly...
|
|
|
|
 |
|
 |
I found the solution in another thread. The problem was the z-order of my controls. Your group box was probably added before your CDropEdit control- try deleting the group box and replacing it.
Hope that works for you too!
|
|
|
|
 |
|
 |
I've used this method successfully in Dialogs. It doesn't use COM and doesn't use SubClassing, The control class handles the processing independantly of the Dialog, so it can be as simple or as complex as you need.
Create a new DropEdit class that inherits from CEdit.
// ======================= DropEdit.h =================================
#pragma once
// CDropEdit
class CDropEdit : public CEdit
{
DECLARE_DYNAMIC(CDropEdit)
public:
CDropEdit();
virtual ~CDropEdit();
protected:
void OnDropFiles(HDROP hDropInfo);
DECLARE_MESSAGE_MAP()
};
In the implementation file process the ON_WM_DROPFILES message
// ========================= DropEdit.cpp ==============
// DropEdit.cpp : implementation file
//
#include "stdafx.h"
#include "DropEdit.h"
// CDropEdit
IMPLEMENT_DYNAMIC(CDropEdit, CEdit)
BEGIN_MESSAGE_MAP(CDropEdit, CEdit)
ON_WM_DROPFILES()
END_MESSAGE_MAP()
CDropEdit::CDropEdit()
{
}
CDropEdit::~CDropEdit()
{
}
void CDropEdit::OnDropFiles(HDROP hDropInfo)
{
TCHAR szFileName[_MAX_PATH];
DragQueryFile(hDropInfo,0,szFileName, _MAX_PATH - 1);
SetWindowText(szFileName);
}
In your application files declare a CDropEdit control variable .
// ================== TestDlg.h ===================
// TestDlg.h
#include "DropEdit.h"
Class CTestDlg : public CDialog
{
public:
CDropEdit m_DropEdit;
CString m_FilePath;
};
Finally add the Dialog initalization and message entries
// =================== TestDlg.cpp ==============
// TestDlg.cpp
// IDC_FILENAME is a standard Edit control in the Dialog
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_FILENAME, m_FilePath);
DDX_Control(pDX, IDC_FILENAME, m_DropEdit);
}
BOOL CTestDlg::OnInitDialog()
{
// insert one line to enable drag/drop
::DragAcceptFiles(m_DropEdit.m_hWnd,TRUE);
}
Now when you drop a file into the edit control, the DropEdit class handles the message internally, and the file path just appears as window text in the edit control.
You get the path by using UpDateData() or GetDlgItemText(...) API calls, whichever you prefer.
|
|
|
|
 |
|
 |
GrazM wrote: DDX_Control(pDX, IDC_FILENAME, m_DropEdit);
just FYI, that line ends up doing the same 'subclass' call that i made explict in my instructions.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
 |
|
 |
You are correct, of course. The subclassing is done under the covers, so for the purposes of demonstrating the technique your method has more clarity
Thanks.
|
|
|
|
 |
|
 |
Quite short article
But long story short (so to say ) the idea is very good. And so is the control. Thanks.
SkyWalker
|
|
|
|
 |
|
 |
It's what I want!
Thanks!;P
|
|
|
|
 |
|
 |
What if the control you want to receive dropped files is contained in a dialog that is used as a custom control? It doesn't seem to handle the drag events. Instead the parent dialog controls this. How do you give control to the child dialog?
|
|
|
|
 |
|
 |
I am having problems too with this. I have seen similar posts too.
I want to include this in a modal dialog. Do I still include initialize and couninitialize in the CMine.cpp app class? also the ONinitdialog of the CWithDropEditDlg.cpp gets called when the main dialog (CMineDlg.cpp) is initialized. I have tried on draw and onpaint but no luck.
It compiles fine but
if you need anything more info please ask.
it is a lovely class and i have altered it to parse the dragged on file and extract all http:// urls from it. It was just what i was after.
thanks
kurt
edited**
My dialog:
Main -> Popup (modal) -> modal has child dialogs inside. ( tab like with buttons instead of tabs).
If i add the edit to the popup dialog it works fine, but if i add it to one of its childs, hte tabs, it doesnt doo it. still compiles.
|
|
|
|
 |
|
 |
What a great idea...
cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
 |
|
 |
Thanks a ton for your contribution! I got the DropEdit control working, but I do not know how to use the data now that I have it. I want to call some functions in my dialog class, but I get a compile error saying I can not call non-static functions. Do I need to send a USER_MSG to the dialog window? Also, it seems that if I use the SubclassDlgItem() method (as opposed to declaring the variable CDropEdit) that I should get the WM_DROPFILES message in the dialog class since 'this' points to the dialog class, but this doesn't work. I have six edit boxes that I would like to drop files on, so another consideration is that I need to know the control ID of the edit box that got dropped on.... which I know inside your CDropEdit class. Any thoughts on this would surely be appriciated. I guess I am more of a beginner at this than I thought. Thanks agian for your work and your help.
Chris
|
|
|
|
 |
|
 |
you can handle the EN_CHANGE message in your dialog for each edit control (use the class wizard). your handlers will be called each time the text in a specific edit control changes. this is built into CEdit.
-c
Though the cough, hough and hiccough so unsought would plough me through,
enough that I o'er life's dark lough my thorough course pursue.
--Stuart Kidd
|
|
|
|
 |
|
 |
That worked fine! Thanks for the suggestion.
Chris
|
|
|
|
 |
|
|
 |
|
 |
Great work!
Here's my app that uses CDropEdit. I have an Edit control and three buttons. You put a filename into the Edit control, and one button locks the file (CFile::Open with no sharing). Another button will unlock the file, and the last button closes the dialog. All it does is lock and unlock a file.
When the user clicks on the lock button, I want to disable the lock button and the edit control. To do that, I created a CEdit member variable attached to the edit control, in addition to the CString member variable that's used in your class. So when the user clicks on the lock button, I do a .EnableWindow(TRUE); Then when the user clicks on the unlock button, everything goes back to normal.
Everything compiles fine. But when I run, it gives an assertion error when it gets to:
m_dropEdit.SubclassDlgItem(IDC_LOCKFILENAME,this);
When I remove all of my CEdit member variable stuff (disabling of edit control), everything works fine. Can you please help?
Thanks.
|
|
|
|
 |
|
 |
the problem is that you've used the same edit control for two variables.
here's what i'd do...
get rid of that subclass statement. then, in your .h file for the dialog, replace the "CEdit m_myEdit;" declaration with "CDropEdit m_myEdit;". the subclass stuff will be done automatically for you.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
 |
|
 |
Chris, thanks for such a fast reply, and for such an easy solution!
|
|
|
|
 |
|
 |
I have worked with VC 6.00 and I have zipped the hole project using Windows Commander selecting the entire directory the pressing Ctrl F5 .
During this operation the main .cpp file from may project simply DISSAPEARED !!! I have observed this shortly after I have deleted the zip file .
I can't recover none of them (have tried norton unerase , recicle bin )
If you have any idea please , please help me!
Thanks
Jancsi
xxx
|
|
|
|
 |
|
 |
Try searching the files in your temp dir for one with the right text in it... VS quite often puts the cpp files in temp files.... I've recovered from there a few times...
Blade[DMS]
|
|
|
|
 |
|
|
 |
|
 |
you're quite welcome.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
 |
|
 |
if this class is used in a dialog (not an dialog-app) the subclass call crashes !
ghu
|
|
|
|
 |