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

📄 cmdbarband.cpp

📁 《Windows CE 6.0开发者参考》(《Programming Windows Embedded CE 6.0 Developer Reference》)第四版书中的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//======================================================================
// CmdBarBand - Demonstration of CmdBar and CmdBand controls 
//
// Written for the book Programming Windows CE
// Copyright (C) 2007 Douglas Boling
//======================================================================
#include <windows.h>                 // For all that Windows stuff
#include <commctrl.h>                // Command bar/band includes
#include "CmdBarBand.h"              // Program-specific stuff

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

// Message dispatch table for MainWindowProc
const struct decodeUINT MainMessages[] = {
    WM_CREATE, DoCreateMain,
    WM_PAINT, DoPaintMain,
    WM_NOTIFY, DoNotifyMain,
    WM_COMMAND, DoCommandMain,
    WM_DESTROY, DoDestroyMain,
};
// Command message dispatch for MainWindowProc
const struct decodeCMD MainCommandItems[] = {
    IDM_VIEWCMDBAR, DoMainCommandVCmdBar,
    IDM_VIEWCMDBAND, DoMainCommandVCmdBand,
    IDM_EXIT, DoMainCommandExit,
};
// Command band button initialization structure
const TBBUTTON tbCBStdBtns[] = {
//  BitmapIndex      Command  State            Style    UserData  String
    {STD_FILENEW,    210,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,    0},
    {STD_FILEOPEN,   211,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,    0},
    {STD_FILESAVE,   212,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,    0},
    {0,              0,       TBSTATE_ENABLED, TBSTYLE_SEP,    0,    0},
    {STD_CUT,        213,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,    0},
    {STD_COPY,       214,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,    0},
    {STD_PASTE,      215,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,    0},
    {0,              0,       TBSTATE_ENABLED, TBSTYLE_SEP,    0,    0},
    {STD_PROPERTIES, 216,     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"),
};

// Array that stores the band configuration
COMMANDBANDSRESTOREINFO cbr[NUMBANDS];
INT nBandOrder[NUMBANDS];
//======================================================================
// Program entry point
//
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPWSTR lpCmdLine, int nCmdShow) {
    HWND hwndMain;
    MSG msg;

    // Initialize application.
    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);
}
//----------------------------------------------------------------------
// InitInstance - Instance initialization
//
HWND InitInstance (HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow){
    HWND hWnd;
    WNDCLASS wc;
    INITCOMMONCONTROLSEX icex;

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

#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
    // If Windows Mobile, allow only one instance of the application.
    hWnd = FindWindow (szAppName, NULL);
    if (hWnd) {
        SetForegroundWindow ((HWND)(((DWORD)hWnd) | 0x01));    
        return 0;
    }
#endif
    // 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 = LoadCursor (NULL, IDC_ARROW);// Default cursor
    wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
    wc.lpszMenuName =  NULL;                  // Menu name
    wc.lpszClassName = szAppName;             // Window class name

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

    // Load the command bar common control class.
    icex.dwSize = sizeof (INITCOMMONCONTROLSEX);
    icex.dwICC = ICC_WIN95_CLASSES | ICC_COOL_CLASSES;
    InitCommonControlsEx (&icex);

    // Create main window.
    hWnd = CreateWindow (szAppName, TEXT ("Band Demo"), WS_VISIBLE,    
                         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
                         CW_USEDEFAULT, NULL, NULL, hInstance, NULL); 
    // 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;
}
//----------------------------------------------------------------------
// 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);
}
//======================================================================
// Message handling procedures for MainWindow
//----------------------------------------------------------------------
// DoCreateMain - Process WM_CREATE message for window.
//
LRESULT DoCreateMain (HWND hWnd, UINT wMsg, WPARAM wParam,
                      LPARAM lParam) {
	// Create our initial command bar.
    CreateCommandBar (hWnd);
    return 0;
}
//----------------------------------------------------------------------
// DoPaintMain - Process WM_PAINT message for window.
//
LRESULT DoPaintMain (HWND hWnd, UINT wMsg, WPARAM wParam,
                     LPARAM lParam) {
    PAINTSTRUCT ps;
    HWND hwndCB;
    RECT rect;
    HDC hdc;

    // Adjust the size of the client rect to take into account
    // the command bar or command bands height.
    GetClientRect (hWnd, &rect);
    if (hwndCB = GetDlgItem (hWnd, IDC_CMDBAND))
        rect.top += CommandBands_Height (hwndCB);
    else
        rect.top += CommandBar_Height (GetDlgItem (hWnd, IDC_CMDBAR));

	// Draw an X in the client area to show viewable area
    hdc = BeginPaint (hWnd, &ps);
	MoveToEx (hdc, rect.left, rect.top, NULL);
	LineTo (hdc, rect.right, rect.bottom);
	MoveToEx (hdc, rect.left, rect.bottom, NULL);
	LineTo (hdc, rect.right, rect.top);
    EndPaint (hWnd, &ps);
    return 0;
}
//----------------------------------------------------------------------
// DoCommandMain - Process WM_COMMAND message for window.
//
LRESULT DoCommandMain (HWND hWnd, UINT wMsg, WPARAM wParam,
                       LPARAM lParam) {
    INT  i;
    // Parse the parameters.
    WORD idItem = (WORD) LOWORD (wParam);
    WORD wNotifyCode = (WORD) HIWORD (wParam);
    HWND hwndCtl = (HWND) lParam;

    // Call routine to handle control message.
    for (i = 0; i < dim(MainCommandItems); i++) {
        if (idItem == MainCommandItems[i].Code)
            return (*MainCommandItems[i].Fxn)(hWnd, idItem, hwndCtl,
                                              wNotifyCode);
    }
    return 0;
}
//----------------------------------------------------------------------
// DoNotifyMain - Process WM_NOTIFY message for window.
//
LRESULT DoNotifyMain (HWND hWnd, UINT wMsg, WPARAM wParam,
                      LPARAM lParam) {

    // Parse the parameters.
    LPNMHDR pnmh = (LPNMHDR)lParam;

    if (pnmh->code == RBN_HEIGHTCHANGE) {
        InvalidateRect (hWnd, NULL, TRUE);
    }
    return 0;
}

⌨️ 快捷键说明

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