Microsoft Knowledge Base Email Alertz

KBAlertz.com: (86724) - 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...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








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

SUMMARY

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.

MORE INFORMATION

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.
  1. Add SHELL.LIB to the list of libraries required to build the file.
  2. Add the name of the subclass procedure (MyDragDropProc) to the EXPORTS section of the module definition (DEF) file.
  3. Include the SHELLAPI.H file in the application's source code.
  4. Declare the following procedure and variables:
          BOOL FAR PASCAL MyDragDropProc(HWND, unsigned, WORD, LONG);
    
          FARPROC lpfnDragDropProc, lpfnOldEditProc;
          char    szTemp64[64];
    					
  5. 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;
    					
  6. 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;
          }
    					
  7. 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
Keywords: 
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