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

📄 cmdbar.c

📁 Programming Windows CE Windows CE程序设计书籍源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
//======================================================================
// CmdBar - Command bar demonstration
//
// Written for the book Programming Windows CE
// Copyright (C) 1998 Douglas Boling
//======================================================================
#include <windows.h>                 // For all that Windows stuff
#include <commctrl.h>                // Command bar includes
#include "CmdBar.h"                  // Program-specific stuff

//----------------------------------------------------------------------
// Global data
//
const TCHAR szAppName[] = TEXT ("CmdBar");
HINSTANCE hInst;                     // Program instance handle

// Message dispatch table for MainWindowProc
const struct decodeUINT MainMessages[] = {
    WM_CREATE, DoCreateMain,
    WM_COMMAND, DoCommandMain,
    WM_NOTIFY, DoNotifyMain,
    WM_DESTROY, DoDestroyMain,
};

// Command Message dispatch for MainWindowProc
const struct decodeCMD MainCommandItems[] = {
    IDM_EXIT, DoMainCommandExit,
    IDM_STDBAR, DoMainCommandVStd,
    IDM_VIEWBAR, DoMainCommandVView,
    IDM_COMBOBAR, DoMainCommandVCombo,
    IDM_ABOUT, DoMainCommandAbout,
};

// Standard file bar button structure
const TBBUTTON tbCBStdBtns[] = {
//  BitmapIndex       Command    State       Style       UserData String
    {0,               0,         0,          TBSTYLE_SEP,       0,   0},
    {STD_FILENEW,     IDC_NEW,   TBSTATE_ENABLED,
                                             TBSTYLE_BUTTON,    0,   0},
    {STD_FILEOPEN,    IDC_OPEN,  TBSTATE_ENABLED,
                                             TBSTYLE_BUTTON,    0,   0},
    {STD_FILESAVE,    IDC_SAVE,  TBSTATE_ENABLED,
                                             TBSTYLE_BUTTON,    0,   0},
    {0,                 0,       0,          TBSTYLE_SEP,       0,   0},
    {STD_CUT,         IDC_CUT,   TBSTATE_ENABLED,
                                             TBSTYLE_BUTTON,    0,   0},
    {STD_COPY,        IDC_COPY,  TBSTATE_ENABLED,
                                             TBSTYLE_BUTTON,    0,   0},
    {STD_PASTE,       IDC_PASTE, TBSTATE_ENABLED,
                                             TBSTYLE_BUTTON,    0,   0},
    {0,                 0,       0,          TBSTYLE_SEP,       0,   0},
    {STD_PROPERTIES,  IDC_PROP,  TBSTATE_ENABLED,
        TBSTYLE_BUTTON,    0,   0}
};

// Standard view bar button structure
const TBBUTTON tbCBViewBtns[] = {
//  BitmapIndex       Command    State       Style        UserData String
    {0,               0,         0,          TBSTYLE_SEP,        0,  0},
    {VIEW_LARGEICONS, IDC_LICON, TBSTATE_ENABLED | TBSTATE_CHECKED,
                                             TBSTYLE_CHECKGROUP, 0,  0},
    {VIEW_SMALLICONS, IDC_SICON, TBSTATE_ENABLED,
                                             TBSTYLE_CHECKGROUP, 0,  0},
    {VIEW_LIST,       IDC_LIST,  0,          TBSTYLE_CHECKGROUP, 0,  0},
    {VIEW_DETAILS,    IDC_RPT,   TBSTATE_ENABLED,
                                             TBSTYLE_CHECKGROUP, 0,  0},
    {0,               0,         TBSTATE_ENABLED,
                                             TBSTYLE_SEP,        0,  0},
    {VIEW_SORTNAME,   IDC_SNAME, TBSTATE_ENABLED | TBSTATE_CHECKED,
                                             TBSTYLE_CHECKGROUP, 0,  0},
    {VIEW_SORTTYPE,   IDC_STYPE, TBSTATE_ENABLED,
                                             TBSTYLE_CHECKGROUP, 0,  0},
    {VIEW_SORTSIZE,   IDC_SSIZE, TBSTATE_ENABLED,
                                             TBSTYLE_CHECKGROUP, 0,  0},
    {VIEW_SORTDATE,   IDC_SDATE, TBSTATE_ENABLED,
                                             TBSTYLE_CHECKGROUP, 0,  0},
    {0,               0,         0,          TBSTYLE_SEP,        0,  0},
};
// Tooltip string list for view bar
const TCHAR *pViewTips[] = {TEXT (""),
                            TEXT ("Large"),
                            TEXT ("Small"),
                            TEXT ("List"),
                            TEXT ("Details"),
                            TEXT (""),
                            TEXT ("Sort by Name"),
                            TEXT ("Sort by Type"),
                            TEXT ("Sort by Size"),
                            TEXT ("Sort by Date"),
};

