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

📄 acdsmpl.c

📁 TAPI ACD Samples
💻 C
📖 第 1 页 / 共 5 页
字号:
                        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
                        pGroup = (PGROUP)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)pGroup->lpszName);

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

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


                // bug idcancel doesn't cancel
                case IDOK:
                case IDCANCEL:
                {
                    EndDialog(hWnd, 1);
                    return 1;
                }

                default:
                    return 0;
            }
    }
    return 0;
}

//////////////////////////////////////////////////////////////
//
//  BOOL DeleteLeafAndStruct(HTREEITEM hItem)
//    delete hItem from the tree and deleted associated
//    structure
//
//////////////////////////////////////////////////////////////
BOOL DeleteLeafAndStruct(HTREEITEM hItem)
{
    TV_ITEM     tvi;

    // get the item
    tvi.mask = TVIF_PARAM;
    tvi.hItem = hItem;

    TreeView_GetItem(g.hTreeWnd,
                     &tvi);

    // delete the structure
    if (((PGENERICSTRUCT)tvi.lParam)->dwKey == GROUPKEY)
    {
        DeleteGroup((PGROUP)tvi.lParam);
    }
    else
    {
        DeleteAgent((PAGENT)tvi.lParam);
    }

    // remove it from the tree
    TreeView_DeleteItem(g.hTreeWnd,
                        hItem);

    return TRUE;
}


////////////////////////////////////////////////////////////////////
//
//  BOOL BuildLineList(HWND hWnd,
//                     DWORD dwDeviceID)
//
//  Fill in ComboBox with names of all available TAPI
//  devices
//
////////////////////////////////////////////////////////////////////
BOOL BuildLineList(HWND hWnd,
                   DWORD dwDeviceID)
{
    DWORD               dwDev;
    LPLINEDEVCAPS       pLineDevCaps;
    int                 item;
    BOOL                bSet = FALSE;

    // clear dropdown box
    SendMessage(hWnd,
                CB_RESETCONTENT,
                0,
                0);

    // loop through all devices
    for (dwDev = 0; dwDev < g.dwNumDevs; dwDev++)
    {
        pLineDevCaps = LineGetDevCaps(g.hLineApp,
                                      dwDev);

        // add the string to to list
        if (pLineDevCaps == NULL || pLineDevCaps->dwLineNameSize == 0)
        {
            item = SendMessage(hWnd,
                               CB_ADDSTRING,
                               0,
                               (LPARAM)TEXT("NoName"));
        }
        else
        {
            item = SendMessage(hWnd,
                               CB_ADDSTRING,
                               0,
                               (LPARAM)((LPTSTR)((LPBYTE)pLineDevCaps + pLineDevCaps->dwLineNameOffset)));
        }

        // save the device ID
        SendMessage(hWnd,
                    CB_SETITEMDATA,
                    item,
                    dwDev);

        // if this is the device we are looking for
        // set it to be selected
        if (dwDev == dwDeviceID)
        {
            SendMessage(hWnd,
                        CB_SETCURSEL,
                        (WPARAM)item,
                        0);

            bSet = TRUE;
        }
        
        if (pLineDevCaps != NULL)
        {
            ACDFree((HLOCAL)pLineDevCaps);
        }
    }

    // if we didn't set the selection, default
    if (!bSet)
    {
        SendMessage(hWnd,
                    CB_SETCURSEL,
                    0,
                    0);
    }

    return TRUE;
}


///////////////////////////////////////////////////////////////////////////////
//
//  BOOL BuildAddressList()
//
//  Fill combo box with list of addresses on selected device ID
//
///////////////////////////////////////////////////////////////////////////////
BOOL BuildAddressList(HWND hWnd,
                      HWND hParentWnd,
                      DWORD dwAddress)
{
    TCHAR               szBuffer[32];
    LPLINEDEVCAPS       pLineDevCaps;
    LPLINEADDRESSCAPS   pLineAddressCaps;
    DWORD               dwCurAddress, dwDeviceID;
    int                 iCurSel;

    // clear box
    SendMessage(hWnd,
                CB_RESETCONTENT,
                0,
                0);

    // get the current selected device
    iCurSel = SendDlgItemMessage(hParentWnd,
                                 IDC_LINECOMBO,
                                 CB_GETCURSEL,
                                 0,
                                 0);

    // get associated deviceid
    dwDeviceID = (DWORD)SendDlgItemMessage(hParentWnd,
                                           IDC_LINECOMBO,
                                           CB_GETITEMDATA,
                                           (WPARAM)iCurSel,
                                           0);
    
    pLineDevCaps = LineGetDevCaps(g.hLineApp,
                                  dwDeviceID);
    if (pLineDevCaps == NULL)
      return FALSE;

    // loop through all addresses
    for (dwCurAddress = 0; dwCurAddress < pLineDevCaps->dwNumAddresses; dwCurAddress++)
    {
        pLineAddressCaps = LineGetAddressCaps(g.hLineApp,
                                              dwDeviceID,
                                              dwCurAddress);

        // add name to list box
        if (pLineAddressCaps == NULL || pLineAddressCaps->dwAddressSize == 0)
        {
            wsprintf(szBuffer, TEXT("Address %d"), dwCurAddress);
            
            SendMessage(hWnd,
                        CB_ADDSTRING,
                        0,
                        (LPARAM)szBuffer);
        }
        else
        {
            SendMessage(hWnd,
                        CB_ADDSTRING,
                        0,
                        (LPARAM)((LPTSTR)((LPBYTE)pLineAddressCaps + pLineAddressCaps->dwAddressOffset)));
        }
        
        ACDFree((HLOCAL)pLineAddressCaps);
    }

    SendMessage(hWnd,
                CB_SETCURSEL,
                (WPARAM)dwAddress,
                0);

    ACDFree(pLineDevCaps);
    
    return TRUE;
}

