⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 duallistmanager.cpp

📁 一个完整的考勤处理软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:

///////////////////////////////////////////////////////////////////////////////
//
//  Method:			EnableButtons
//
//  Purpose:		Enables/disables all of the buttons Add; Add All; Remove: 
//                  Remove All; Move Up; Move Down; based on the contents and 
//                  selction state of the listbox controls.
//
//  Inputs:
//
//		void
//
//  Outputs:
//
//		None
//
//  Return value:
//
//		void 
//
//  Exceptions:		None
//
///////////////////////////////////////////////////////////////////////////////
void CDualListManager::EnableButtons(bool bIsCur)//void
{
    int     iSelCountAvailable;
    int     iCountAvailable    = m_ctrlAvailableList.GetCount();
    int     iSelCountChoosen   = m_ctrlChoosenList.GetSelCount();
    int     iCountChoosen      = m_ctrlChoosenList.GetCount();

    // If either of the listboxes are single selection listboxes the call to 
    // GetSelCount() will return -1 even if an item is selected. This code 
    // checks the style flag for each control and calls GetCurSel or 
    // GetSelCount depending on which style the given listbox has.
    // Get the count for the available list
    if(TRUE == m_bAvailableListSingleSelType)
    {
        iSelCountAvailable = (-1 == m_ctrlAvailableList.GetCurSel()) ? 0 : 1;
    }
    else
    {
        iSelCountAvailable = m_ctrlAvailableList.GetSelCount();
    }
    // Get the count for the choosen list
    if(TRUE == m_bChoosenListSingleSelType)
    {
        iSelCountChoosen = (-1 == m_ctrlChoosenList.GetCurSel()) ? 0 : 1;
    }
    else
    {
        iSelCountChoosen = m_ctrlChoosenList.GetSelCount();
    }

    BOOL    bEnableMoveUp   = FALSE;
    BOOL    bEnableMoveDown = FALSE;

    // Now enable/disable the move buttons based on the contents and selction 
    // state of the listbox controls.
    EnableWindow( m_iIDAddButton, iSelCountAvailable > 0 ? bIsCur : FALSE);
    EnableWindow( m_iIDAddAllButton, iCountAvailable > 0 ? bIsCur : FALSE);
    EnableWindow( m_iIDRemoveButton, iSelCountChoosen > 0 ? bIsCur : FALSE);
    EnableWindow( m_iIDRemoveAllButton, iCountChoosen > 0 ? bIsCur : FALSE);

    // Determine whether or not the up and down buttons should be enabled or
    // disabled based on what is selected and where it is in the list.
    if(0 < iSelCountChoosen)
    {
        int     iSelFirst = -1, iSelLast = -1;

        // Loop through all of the items in the list.
        for(int iIndex = 0; iIndex < iCountChoosen; ++iIndex)
        {
            // Check if this item is selected.
            if( 0 < m_ctrlChoosenList.GetSel( iIndex ) )
            {
                if(-1 == iSelFirst)
                {
                    iSelFirst = iIndex;
                }
                iSelLast = iIndex;
            }
        }

        // Up is disabled if all of the selected items are at the top of the listbox
        bEnableMoveUp   = (iSelFirst == 0 &&  (iSelLast - iSelFirst + 1) == iSelCountChoosen)
                          ? FALSE: TRUE;

        // Down is disabled if all of the selected items are at the bottom of the listbox
        bEnableMoveDown = (iSelLast == iCountChoosen - 1  &&  (iSelLast - iSelFirst + 1) == iSelCountChoosen)
                          ? FALSE: TRUE;
    }

    // Enable/disable the up and down buttons
    EnableWindow(m_iIDMoveUpButton, bEnableMoveUp);
    EnableWindow(m_iIDMoveDownButton, bEnableMoveDown);
}

///////////////////////////////////////////////////////////////////////////////
//
//  Method:			EnableWindow
//
//  Purpose:		Enables/disables a control based on the contents and 
//                  selection state of the listboxes. Advances the focus to the
//                  next control if the control being disabled has the focus.
//
//  Inputs:
//
//		int iIDControl
//
//		BOOL bEnable
//
//  Outputs:
//
//		None
//
//  Return value:
//
//		void 
//
//  Exceptions:		None
//
///////////////////////////////////////////////////////////////////////////////
void CDualListManager::EnableWindow(int iIDControl, BOOL bEnable)
{
    // If we are about to disable a control and it is the control that currently
    // has the focus advance the focus to the next control before disabling it.
    CWnd * pWnd = m_pWndParent->GetFocus();
    if(NULL != pWnd)
    {
        if( FALSE == bEnable && m_pWndParent->GetFocus()->GetDlgCtrlID() == iIDControl)
        {
            // Use SendMessage instead of call NextDlgCtrl() which would force
            // us to cast the rWndParent. Since we don't know if it is a CDialog,
            // CView, CProperyPage etc. calling SendMessage is the way to go.
            m_pWndParent->SendMessage(WM_NEXTDLGCTL, 0, 0L);
        }
    }

    // Now disable the control whose id was passed in if it is a valid window.
    // It may not be if this class was constructed with a NULL ID for a given
    // control
    pWnd = m_pWndParent->GetDlgItem(iIDControl);
    if(NULL != pWnd)
    {
        pWnd->EnableWindow( bEnable );
    }
}

