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

📄 acdsmpl.c

📁 TAPI ACD Samples
💻 C
📖 第 1 页 / 共 5 页
字号:
//////////////////////////////////////////////////////////////////////////////////////
//
//  AddToList() - Window proc for Add Agent To Group and Add Group To Agent
//    dialog box
//
//////////////////////////////////////////////////////////////////////////////////////
BOOL CALLBACK GroupAddToListProc(HWND   hWnd,
                                 UINT   uMsg,
                                 WPARAM wParam,
                                 LPARAM lParam)
{
    static PGROUP           pGroup;
    PAGENT                  pAgent;
    PLISTITEM               pList;
    TV_ITEM                 tvi;
    DWORD                   dwListBox;
    BOOL                    bFound;
    int                     item;
    TCHAR                   szBuffer[128];
    
    
    switch (uMsg)
    {
        case WM_INITDIALOG:

            // get the item in question
            tvi.mask    = TVIF_HANDLE | TVIF_PARAM;
            tvi.hItem   = g.hTreeItemWithMenu;

            TreeView_GetItem(g.hTreeWnd,
                             &tvi);

            pGroup = (PGROUP)tvi.lParam;

            // init lists
            if (pGroup)
            {
                // initialize text in dialog
                wsprintf(szBuffer, TEXT("Add To %s"), pGroup->lpszName);

                SetWindowText(hWnd,
                              TEXT("Add To Group"));

                SetDlgItemText(hWnd,
                               IDC_STATICNOTINLIST,
                               TEXT("Not in Group"));
                SetDlgItemText(hWnd,
                               IDC_STATICINLIST,
                               TEXT("Group Members"));

                pAgent = g.pAgents;

                // walk list and initialize list boxes
                while (pAgent)
                {
                    pList = pGroup->pAgentList;

                    bFound = FALSE;
                
                    while (pList)
                    {
                        if (pList->pAgent == pAgent)
                        {
                            bFound = TRUE;
                            break;
                        }

                        pList = pList->pNext;
                    }

                    // if it was found, it is already a member of
                    // the group
                    if (bFound)
                    {
                        dwListBox = IDC_LIST2;
                    }
                    else
                    {
                        dwListBox = IDC_LIST1;
                    }

                    // add to correct list box
                    item = SendDlgItemMessage(hWnd,
                                              dwListBox,
                                              LB_ADDSTRING,
                                              0,
                                              (LPARAM)pAgent->lpszName);

                    // set the item data to be the item so we can get back it.
                    if (item != LB_ERR)
                    {
                        SendDlgItemMessage(hWnd,
                                           dwListBox,
                                           LB_SETITEMDATA,
                                           (WPARAM)item,
                                           (LPARAM)pAgent);
                    }

                    pAgent = pAgent->pNext;
                }
            }

            
            
            return 1;

        case WM_COMMAND:

            switch (LOWORD(wParam))
            {
                case IDC_ADD:
                {
                    // get the item
                    item = SendDlgItemMessage(hWnd,
                                              IDC_LIST1,
                                              LB_GETCURSEL,
                                              0,
                                              0);

                    if (item == 0)
                    {
                        if (!SendDlgItemMessage(hWnd,
                                                IDC_LIST1,
                                                LB_GETSEL,
                                                (WPARAM)item,
                                                0))
                        {
                            item = -1;
                        }
                    }

                    if (item != -1)
                    {
                        // get the PAGENT associated with it
                        pAgent = (PAGENT)SendDlgItemMessage(hWnd,
                                                            IDC_LIST1,
                                                            LB_GETITEMDATA,
                                                            (WPARAM)item,
                                                            0);

                        // delete it from this listbox
                        SendDlgItemMessage(hWnd,
                                           IDC_LIST1,
                                           LB_DELETESTRING,
                                           (WPARAM)item,
                                           0);

                        // add it to this list box
                        item = SendDlgItemMessage(hWnd,
                                                  IDC_LIST2,
                                                  LB_ADDSTRING,
                                                  0,
                                                  (LPARAM)pAgent->lpszName);

                        // set the item data again
                        SendDlgItemMessage(hWnd,
                                           IDC_LIST2,
                                           LB_SETITEMDATA,
                                           item,
                                           (WPARAM)pAgent);

                        // add it to the group's list
                        InsertIntoGroupList(pGroup,
                                            pAgent);
                        
                        return 1;
                        
                    }
                }
                break;
                
                case IDC_REMOVE:
                {
                    // get the item
                    item = SendDlgItemMessage(hWnd,
                                              IDC_LIST2,
                                              LB_GETCURSEL,
                                              0,
                                              0);

                    if (item == 0)
                    {
                        if (!SendDlgItemMessage(hWnd,
                                                IDC_LIST2,
                                                LB_GETSEL,
                                                (WPARAM)item,
                                                0))
                        {
                            item = -1;
                        }
                    }

                    if (item != -1)
                    {
                        // get the struct associated with it
                        pAgent = (PAGENT)SendDlgItemMessage(hWnd,
                                                                IDC_LIST2,
                                                                LB_GETITEMDATA,
                                                                (WPARAM)item,
                                                                0);

                        // delete it from this list
                        SendDlgItemMessage(hWnd,
                                           IDC_LIST2,
                                           LB_DELETESTRING,
                                           (WPARAM)item,
                                           0);

                        // add it to this list
                        item = SendDlgItemMessage(hWnd,
                                                  IDC_LIST1,
                                                  LB_ADDSTRING,
                                                  0,
                                                  (LPARAM)pAgent->lpszName);

                        // set the item data
                        SendDlgItemMessage(hWnd,
                                           IDC_LIST1,
                                           LB_SETITEMDATA,
                                           item,
                                           (WPARAM)pAgent);

                        // remove it from the lists
                        RemoveFromGroupList(pGroup,
                                            pAgent);
                        
                        return 1;
                        
                    }
                    
                }
                break;


                // bug idcancel doesn't cancel
                case IDOK:
                case IDCANCEL:
                {
                    UpdateGroupLeaf(pGroup);

                    EndDialog(hWnd, 1);
                    return 1;
                }

                default:
                    return 0;

            }

    }

    return 0;
}


