Drag and drop in a listbox.

I can't get this to work. Every time i only se the circle with a crossover line icon (not allowed sign).

What shall i do?

Your sincerely andla.

// AndyLite.h : Declaration of the CAndyLite

#ifndef __ANDYLITE_H_
#define __ANDYLITE_H_

#include "resource.h"       // main symbols
#include <atlctl.h>
#include <commctrl.h>


/////////////////////////////////////////////////////////////////////////////
// CAndyLite
BOOL InitListViewImageLists(HWND hwndLV);
BOOL WINAPI InitListViewItems(HWND hwndLV, FILE *pfData) ;
LPSTR DupString(LPSTR lpsz);
void SetInitialData(HWND hList);
#define C_COLUMNS 6  
typedef struct myitem_tag
{    
LPSTR aCols[C_COLUMNS];
} MYITEM;

class ATL_NO_VTABLE CAndyLite :
      public CComObjectRootEx<CComSingleThreadModel>,
      public CStockPropImpl<CAndyLite, IAndyLite, &IID_IAndyLite, &LIBID_DRAGTEMPLib>,
      public CComControl<CAndyLite>,
      public IPersistStreamInitImpl<CAndyLite>,
      public IOleControlImpl<CAndyLite>,
      public IOleObjectImpl<CAndyLite>,
      public IOleInPlaceActiveObjectImpl<CAndyLite>,
      public IViewObjectExImpl<CAndyLite>,
      public IOleInPlaceObjectWindowlessImpl<CAndyLite>,
      public CComCoClass<CAndyLite, &CLSID_AndyLite>
{
public:
      CContainedWindow m_ctlSysListView32;
      

      CAndyLite() :      
            m_ctlSysListView32(_T("SysListView32"), this, 1)
      {
            m_bWindowOnly = TRUE;
            m_hWndList=0;
            
      }

DECLARE_REGISTRY_RESOURCEID(IDR_ANDYLITE)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CAndyLite)
      COM_INTERFACE_ENTRY(IAndyLite)
      COM_INTERFACE_ENTRY(IDispatch)
      COM_INTERFACE_ENTRY(IViewObjectEx)
      COM_INTERFACE_ENTRY(IViewObject2)
      COM_INTERFACE_ENTRY(IViewObject)
      COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
      COM_INTERFACE_ENTRY(IOleInPlaceObject)
      COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
      COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
      COM_INTERFACE_ENTRY(IOleControl)
      COM_INTERFACE_ENTRY(IOleObject)
      COM_INTERFACE_ENTRY(IPersistStreamInit)
      COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
END_COM_MAP()

BEGIN_PROP_MAP(CAndyLite)
      PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
      PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
      PROP_ENTRY("HWND", DISPID_HWND, CLSID_NULL)
      // Example entries
      // PROP_ENTRY("Property Description", dispid, clsid)
      // PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()

BEGIN_MSG_MAP(CAndyLite)
      MESSAGE_HANDLER(WM_CREATE, OnCreate)
      MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
      CHAIN_MSG_MAP(CComControl<CAndyLite>)
ALT_MSG_MAP(1)
      // Replace this with message map entries for superclassed SysListView32
      MESSAGE_HANDLER(WM_DROPFILES, OnDropFiles)