///////////////////////////////////////////////////////////////////////////
//
//  BOOL UpdateGroupLeaf(PGROUP pStruct)
//
//  Updates a group in the tree view when a new agent is added to that
//  group
//
///////////////////////////////////////////////////////////////////////////
BOOL UpdateGroupLeaf(PGROUP pStruct)
{
    HTREEITEM   hItem;
    PLISTITEM   pItem;
    TV_ITEM     tvi;

    // get the item's first child
    hItem = TreeView_GetChild(g.hTreeWnd,
                              pStruct->hItem);

    
    while (hItem)
    {
        // delete all childre
        TreeView_DeleteItem(g.hTreeWnd,
                            hItem);
        hItem = TreeView_GetChild(g.hTreeWnd,
                                  pStruct->hItem);
    
    }

    pItem = pStruct->pAgentList;

    // walk the agent list
    while (pItem)
    {
        // add all the agents
        hItem = AddItemToTree(pStruct->hItem,
                              ((PAGENT)pItem->pAgent)->lpszName,
                              (LPARAM)NULL,
                              (HTREEITEM *)NULL);


        // if currently logged into that group
        /// bold that item
        if (pItem->bLoggedIn)
        {
            tvi.mask = TVIF_STATE | TVIF_HANDLE;
            tvi.hItem = hItem;
            tvi.state = TVIS_BOLD;
            tvi.stateMask = TVIS_BOLD;

            TreeView_SetItem(g.hTreeWnd,
                             &tvi);
        }
 
        pItem = pItem->pNext;
    }

    
    return TRUE;
}


///////////////////////////////////////////////////////////////////////
//
//  BOOL DoGroupView()
//
//  Display the tree in a "group view" (show groups, and under the
//  group, the agents that can log into that group)
//
///////////////////////////////////////////////////////////////////////
BOOL DoGroupView()
{
    PGROUP      pGroupParent, pGroup;
    TCHAR       szGroupParentName[] = TEXT("Groups");
    HTREEITEM   hItem;
    TV_ITEM     tvi;

    g.bGroupView = TRUE;

    // get the root
    hItem = TreeView_GetRoot(g.hTreeWnd);

    // free resources allocated for root
    if (hItem)
    {
        tvi.mask = TVIF_PARAM | TVIF_HANDLE;
        tvi.hItem = hItem;
        TreeView_GetItem(g.hTreeWnd,
                         &tvi);

        ACDFree((PAGENT)tvi.lParam);
    }

    // clear tree
    TreeView_DeleteAllItems(g.hTreeWnd);

    // alloc memory for the structure for the Group parent
    pGroupParent = (PGROUP)ACDAlloc(sizeof(GROUP));

    // alloc memory and copy the fixed name
    pGroupParent->lpszName = (LPTSTR)ACDAlloc((lstrlen(szGroupParentName) + 1) * sizeof(TCHAR));
    pGroupParent->dwKey = GROUPROOTKEY;
    
    lstrcpy(pGroupParent->lpszName, szGroupParentName);

    // add it to the tree
    g.hGroupParent = AddItemToTree(TVI_ROOT,
                                   pGroupParent->lpszName,
                                   (LPARAM)pGroupParent,
                                   &pGroupParent->hItem);

    pGroup = g.pGroups;

    // walk groups and add them to tree
    while (pGroup)
    {
        AddItemToTree(g.hGroupParent,
                      pGroup->lpszName,
                      (LPARAM)pGroup,
                      &pGroup->hItem);

        UpdateGroupLeaf(pGroup);

        pGroup = pGroup->p

⌨️ 快捷键说明

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