///////////////////////////////////////////////////////////////////////////////
//
//  Method:			SelectLBItem
//
//  Purpose:		Checks to see if the listbox is a single or multi select
//                  listbox and calls the appropriate selection method on the
//                  CListBox class.
//
//  Inputs:
//
//		CListBox & rListBox
//
//		int iItem
//
//  Outputs:
//
//		None
//
//  Return value:
//
//		void 
//
//  Exceptions:		None
//
///////////////////////////////////////////////////////////////////////////////
void CDualListManager::SelectLBItem(CListBox & rListBox, int iItem)
{
    if(rListBox.GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL))
    {
        rListBox.SetSel(iItem);
    }
    else
    {
        rListBox.SetCurSel(iItem);
    }
}

///////////////////////////////////////////////////////////////////////////////
//
//  Method:			ProcessCmdMsg
//
//  Purpose:		Should be called from the parents OnCmdMsg(...) method.
//                  Processes the windows commands associated with the buttons
//                  and listbox controls. Normally this would happen in the 
//                  message map but since the ids of the controls are passed
//                  into this class the message map cannot be used.
//                  
//                  The parent can also process the message if it wants or it
//                  can check the return code and bypass the message if it was
//                  handled by this method.
//
//  Inputs:
//
//		int nID - id of the control the message is associated with
//
//		int nCode - message value
//
//  Outputs:
//
//		None
//
//  Return value:
//
//		BOOL 
//
//  Exceptions:		None
//
///////////////////////////////////////////////////////////////////////////////
BOOL CDualListManager::ProcessCmdMsg(int nID, int nCode) 
{
    BOOL bProcessed = TRUE;

    // Add - button handler
    if(nID == m_iIDAddButton)
        MoveSelected(m_ctrlAvailableList, m_ArrayAvailable, m_ArrayChoosen, FALSE);
    // Add All - button handler
    else if(nID == m_iIDAddAllButton)
        MoveAll(m_ctrlAvailableList, m_ctrlChoosenList, m_ArrayAvailable, m_ArrayChoosen);
    // Remove - button handler
    else if(nID == m_iIDRemoveButton)
        MoveSelected(m_ctrlChoosenList, m_ArrayChoosen, m_ArrayAvailable, TRUE);
    // Remove All - button handler
    else if(nID == m_iIDRemoveAllButton)
        MoveAll(m_ctrlChoosenList, m_ctrlAvailableList, m_ArrayChoosen, m_ArrayAvailable);
    // Move Down - button handler
    else if(nID == m_iIDMoveDownButton)
        MoveUpOrDown(FALSE);
    // Move Up - button handler
    else if(nID == m_iIDMoveUpButton)
        MoveUpOrDown(TRUE);
    // Double Click on an item in the from list - handler
	else if(nID == m_iIDAvailableList && nCode == LBN_DBLCLK)
        MoveSelected(m_ctrlAvailableList, m_ArrayAvailable, m_ArrayChoosen, FALSE);
    // Double Click on an item in the to list - handler
	else if(nID == m_iIDChoosenList && nCode == LBN_DBLCLK)
        MoveSelected(m_ctrlChoosenList, m_ArrayChoosen, m_ArrayAvailable, TRUE);
    // Selection changed in the from list - handler
	else if(nID == m_iIDAvailableList && nCode == LBN_SELCHANGE)
        EnableButtons(m_bIsCur);
    // Selection changed in the to list - handler
	else if(nID == m_iIDChoosenList && nCode == LBN_SELCHANGE)
        EnableButtons(m_bIsCur);
    // All other messages are sent to the base class.
    else
        bProcessed = FALSE;

    // If we processed the message then update the buttons to reflect any 
    // changes we made.
    if(TRUE == bProcessed)
    {
        EnableButtons(m_bIsCur);
    }
	
    return bProcessed;
}

/////////////////////////////////////////////////////////////////////////////
// CDualListManager dialog


//CDualListDialog::CDualListDialog(CWnd* pParent /*=NULL*/)
/*	: CDialog(CDualListDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDualListManager)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDualListDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDualListManager)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDualListDialog, CDialog)
	//{{AFX_MSG_MAP(CDualListManager)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
*/
/////////////////////////////////////////////////////////////////////////////
// CDualListManager message handlers


void CDualListManager::GetChoosenItem(CAttendanceDlg *pDlg)
{
    int iCount = m_ArrayChoosen.GetSize();
	pDlg->m_iHoliday=iCount;
	pDlg->m_ArrayHoliday.SetSize(iCount);
    for(int iIndex = 0; iIndex < iCount; ++iIndex)
    {
		long l=m_ArrayChoosen[iIndex];
		pDlg->m_ArrayHoliday[iIndex] = m_ArrayChoosen[iIndex]+1;
		l=pDlg->m_ArrayHoliday[iIndex];
/*		CString csName;
        m_KeyMap.Lookup(m_ArrayChoosen[iIndex], csName);
        iIndex2 = m_ctrlChoosenList.AddString(csName);
        m_ctrlChoosenList.SetItemData(iIndex2, m_ArrayChoosen[iIndex]);
*/  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -