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

📄 listdlg.c

📁 上传的代码是WindowsCEProgramming第一版的源代码
💻 C
字号:
//======================================================================
// ListDlg - List box dialog window code
//
// Written for the book Programming Windows CE
// Copyright (C) 1998 Douglas Boling
//======================================================================
#include <windows.h>                 // For all that Windows stuff
#include <prsht.h>                   // Property sheet includes
#include "DlgDemo.h"                 // Program-specific stuff

extern HINSTANCE hInst;
//----------------------------------------------------------------------
// Global data
//
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},
};

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},
};

extern NOTELABELS nlPropPage[];
extern int nPropPageSize;
//======================================================================
// ListDlgProc - Button page dialog box procedure
//
BOOL CALLBACK ListDlgProc (HWND hWnd, UINT wMsg, WPARAM wParam,
                           LPARAM lParam) {
    TCHAR szOut[128];
    HWND hwndMain;
    INT i;

    switch (wMsg) {

        case WM_INITDIALOG:
            // The generic parameter contains the
            // top-level window handle.
            hwndMain = (HWND)((LPPROPSHEETPAGE)lParam)->lParam;
            // Save the window handle in the window structure.
            SetWindowLong (hWnd, DWL_USER, (LONG)hwndMain);

            // Fill the list and combo boxes.
            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);
            }
            // Provide default selection for the combo box.
            SendDlgItemMessage (hWnd, IDC_COMBOBOX, CB_SETCURSEL, 0, 0);
            return TRUE;
        //
        // Reflect WM_COMMAND messages to main window.
        //
        case WM_COMMAND:
            // Get the handle of the main window from the user word.
            hwndMain = (HWND) GetWindowLong (hWnd, DWL_USER);

            // Report the WM_COMMAND messages.
            lstrcpy (szOut, TEXT ("WM_COMMAND: "));
            if (LOWORD (wParam) == IDC_COMBOBOX) {
                for (i = 0; i < dim(nlCombo); i++) {
                    if (HIWORD (wParam) == nlCombo[i].wNotification) {
                        lstrcat (szOut, nlCombo[i].pszLabel);
                        break;
                    }
                }
                if (i == dim(nlCombo))
                    wsprintf (szOut,
                              TEXT ("WM_COMMAND notification: %x"),
                              HIWORD (wParam));
            } else {
                for (i = 0; i < dim(nlList); i++) {
                    if (HIWORD (wParam) == nlList[i].wNotification) {
                        lstrcat (szOut, nlList[i].pszLabel);
                        break;
                    }
                }
                if (i == dim(nlList))
                    wsprintf (szOut,
                              TEXT ("WM_COMMAND notification: %x"),
                              HIWORD (wParam));
            }
            SendMessage (hwndMain, MYMSG_ADDLINE,
                         MAKEWPARAM (LOWORD (wParam),ID_LISTPAGE),
                        (LPARAM)szOut);
            return TRUE;

        //
        // Reflect notify message.
        //
        case WM_NOTIFY:
            // Get the handle of the main window from the user word.
            hwndMain = (HWND) GetWindowLong (hWnd, DWL_USER);

            // Look up notify message.
            for (i = 0; i < nPropPageSize; i++) {
                if (((NMHDR *)lParam)->code ==
                                        nlPropPage[i].wNotification) {
                    lstrcpy (szOut, nlPropPage[i].pszLabel);
                    break;
                }
            }
            if (i == nPropPageSize)
                wsprintf (szOut, TEXT ("Notify code:%d"),
                          ((NMHDR *)lParam)->code);

            SendMessage (hwndMain, MYMSG_ADDLINE,
                         MAKEWPARAM (-1,ID_LISTPAGE),
                         (LPARAM)szOut);
            return FALSE;  // Return false to force default processing.
    }
    return FALSE;
}

⌨️ 快捷键说明

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