Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

WTL for MFC Programmers, Part X - Implementing a Drag and Drop Source

, 16 Jun 2006
A tutorial on using drag and drop in your WTL application.
wtl4mfc10_demo.zip
WTL4MFC10_demo
WTLCabView
release
WTLCabView.exe
res
next.ico
prev.ico
Toolbar.bmp
WTLCabView.exe.manifest
WTLCabView.ico
WTLCabView.dsp
WTLCabView.dsw
// WTLCabViewView.h : interface of the CWTLCabViewView class
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_WTLCABVIEWVIEW_H__9300C31D_E4FF_4E4B_A98D_670F63106D35__INCLUDED_)
#define AFX_WTLCABVIEWVIEW_H__9300C31D_E4FF_4E4B_A98D_670F63106D35__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#define VIEW_STYLES (LVS_REPORT|LVS_SHOWSELALWAYS|LVS_SHAREIMAGELISTS|LVS_AUTOARRANGE)
#define VIEW_EX_STYLES (WS_EX_CLIENTEDGE)

class CWTLCabViewView : public CWindowImpl<CWTLCabViewView, CListViewCtrl,
                                             CWinTraitsOR<VIEW_STYLES,VIEW_EX_STYLES> >
{
public:
    DECLARE_WND_SUPERCLASS(NULL, CListViewCtrl::GetWndClassName())

    // Construction
    CWTLCabViewView();

    // Maps
    BEGIN_MSG_MAP(CWTLCabViewView)
        MSG_WM_DESTROY(OnDestroy)
        REFLECTED_NOTIFY_CODE_HANDLER_EX(LVN_COLUMNCLICK, OnColumnClick)
        REFLECTED_NOTIFY_CODE_HANDLER_EX(LVN_MARQUEEBEGIN, OnMarqueeBegin)
        REFLECTED_NOTIFY_CODE_HANDLER_EX(LVN_KEYDOWN, OnKeyDown)
        REFLECTED_NOTIFY_CODE_HANDLER_EX(LVN_DELETEITEM, OnDeleteItem)
        DEFAULT_REFLECTION_HANDLER()
    END_MSG_MAP()

    // Message handlers
    BOOL PreTranslateMessage ( MSG* pMsg );

    void OnDestroy();

    // Notify handlers
    LRESULT OnColumnClick ( NMHDR* phdr );
    LRESULT OnMarqueeBegin ( NMHDR* phdr );
    LRESULT OnKeyDown ( NMHDR* phdr );
    LRESULT OnDeleteItem ( NMHDR* phdr );

    // Operations
    void Init();
    void Clear();
    void SetViewMode ( int nMode );
    void AddFile ( LPCTSTR szFilename, long cbyUncompressedSize, USHORT uDate,
                   USHORT uTime, USHORT uAttribs );
    void AddPartialFile ( LPCTSTR szFilename, LPCTSTR szStartingCabName,
                          LPCTSTR szStartingDiskName );
    void UpdateContinuedFile ( const CDraggedFileInfo& info );
    bool GetDraggedFileInfo ( std::vector<CDraggedFileInfo>& vec );

protected:
    CImageList m_imlSmall, m_imlLarge, m_imlTiles, m_imlState;
    CComPtr<IImageList> m_TileIml;

    int m_nSortedCol;   // -1 if list hasn't been sorted yet
    bool m_bSortAscending;

    void InitImageLists();
    void InitColumns();

    static int CALLBACK SortCallback ( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort );
    int SortCallback ( const CCompressedFileInfo& info1, const CCompressedFileInfo& info2 ) const;
};


/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_WTLCABVIEWVIEW_H__9300C31D_E4FF_4E4B_A98D_670F63106D35__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Michael Dunn
Software Developer (Senior) VMware
United States United States
Michael lives in sunny Mountain View, California. He started programming with an Apple //e in 4th grade, graduated from UCLA with a math degree in 1994, and immediately landed a job as a QA engineer at Symantec, working on the Norton AntiVirus team. He pretty much taught himself Windows and MFC programming, and in 1999 he designed and coded a new interface for Norton AntiVirus 2000.
Mike has been a a developer at Napster and at his own lil' startup, Zabersoft, a development company he co-founded with offices in Los Angeles and Odense, Denmark. Mike is now a senior engineer at VMware.

He also enjoys his hobbies of playing pinball, bike riding, photography, and Domion on Friday nights (current favorite combo: Village + double Pirate Ship). He would get his own snooker table too if they weren't so darn big! He is also sad that he's forgotten the languages he's studied: French, Mandarin Chinese, and Japanese.
 
Mike was a VC MVP from 2005 to 2009.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 16 Jun 2006
Article Copyright 2006 by Michael Dunn
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid