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

📄 acdsmpl.c

📁 TAPI ACD Samples
💻 C
📖 第 1 页 / 共 5 页
字号:
//////////////////////////////////////////////////////////////////////////////
//
//  ACDSMPL.C
//
//  Handles all the UI for ACDSample
//
//////////////////////////////////////////////////////////////////////////////

#include <windows.h>
#include <commctrl.h>
#include <commdlg.h>
#include <tapi.h>
#include <stdlib.h>
#include "resource.h"
#include "acdsmpl.h"


//////////////////////////////////////////////////////////////////////////////
//  PROTOTYPES
//////////////////////////////////////////////////////////////////////////////
static BOOL CreateMainWindow (int nCmdShow);

static LRESULT CALLBACK MainDlgProc (HWND   hwnd,
                                     UINT   uMsg,
                                     WPARAM wParam,
                                     LPARAM lParam);
void MySetWindow(HWND, int);
void MySaveWindow(HWND);
BOOL ResizeWindows(BOOL bSizeBar, DWORD dwBarLocation);
HTREEITEM AddItemToTree(HTREEITEM hParent,
                        LPTSTR lpszName,
                        LPARAM lParam,
                        HTREEITEM * phItem);
BOOL DoPopupMenu(HTREEITEM hItem, POINT pt);
BOOL DeleteLeafAndStruct(HTREEITEM hItem);
BOOL CALLBACK ChangeGroupDlgProc(HWND   hWnd,
                            UINT   uMsg,
                            WPARAM wParam,
                            LPARAM lParam);
BOOL CALLBACK ChangeAgentDlgProc(HWND   hWnd,
                            UINT   uMsg,
                            WPARAM wParam,
                            LPARAM lParam);
BOOL CALLBACK AddGroupDlgProc(HWND   hWnd,
                         UINT   uMsg,
                         WPARAM wParam,
                         LPARAM lParam);
BOOL CALLBACK AddAgentDlgProc(HWND   hWnd,
                         UINT   uMsg,
                         WPARAM wParam,
                         LPARAM lParam);
LRESULT DoCommand(WPARAM wParam, LPARAM lParam);
void AddGroupsToMenu(HTREEITEM hItem,
                     HMENU hMenu);
BOOL CALLBACK GroupAddToListProc(HWND   hWnd,
                            UINT   uMsg,
                            WPARAM wParam,
                            LPARAM lParam);
BOOL CALLBACK AgentAddToListProc(HWND   hWnd,
                            UINT   uMsg,
                            WPARAM wParam,
                            LPARAM lParam);
BOOL BuildLineList(HWND hWnd,
                   DWORD dwDeviceID);
BOOL BuildAddressList(HWND hWnd,
                      HWND hParentWnd,
                      DWORD dwDeviceID);
BOOL InitializeTapi();
BOOL CleanUp();
BOOL UpdateGroupLeaf(PGROUP pGroup);
BOOL DoAgentView();
BOOL DoGroupView();
BOOL ReadInFile();
BOOL WriteToDisk();



//////////////////////////////////////////////////////////////////////////////
//  GLOBALS
//////////////////////////////////////////////////////////////////////////////
ACDGLOBALS      g;

TCHAR gszACDSampleKey[]     = TEXT("Software\\Microsoft\\ACDSample");
TCHAR gszPlacementValue[]   = TEXT("WindowPlacement");
TCHAR gszBarLocation[]      = TEXT("BarLocation");