// Combination standard and view bar button structure
const TBBUTTON tbCBCmboBtns[] = {
//  BitmapIndex       Command    State       Style        UserData String
    {0,               0,         0,          TBSTYLE_SEP,        0,  0},
    {STD_FILENEW,     IDC_NEW,   TBSTATE_ENABLED,
                                             TBSTYLE_BUTTON,     0,  0},
    {STD_FILEOPEN,    IDC_OPEN,  TBSTATE_ENABLED,
                                             TBSTYLE_BUTTON,     0,  0},
    {STD_PROPERTIES,  IDC_PROP,  TBSTATE_ENABLED,
                                             TBSTYLE_BUTTON,     0,  0},
    {0,               0,         0,          TBSTYLE_SEP,        0,  0},
    {STD_CUT,         IDC_CUT,   TBSTATE_ENABLED,
                                             TBSTYLE_BUTTON,     0,  0},
    {STD_COPY,        IDC_COPY,  TBSTATE_ENABLED,
                                             TBSTYLE_BUTTON,     0,  0},
    {STD_PASTE,       IDC_PASTE, TBSTATE_ENABLED,
                                             TBSTYLE_BUTTON,     0,  0},
    {0,               0,         0,          TBSTYLE_SEP,        0,  0},
    {STD_BMPS + VIEW_LARGEICONS,
                      IDC_LICON, TBSTATE_ENABLED | TBSTATE_CHECKED,
                                             TBSTYLE_CHECKGROUP, 0,  0},
    {STD_BMPS + VIEW_SMALLICONS,
                      IDC_SICON, TBSTATE_ENABLED,
                                             TBSTYLE_CHECKGROUP, 0,  0},
    {STD_BMPS + VIEW_LIST,
                      IDC_LIST,  TBSTATE_ENABLED,
                                             TBSTYLE_CHECKGROUP, 0,  0},
    {STD_BMPS + VIEW_DETAILS,
                      IDC_RPT,   TBSTATE_ENABLED,
                                             TBSTYLE_CHECKGROUP, 0,  0},
    {0,               0,         0,          TBSTYLE_SEP,        0,  0},
    {STD_BMPS + VIEW_BMPS,
                      IDC_DPSORT,TBSTATE_ENABLED,
                                             TBSTYLE_DROPDOWN,   0,  0}
};

//======================================================================
// Program entry point
//
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPWSTR lpCmdLine, int nCmdShow) {
    HWND hwndMain;
    MSG msg;
    int rc = 0;

    // Initialize application.
    rc = InitApp (hInstance);
    if (rc) return rc;

    // Initialize this instance.
    hwndMain = InitInstance (hInstance, lpCmdLine, nCmdShow);
    if (hwndMain == 0)
        return 0x10;

    // Application message loop
    while (GetMessage (&msg, NULL, 0, 0)) {
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }
    // Instance cleanup
    return TermInstance (hInstance, msg.wParam);
}
//----------------------------------------------------------------------
// InitApp - Application initialization
//
int InitApp (HINSTANCE hInstance) {
    WNDCLASS wc;
    INITCOMMONCONTROLSEX icex;

    // Register application main window class.
    wc.style = 0;                             // Window style
    wc.lpfnWndProc = MainWndProc;             // 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 = NULL;                        // Default cursor
    wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
    wc.lpszMenuName =  NULL;                  // Menu name
    wc.lpszClassName = szAppName;             // Window class name

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

    // Load the command bar common control class.
    icex.dwSize = sizeof (INITCOMMONCONTROLSEX);
    icex.dwICC = ICC_BAR_CLASSES;
    InitCommonControlsEx (&icex);
    return 0;
}
//----------------------------------------------------------------------
// InitInstance - Instance initialization
//
HWND InitInstance (HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow){
    HWND hWnd;

    // Save program instance handle in global variable.
    hInst = hInstance;

    // Create main window.
    hWnd = CreateWindow (szAppName,            // Window class
                         TEXT ("CmdBar Demo"), // Window title
                         WS_VISIBLE,           // Style flags
                         CW_USEDEFAULT,        // x position
                         CW_USEDEFAULT,        // y position
                         CW_USEDEFAULT,        // Initial width
                         CW_USEDEFAULT,        // Initial height
                         NULL,                 // Parent
                         NULL,                 // Menu, must be null
                         hInstance,            // Application instance
                         NULL);                // Pointer to create
                                               // parameters
    // Return fail code if window not created.
    if (!IsWindow (hWnd)) return 0;

    // Standard show and update calls
    ShowWindow (hWnd, nCmdShow);
    UpdateWindow (hWnd);
    return hWnd;
}
//----------------------------------------------------------------------
// TermInstance - Program cleanup
//
int TermInstance (HINSTANCE hInstance, int nDefRC) {
    return nDefRC;
}
//======================================================================
// Message handling procedures for MainWindow
//----------------------------------------------------------------------
// MainWndProc - Callback function for application window
//
LRESULT CALLBACK MainWndProc (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(MainMessages); i++) {
        if (wMsg == MainMessages[i].Code)
            return (*MainMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
    }
    return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
//----------------------------------------------------------------------
// DoCreateMain - Process WM_CREATE message for window.
//
LRESULT DoCreateMain (HWND hWnd, UINT wMsg, WPARAM wParam,
                      LPARAM lParam) {
    HWND hwndCB;

    // Create a minimal command bar that only has a menu and an

⌨️ 快捷键说明

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