BOOL CALLBACK AgentAddToListProc(HWND   hWnd,
                                 UINT   uMsg,
                                 WPARAM wParam,
                                 LPARAM lParam)
{
    static PAGENT           pAgent;
    PGROUP                  pGroup;
    PLISTITEM               pList;
    TV_ITEM                 tvi;
    DWORD                   dwListBox;
    BOOL                    bFound;
    int                     item;
    TCHAR                   szBuffer[128];
    
    
    switch (uMsg)
    {
        case WM_INITDIALOG:

            // get the item in question
            tvi.mask    = TVIF_HANDLE | TVIF_PARAM;
            tvi.hItem   = g.hTreeItemWithMenu;

            TreeView_GetItem(g.hTreeWnd,
                             &tvi);

            pAgent = (PAGENT)tvi.lParam;

            // init lists
            if (pAgent)
            {
                // initialize text in dialog
                wsprintf(szBuffer, TEXT("Add To %s"), pAgent->lpszName);

                SetWindowText(hWnd,
                              TEXT("Add To Agent"));

                SetDlgItemText(hWnd,
                               IDC_STATICNOTINLIST,
                               TEXT("Not Member Of"));
                SetDlgItemText(hWnd,
                               IDC_STATICINLIST,
                               TEXT("Member Of"));

                pGroup = g.pGroups;

                // walk list and initialize list boxes
                while (pGroup)
                {
                    pList = pGroup->pAgentList;

                    bFound = FALSE;
                
                    while (pList)
                    {
                        if (pList->pAgent == pAgent)
                        {
                            bFound = TRUE;
                            break;
                        }

                        pList = pList->pNext;
                    }

                    // if it was found, it is already a member of
                    // the group
                    if (bFound)
                    {
                        dwListBox = IDC_LIST2;
                    }
                    else
                    {
                        dwListBox = IDC_LIST1;
                    }

                    // add to correct list box
                    item = SendDlgItemMessage(hWnd,
                                              dwListBox,
                                              LB_ADDSTRING,
                                              0,
                                              (LPARAM)pGroup->lpszName);

                    // set the item data to be the item so we can get back it.
                    if (item != LB_ERR)
                    {
                        SendDlgItemMessage(hWnd,
                                           dwListBox,
                                           LB_SETITEMDATA,
                                           (WPARAM)item,
                                           (LPARAM)pGroup);
                    }

                    pGroup = pGroup->pNext;
                }
            }

            
            
            return 1;

        case WM_COMMAND:

            switch (LOWORD(wParam))
            {
                case IDC_ADD:
                {
                    // get the item
                    item = SendDlgItemMessage(hWnd,
                                              IDC_LIST1,
                                              LB_GETCURSEL,
                                              0,
                                              0);

                    if (item == 0)
                    {
                        if (!SendDlgItemMessage(hWnd,
                                                IDC_LIST1,
                                                LB_GETSEL,
                                                (WPARAM)item,
                                                0))
                        {
                            item = -1;
                        }
                    }

                    if (item != -1)
                    {
                        // get the PGROUP associated with it
                        pGroup = (PGROUP)SendDlgItemMessage(hWnd,
                                                                IDC_LIST1,
                                                                LB_GETITEMDATA,
                                                                (WPARAM)item,
                                                                0);

                        // delete it from this listbox
                        SendDlgItemMessage(hWnd,
                                           IDC_LIST1,
                                           LB_DELETESTRING,
                                           (WPARAM)item,
                                           0);

                        // add it to this list box
                        item = SendDlgItemMessage(hWnd,
                                                  IDC_LIST2,
                                                  LB_ADDSTRING,
                                                  0,
                                                  (LPARAM)pGroup->lpszName);

                        // set the item data again
                        SendDlgItemMessage(hWnd,
                                           IDC_LIST2,
                                           LB_SETITEMDATA,
                                           item,
                                           (WPARAM)pGroup);

                        // add it to the item's list

⌨️ 快捷键说明

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