//////////////////////////////////////////////////////////////////////////////
//
// WinMain()
//
//////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR     lpszCmdLine,
                    int       nCmdShow)
{
    MSG msg;

    // initialize global variables
    g.hInstance = hInstance;
    g.pAgents = NULL;
    g.pGroups = NULL;

    // init tapi stuff
    if (!InitializeTapi())
    {
        MessageBox(NULL,
                   TEXT("TAPI could not be initialized.\nVerify that")
                   TEXT("your machine has TAPI devices installed"),
                   TEXT("Cannot start ACDSMPL"),
                   MB_OK);
    }

    if (!CreateMainWindow(nCmdShow))
    {
        return 0;
    }

    // main message loop
    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (!IsDialogMessage(g.hMainWnd,
                             &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return 1;
}


/////////////////////////////////////////////////////////////////////////////
//
//  CreateMainWindow()
//
//////////////////////////////////////////////////////////////////////////////
BOOL CreateMainWindow (int nCmdShow)
{

    // InitCommonControls for TreeView control
    InitCommonControls();

    // Create the main window
    g.hMainWnd = CreateDialog(g.hInstance,
                             MAKEINTRESOURCE(IDD_MAINDLG),
                             NULL,
                             MainDlgProc);

    if (g.hMainWnd == NULL)
    {
        return FALSE;
    }

    // restore default location
    MySetWindow(g.hMainWnd, nCmdShow);
    
    // store global hwnds
    g.hTreeWnd = GetDlgItem(g.hMainWnd,
                            IDC_TREEWND);

    g.hLogWnd = GetDlgItem(g.hMainWnd,
                           IDC_EDITWND);

    if ((g.hTreeWnd == FALSE) || (g.hLogWnd == FALSE))
    {
        return FALSE;
    }

    ResizeWindows(FALSE, 0);

    return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
//
//  MainDlgProc()
//
//////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK MainDlgProc (HWND   hWnd,
                              UINT   uMsg,
                              WPARAM wParam,
                              LPARAM lParam)
{
    static BOOL     bButtonDown = FALSE;
    
    switch (uMsg)
    {
        case WM_INITDIALOG:
            return TRUE;

        case WM_COMMAND:
        {
            LRESULT lResult;
            
            lResult = DoCommand(wParam, lParam);
            return lResult;
        }

        // button and mousemove messages tracked to move
        // the bar between the treeview control and the
        // edit control
        case WM_LBUTTONDOWN:
        {
            bButtonDown = TRUE;
            SetCapture(hWnd);
            return 0;
        }

        case WM_LBUTTONUP:
        {
            bButtonDown = FALSE;
            ReleaseCapture();
            return 0;
        }

        case WM_MOUSEMOVE:
        {
            if (bButtonDown)
            {
                ResizeWindows(TRUE, (DWORD)LOWORD(lParam));
                return 1;
            }
            break;
        }

        case WM_SIZE:
        {
            ResizeWindows(FALSE, 0);
            return 1;
        }

        // catch right click in tree view to make
        // popup menu
        case WM_NOTIFY:
        {
            LPNMHDR     pnmhdr;
            POINT       pt;
            HTREEITEM   hItem;
            TV_HITTESTINFO  hittestinfo;
            RECT        rc;

            pnmhdr = (LPNMHDR)lParam;

            // make sure it's a right click and it's in the treeview
            if ((pnmhdr->code != NM_RCLICK) || (pnmhdr->hwndFrom != g.hTreeWnd))
            {
                break;
            }

            GetCursorPos(&pt);
            GetWindowRect(g.hTreeWnd,
                          &rc);
            
            hittestinfo.pt.x = pt.x - rc.left;
            hittestinfo.pt.y = pt.y - rc.top;

            // hittest to get the tree view item
            hItem = TreeView_HitTest(g.hTreeWnd,
                                     &hittestinfo);

            // only display a menu if the mouse is actually
            // over the item (TVHT_ONITEM)
            if (hItem == NULL || (!(hittestinfo.flags & TVHT_ONITEM)) )
            {
                return TRUE;
            }

            // select that item (right clicking will not select
            // by default
            TreeView_Select(g.hTreeWnd,
                            hItem,
                            TVGN_CARET);

            // create the menu
            DoPopupMenu(hItem, pt);

            return TRUE;
                           
            
        }
        
        case WM_CLOSE:

            // save the current window location
            WriteToDisk();
            CleanUp();
            MySaveWindow(hWnd);
            PostQuitMessage(0);
            return 1;

        default:
            break;
    }
    return 0;
}


////////////////////////////////////////////////////////////////////////////////
//
//  ResizeWindows - Handles resizing the two child windows of the
//      main window.  If bSizeBar is true, then the sizing is happening
//      because the user is moving the bar.  if bSizeBar is false, the sizing
//      is happening because of the WM_SIZE or something like that.
//
////////////////////////////////////////////////////////////////////////////////
BOOL ResizeWindows(BOOL bSizeBar, DWORD dwBarLocation)
{
    RECT            rc, rc2;
    int             x;

    // is the user moving the bar?
    if (!bSizeBar)
    {
        dwBarLocation = g.dwBarLocation;
    }

    GetClientRect(g.hMainWnd, &rc);

    // make sure the bar is in a OK location
    if (bSizeBar)
    {
        if ((LONG)dwBarLocation < GetSystemMetrics(SM_CXSCREEN)/WINDOWSCALEFACTOR)
            return FALSE;

        if ((LONG)(rc.right - dwBarLocation) < GetSystemMetrics(SM_CXSCREEN)/WINDOWSCALEFACTOR)
            return FALSE;
    }

    // save the bar location
    g.dwBarLocation = dwBarLocation;

    // get the size of the frame
    x = GetSystemMetrics(SM_CXFRAME);

    // move tree windows
    MoveWindow(g.hTreeWnd,
               0,
               0,
               dwBarLocation,
               rc.bottom,
               TRUE);

    // get the size of the window (in case move window failed
    GetClientRect(g.hTreeWnd, &rc2);

    // move the edit window with respect to the tree window
    MoveWindow(g.hLogWnd,
               rc2.right-rc2.left+x+SIZEBAR,
               0,
               rc.right-(rc2.right-rc2.left)-x-SIZEBAR,
               rc.bottom,
               TRUE);

    return TRUE;
}

//////////////////////////////////////////////////////////////////////////////
//
//  MySetWindow - reads in the window placement from registry
//  and sets the window and bar.
//
//////////////////////////////////////////////////////////////////////////////
void MySetWindow(HWND hWnd, int nCmdShow)
{
    WINDOWPLACEMENT     pwp;
    HKEY                hKey;
    DWORD               dwDataSize;
    DWORD               dwDataType;
    RECT                rc;

    pwp.length = sizeof(WINDOWPLACEMENT);

    // open the key and read in the WINDOWPLACEMENT structure
    RegOpenKeyEx(HKEY_CURRENT_USER,
                 gszACDSampleKey,
                 0,
                 KEY_ALL_ACCESS,
                 &hKey);

    dwDataSize = sizeof(pwp);
    
    if ( RegQueryValueEx(hKey,
                         gszPlacementValue,
                         0,
                         &dwDataType,
                         (LPBYTE)&pwp,
                         &dwDataSize) )
    {
        // if it fails, default
        ShowWindow(g.hMainWnd, nCmdShow);
        GetWindowRect(g.hMainWnd, &rc);
        g.dwBarLocation = (rc.right - rc.left) / 2;
    }
    else
    {
        // if it succeeds, set the window and bar
        dwDataSize = sizeof(DWORD);
        
        if (RegQueryValueEx(hKey,
                            gszBarLocation,
                            0,
                            &dwDataType,
                            (LPBYTE)&g.dwBarLocation,
                            &dwDataSize))
        {
            g.dwBarLocation = (pwp.rcNormalPosition.right - pwp.rcNormalPosition.left) / 2;

⌨️ 快捷键说明

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