END_MSG_MAP()
// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

      BOOL PreTranslateAccelerator(LPMSG pMsg, HRESULT& hRet)
      {
            if(pMsg->message == WM_KEYDOWN && 
                  (pMsg->wParam == VK_LEFT ||
                  pMsg->wParam == VK_RIGHT ||
                  pMsg->wParam == VK_UP ||
                  pMsg->wParam == VK_DOWN))
            {
                  hRet = S_FALSE;
                  return TRUE;
            }
            //TODO: Add your additional accelerator handling code here
            return FALSE;
      }

      LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
      {
            LRESULT lRes = CComControl<CAndyLite>::OnSetFocus(uMsg, wParam, lParam, bHandled);
            if (m_bInPlaceActive)
            {
                  DoVerbUIActivate(&m_rcPos,  NULL);
                  if(!IsChild(::GetFocus()))
                        m_ctlSysListView32.SetFocus();
            }
            return lRes;
      }

      LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
      {
            RECT rc;
            GetWindowRect(&rc);
            rc.right -= rc.left;
            rc.bottom -= rc.top;
            rc.top = rc.left = 0;
            InitCommonControls();


DWORD dwStyle = WS_VISIBLE|WS_CHILD|LVS_REPORT|LVS_SINGLESEL|WS_BORDER|WS_EX_ACCEPTFILES;
if (!m_hWndList)  
m_hWndList = m_ctlSysListView32.Create(m_hWnd, rc, _T(""), dwStyle);
 
_ASSERTE(m_hWndList);



            //This displays icons.
            SetInitialData(m_ctlSysListView32);
            ::DragAcceptFiles( m_ctlSysListView32,TRUE );
// register the control as a drag and drop target
if(!(S_OK==::RegisterDragDrop(m_ctlSysListView32, (IDropTarget *) this)))
::MessageBox(0,"Error","",0);
if( MakeDragList( m_ctlSysListView32))
MessageBox("success","",0);




            /*if(!InitListViewImageLists(m_hWnd))
                  MessageBox("error","",0);
 
/*TCHAR sz[8];
wsprintf(sz,_TEXT("%ld"), 23);
memset(&item, NULL, sizeof(item));
item.mask = LVIF_TEXT;
item.iItem = 1;
item.pszText = sz;
item.cchTextMax = lstrlen(sz);
 
ListView_InsertItem(m_hWnd, &item);
ListView_SetItemText(m_hWnd, 1, 0, "bulle"); */




            return 0;
      }
      STDMETHOD(SetObjectRects)(LPCRECT prcPos,LPCRECT prcClip)
      {
            IOleInPlaceObjectWindowlessImpl<CAndyLite>::SetObjectRects(prcPos, prcClip);
            int cx, cy;
            cx = prcPos->right - prcPos->left;
            cy = prcPos->bottom - prcPos->top;
            ::SetWindowPos(m_ctlSysListView32.m_hWnd, NULL, 0,
                  0, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE);
            return S_OK;
      }

// IViewObjectEx
      DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)

// IAndyLite
public:
      //LV_ITEM item;
      HWND m_hWndList;
      LRESULT OnDropFiles(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
      {
            // TODO : Add Code for message handler. Call DefWindowProc if necessary.
            return 0;
      }
};

#endif //__ANDYLITE_H_
LVL 1
andlaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

andlaAuthor Commented:
Check the OnCreate and the interfaces if i did it correct.

0
WxWCommented:
Subclass the control and use in the new proc the WM_DROPFILES handle .
0
andlaAuthor Commented:
like this:

class myclass: public dragclass
{
protected:
public:
myclass(){}
~myclass(){}
}

Shall i implement the OnDropFile function?
0
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

WxWCommented:
Your mistake is that you have WS_EX_ACCEPTFILES in the style . WS_EX_ACCEPTFILES is an extended style . Try this after creating the
m_hWndList :

::SetWindowLong(m_hWndList,GWL_EXSTYLE,
::GetWindowLong(m_hWndList,GWL_EXSTYLE) | WS_EX_ACCEPTFILES);

0
WxWCommented:
btw this is an one-line command , EE put the ::GetWindowLong in next line . Don't assume they are 2 lines .
0
andlaAuthor Commented:
I tried to remove ws_ex_acceptfiles as you said and nothing happend. I think there is no problem mixing extended styles ? I can check what styles a window has (with windowse.exe). Please post more suggestions they are very valuable. I need any possible idea.

Your sincerely
andla.
0
andlaAuthor Commented:
If somebody is intressted i can send the project over mail?
0
WxWCommented:
You didn't understand . You need to remove WS_EX_ACCEPTFILES from the regular style , AND put the line I put above , to put WS_EX_ACCEPTFILES in the extended style .
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andlaAuthor Commented:
Now it works fine. Thanks!! I'm not sure why. If i use the DragAcceptFile it should put that bit on. And i tested a version without the WM_DROPFILES_EX set. Can you explain what is going on.?

Thanks!

Your sincerely andla.
0
WxWCommented:
DragAcceptFile registers a window as being able to receive files from Windows File Manager . Thats what the documentation says . I never use it .

The window should have already the WS_EX_ACCEPTFILES style so the drag & drop works .
0
andlaAuthor Commented:
Well if dragfile works it simplifies much more than ole drag and drop (i hope).

Thanks! :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Components

From novice to tech pro — start learning today.