Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 86724 - Last Review: July 11, 2005 - Revision: 1.3
How To Use Drag-Drop in an Edit Control or a Combo Box
This article was previously published under Q86724
In the Microsoft Windows environment, an application can register an
edit control or a combo box as a drag-drop client through the
DragAcceptFiles function. The application must also subclass the
control to process the WM_DROPFILES message that Windows sends when
the user drops a file.
The following seven steps demonstrate how to implement drag-drop in an
edit control. The procedure to implement drag-drop in a combo box is
identical.
- Add SHELL.LIB to the list of libraries required to build the file.
- Add the name of the subclass procedure (MyDragDropProc) to the
EXPORTS section of the module definition (DEF) file.
- Include the SHELLAPI.H file in the application's source code.
- Declare the following procedure and variables:
BOOL FAR PASCAL MyDragDropProc(HWND, unsigned, WORD, LONG);
FARPROC lpfnDragDropProc, lpfnOldEditProc;
char szTemp64[64];
- Add the following code to the initialization of the dialog box:
case WM_INITDIALOG:
// ... other code
// ------- edit control section --------
hWndTemp = GetDlgItem(hDlg, IDD_EDITCONTROL);
DragAcceptFiles(hWndTemp, TRUE);
// subclass the drag-drop edit control
lpfnDragDropProc = MakeProcInstance(MyDragDropProc, hInst);
if (lpfnDragDropProc)
lpfnOldEditProc = SetWindowLong(hWndTemp, GWL_WNDPROC,
(DWORD)(FARPROC)lpfnDragDropProc);
break;
- Write a subclass window procedure for the edit control.
BOOL FAR PASCAL MyDragDropProc(HWND hWnd, unsigned message,
WORD wParam, LONG lParam)
{
int wFilesDropped;
switch (message)
{
case WM_DROPFILES:
// Retrieve number of files dropped
// To retrieve all files, set iFile parameter
// to -1 instead of 0
wFilesDropped = DragQueryFile((HDROP)wParam, 0,
(LPSTR)szTemp64, 63);
if (wFilesDropped)
{
// Parse the file path here, if desired
SendMessage(hWnd, WM_SETTEXT, 0, (LPSTR)szTemp64);
}
else
MessageBeep(0);
DragFinish((HDROP)wParam);
break;
default:
return CallWindowProc(lpfnOldEditProc, hWnd, message,
wParam, lParam);
break;
}
return TRUE;
}
- After the completion of the dialog box procedure, free the edit
control subclass procedure.
if (lpfnDragDropProc)
FreeProcInstance(lpfnDragDropProc);
APPLIES TO
- Microsoft Platform Software Development Kit-January 2000 Edition
| kbhowto kbdragdrop kbcombobox kbeditctrl kbctrl KB86724 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please