List Control with OLE Drag '& Drop

Features

This extended list control allow OLE drag and drop between list controls. The programmer can enable/desable local drag and drop of list items inside the same control, automatic scrolling and the removing of dragged items from the source list.

Control Usage

  1. Initialize the OLE libraries in the application InitInstance member function:
  2. BOOL CDdDemoApp::InitInstance()
    {
     AfxEnableControlContainer();
    #ifdef _AFXDLL
     // Call this when using MFC in a shared DLL
     Enable3dControls(); 
    #else
     // Call this when linking to MFC statically
     Enable3dControlsStatic(); 
    #endif
    
     //-------------------------
     // Initialize OLE libraries
     //-------------------------
     if (!AfxOleInit())
      return FALSE;
    
  3. Insert the #include "DDListCtrl.h" in the dialog C++ file which contains the List Ctrls.
  4. In the OnInitDialog member function of the dialog, initialize and customize the list controls initialization according to the following template:
  5. BOOL CDdDemoDlg::OnInitDialog()
    {
     CDialog::OnInitDialog();
    
     //.................................
    
     //---------------------------->
     // 1 - Subclass the list controls
     //----------------------------
     m_listVars.SubclassDlgItem(IDC_LIST_VAR, this);
     m_listRows.SubclassDlgItem(IDC_LIST_ROWS, this);
     m_listCols.SubclassDlgItem(IDC_LIST_COLS, this);
     m_listData.SubclassDlgItem(IDC_LIST_DATA, this);
     m_listPages.SubclassDlgItem(IDC_LIST_PAGES, this);
      
     //--------------------------------------------------------------
     // 2 - Initialize the List view controls
     //--------------------------------------------------------------
     CString s(TCHAR('M'),29);
     int len = m_listVars.GetStringWidth(s)+15;
     LV_COLUMN lvC;
     lvC.mask = LVCF_FMT | LVCF_WIDTH;
     lvC.fmt  = LVCFMT_LEFT;  // Left-align column
     lvC.cx   = len;          // Width of column in pixels
     if (m_listVars.InsertColumn(0,&lvC) == -1)
      return FALSE;
    
     m_listVars.DeleteAllItems();
    
     m_listVars.SetLocalDD(FALSE);   // Disable local Drag&Drop
     m_listVars.SetScrolling(FALSE); // and auto scrolling
    
     // Create a column for the row variables list view control.
     if (m_listRows.InsertColumn(0,&lvC) == -1)
      return FALSE;
    
     m_listRows.DeleteAllItems();
    
     // Create a column for the column variables list view control.
     if (m_listCols.InsertColumn(0,&lvC) == -1)
      return FALSE;
    
     m_listCols.DeleteAllItems();
    
     // Create a column for the data variables list view control.
     if (m_listData.InsertColumn(0,&lvC) == -1)
      return FALSE;
    
     m_listData.DeleteAllItems();
    
     // Create a column for the page variables view control.
     if (m_listPages.InsertColumn(0,&lvC) == -1)
      return FALSE;
      
     m_listPages.DeleteAllItems();
    
     //------------------------------------------
     // 3 - Set the content of the list view controls
     //------------------------------------------
     CWordArray aVars;
     int size = m_pSelectInfo->m_asNames.GetSize();
     aVars.SetSize(size);
     // Initially the list of available variables contains all variables
     for (int i=0; i<size; i++)
      aVars[i] = i;
    
     // Fill the list of variables
     m_pData->FillListCtrl(m_listVars, aVars);
     m_pData->FillListCtrl(m_listRows, m_pSelectInfo->m_aRowsVar); 
     m_pData->FillListCtrl(m_listCols, m_pSelectInfo->m_aColsVar);  
     m_pData->FillListCtrl(m_listData, m_pSelectInfo->m_aDataVar); 
     m_pData->FillListCtrl(m_listPages, m_pSelectInfo->m_aPagesVar); 
    
     //-----------------------------------------------
     // 4 - Initialize the list controls for Drag&Drop
     //-----------------------------------------------
     m_listVars.Initialize();
     m_listRows.Initialize();
     m_listCols.Initialize();
     m_listData.Initialize();
     m_listPages.Initialize();
     
     return TRUE;  
    }
    

Downloads

Download source - 9 Kb
Download demo project - 32 Kb


Comments

  • Better not to use WM_TIMER

    Posted by Legacy on 01/16/2002 12:00am

    Originally posted by: Robert Dyer

    Because timer messages occur ONLY when the message queue is empty, they are not reliable to use during a drag and drop operation. I found the timer messages were sometimes not getting sent and hence the scrolling did not occur.

    The idea of course here is to make sure scrolling does
    not happen any faster than one line per 300 milliseconds.
    A better approach that also uses less code and fewer resources is to use the WIN32 API function GetTickCount
    in the OnDragOver method of the COleListCtrlDropTarget
    class in DDListCtrl.cpp. Just keep track of the previous tick count when scrolling occurred, and scroll only when the difference between the current and previous tick counts exceeds 300 milliseconds.

    Then there is no need for calls to SetTimer and KillTimer, and you can remove the OnTimer method of CDDListCtrl.


    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The world of data storage is changing around us as organizations continue to seek ways by which they can leverage cloud-based services. However, simply shifting everything to the public cloud is generally neither desirable nor feasible, so organizations are struggling with finding ways that they can leverage the public cloud and its outcomes where it makes sense and leave everything else on-premises. The Gorilla Guide lays out the key questions and considerations you need to think through in building your …

  • On-demand Event Event Date: March 23, 2017 As you adopt the use of cloud services, whether in public/IaaS, SaaS or hybrid environments, the attack surface expands and, if breached, the costs increase exponentially. This session is designed to help IT and security leaders understand and address the unique challenges that enterprises typically face when they deploy their applications in the public cloud. It summarizes the areas that the public cloud vendors typically take care of and highlights the areas …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date