Click here to Skip to main content
6,629,377 members and growing! (21,414 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » WTL » Shell Programming     Intermediate License: The Code Project Open License (CPOL)

How to make your application a dropfile target in WTL

By Igor Vigdorchik

A derived from class to create a dropfile target application using WTL
VC6, Windows, WTL, Dev
Posted:9 Sep 2004
Views:20,792
Bookmarked:12 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
9 votes for this article.
Popularity: 3.68 Rating: 3.86 out of 5

1
2 votes, 22.2%
2

3
5 votes, 55.6%
4
2 votes, 22.2%
5

Introduction

By dropfile target I mean the application that can process file names dropped into it.

To modify your application to become a dropfile target all you have to do is to create your window with the extended window style WS_EX_ACCEPTFILES and handle WM_DROPFILES message.

Another way is to create a window and then call the following API function:

DragAcceptFiles(HWND hWnd, BOOL bAccept)
that turns the WS_EX_ACCEPTFILES style on or off based on the value of the bAccept parameter.

The obvious solution would be to create a class to encapsulate the above mentioned logic. So I present a class CDropFileTarget that does just that.

Using the code

It's very easy to use CDropFileTarget class. Just follow the following steps:

  1. Add CDropFileTarget to the inheritance chain:
    class CMainDlg : public CDialogImpl<CMainDlg>,
            public CUpdateUI<CMainDlg>,
            public CMessageFilter, 
            public CIdleHandler,
            public CDropFileTarget<CMainDlg>
  2. Add CHAIN_MSG_MAP statement to the message map of your class:
    BEGIN_MSG_MAP(CMainDlg)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
        COMMAND_ID_HANDLER(IDOK, OnOK)
        COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
        CHAIN_MSG_MAP(CDropFileTarget<CMainDlg>)
    END_MSG_MAP()
  3. In OnInitDialog() function register your class as a dropfile target
    LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, 
      LPARAM /*lParam*/, BOOL& /*bHandled*/)
    {
        ...
        RegisterDropTarget();
        ...
    }
    
  4. Add the following public function to process the dropped file
    void ProcessFile(LPCTSTR lpszPath)
    {
        // Add your logic
    
    }
That's it.

Conclusion

This class is very simple and may not meet all your requirements, but if you only need to allow your window to accept dropped files and process them then this class is for you.

Disclaimer

THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO RESPONSIBILITIES FOR POSSIBLE DAMAGES CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE RISK OF USING THIS SOFTWARE.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Igor Vigdorchik


Member

Occupation: Web Developer
Location: United States United States

Other popular WTL articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
GeneralNice! PinmemberPablo Aliskevicius20:41 18 Sep '04  
GeneralRe: Nice! PinmemberIgor Vigdorchik6:23 19 Sep '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 9 Sep 2004
Editor: Nishant Sivakumar
Copyright 2004 by Igor Vigdorchik
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project