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

📄 listwnd.cpp

📁 Programming.Microsoft.Windows.CE.Dot.NET.3rd.Edition.pdf the chapter 4 example codes.
💻 CPP
字号:
//======================================================================
// ListWnd - List box control window code
//
// Written for the book Programming Windows CE
// Copyright (C) 2003 Douglas Boling
//======================================================================
#include <windows.h>                 // For all that Windows stuff
#include "Ctlview.h"                 // Program-specific stuff

extern HINSTANCE hInst;
//----------------------------------------------------------------------
// Global data
//
// Message dispatch table for ListWndWindowProc
const struct decodeUINT ListWndMessages[] = {
    WM_CREATE, DoCreateListWnd,
    WM_COMMAND, DoCommandListWnd,
};

// Structure defining the controls in the window
CTLWNDSTRUCT  Lists[] = {
    {TEXT ("combobox"), IDC_COMBOBOX, TEXT (""), 10,  10, 205, 100,
     WS_VSCROLL},

    {TEXT ("Listbox"), IDC_SNGLELIST, TEXT (""),   10,  35, 100, 90,
     WS_VSCROLL | LBS_NOTIFY},

    {TEXT ("Listbox"), IDC_MULTILIST, TEXT (""), 115,  35, 100, 90,
     WS_VSCROLL | LBS_EXTENDEDSEL | LBS_NOTIFY}
};
// Structure labeling the list box control WM_COMMAND notifications
NOTELABELS nlList[] = {{TEXT ("LBN_ERRSPACE "), (-2)},
                       {TEXT ("LBN_SELCHANGE"), 1},
                       {TEXT ("LBN_DBLCLK   "), 2},
                       {TEXT ("LBN_SELCANCEL"), 3},
                       {TEXT ("LBN_SETFOCUS "), 4},
                       {TEXT ("LBN_KILLFOCUS"), 5},
};
// Structure labeling the combo box control WM_COMMAND notifications
NOTELABELS nlCombo[] = {{TEXT ("CBN_ERRSPACE    "), (-1)},
                        {TEXT ("CBN_SELCHANGE   "), 1},
                        {TEXT ("CBN_DBLCLK      "), 2},
                        {TEXT ("CBN_SETFOCUS    "), 3},
                        {TEXT ("CBN_KILLFOCUS   "), 4},
                        {TEXT ("CBN_EDITCHANGE  "), 5},
                        {TEXT ("CBN_EDITUPDATE  "), 6},
                        {TEXT ("CBN_DROPDOWN    "), 7},
                        {TEXT ("CBN_CLOSEUP     "), 8},
                        {TEXT ("CBN_SELENDOK    "), 9},
                        {TEXT ("CBN_SELENDCANCEL"), 10},
};
//----------------------------------------------------------------------
// InitListWnd - ListWnd window initialization
//
int InitListWnd (HINSTANCE hInstance) {
    WNDCLASS wc;

    // Register application ListWnd window class.
    wc.style = 0;                             // Window style
    wc.lpfnWndProc = ListWndProc;             // Callback function
    wc.cbClsExtra = 0;                        // Extra class data
    wc.cbWndExtra = 0;                        // Extra window data
    wc.hInstance = hInstance;                 // Owner handle
    wc.hIcon = NULL,                          // Application icon
    wc.hCursor = LoadCursor (NULL, IDC_ARROW); // Default cursor
    wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
    wc.lpszMenuName =  NULL;                  // Menu name
    wc.lpszClassName = LISTWND;               // Window class name

    if (RegisterClass (&wc) == 0) return 1;

    return 0;
}
//======================================================================
// Message handling procedures for ListWindow
//----------------------------------------------------------------------
// ListWndProc - Callback function for application window
//
LRESULT CALLBACK ListWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,
                              LPARAM lParam) {
    int i;
    //
    // Search message list to see if we need to handle this
    // message.  If in list, call procedure.
    //
    for (i = 0; i < dim(ListWndMessages); i++) {
        if (wMsg == ListWndMessages[i].Code)
            return (*ListWndMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
    }
    return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
//----------------------------------------------------------------------
// DoCreateListWnd - Process WM_CREATE message for window.
//
LRESULT DoCreateListWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
                         LPARAM lParam) {
    int i;
    TCHAR szOut[64];
    for (i = 0; i < dim(Lists); i++) {

        CreateWindow (Lists[i].szClass, Lists[i].szTitle,
                      Lists[i].lStyle | WS_VISIBLE | WS_CHILD | WS_BORDER,
                      Lists[i].x, Lists[i].y, Lists[i].cx, Lists[i].cy,
                      hWnd, (HMENU) Lists[i].nID, hInst, NULL);
    }
    for (i = 0; i < 20; i++) {
        wsprintf (szOut, TEXT ("Item %d"), i);
        SendDlgItemMessage (hWnd, IDC_SNGLELIST, LB_ADDSTRING, 0,
                            (LPARAM)szOut);

        SendDlgItemMessage (hWnd, IDC_MULTILIST, LB_ADDSTRING, 0,
                            (LPARAM)szOut);

        SendDlgItemMessage (hWnd, IDC_COMBOBOX, CB_ADDSTRING, 0,
                            (LPARAM)szOut);
    }
    // Set initial selection.
    SendDlgItemMessage (hWnd, IDC_COMBOBOX, CB_SETCURSEL, 0, 0);
    return 0;
}
//----------------------------------------------------------------------
// DoCommandListWnd - Process WM_COMMAND message for window.
//
LRESULT DoCommandListWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
                          LPARAM lParam) {
    TCHAR szOut[128];
    int i;

    if (LOWORD (wParam) == IDC_COMBOBOX) {
        for (i = 0; i < dim(nlCombo); i++) {
            if (HIWORD (wParam) == nlCombo[i].wNotification) {
                lstrcpy (szOut, nlCombo[i].pszLabel);
                break;
            }
        }
        if (i == dim(nlList))
            wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
    } else {
        for (i = 0; i < dim(nlList); i++) {
            if (HIWORD (wParam) == nlList[i].wNotification) {
                lstrcpy (szOut, nlList[i].pszLabel);
                break;
            }
        }
        if (i == dim(nlList))
            wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
    }
    SendMessage (GetParent (hWnd), MYMSG_ADDLINE, wParam,
                 (LPARAM)szOut);
    return 0;
}

⌨️ 快捷键说明

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