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

📄 cmdbarband.cpp

📁 《Windows CE 6.0开发者参考》(《Programming Windows Embedded CE 6.0 Developer Reference》)第四版书中的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//----------------------------------------------------------------------
// DoDestroyMain - Process WM_DESTROY message for window.
//
LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam,
                       LPARAM lParam) {
    PostQuitMessage (0);
    return 0;

}
//======================================================================
// Command handler routines
//----------------------------------------------------------------------
// DoMainCommandVCmdBar - Process View | Command bar command.
//
LPARAM DoMainCommandVCmdBar (HWND hWnd, WORD idItem, HWND hwndCtl,
                             WORD wNotifyCode) {

    HWND hwndCB = GetDlgItem (hWnd, IDC_CMDBAND);
    if (hwndCB)
        DestroyCommandBand (hWnd);
    else
        return 0;

	CreateCommandBar (hWnd);
    InvalidateRect (hWnd, NULL, TRUE);
    return 0;
}
//----------------------------------------------------------------------
// DoMainCommandVCmdBand - Process View | Command band command.
//
LPARAM DoMainCommandVCmdBand (HWND hWnd, WORD idItem, HWND hwndCtl,
                              WORD wNotifyCode) {

    HWND hwndCB = GetDlgItem (hWnd, IDC_CMDBAR);
    if (hwndCB)
        CommandBar_Destroy (hwndCB);
    else
        return 0;

    CreateCommandBand (hWnd, fFirstBar);
	fFirstBar = FALSE;
    InvalidateRect (hWnd, NULL, TRUE);
    return 0;
}
//----------------------------------------------------------------------
// DoMainCommandExit - Process Program Exit command.
//
LPARAM DoMainCommandExit (HWND hWnd, WORD idItem, HWND hwndCtl,
                          WORD wNotifyCode) {

    SendMessage (hWnd, WM_CLOSE, 0, 0);
    return 0;
}
//----------------------------------------------------------------------
// CreateCommandBar - Create a command bar control.
//
int CreateCommandBar (HWND hWnd) {
    INT i;
    TCHAR szTmp[64];

    // Create a command bar.
    HWND hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);

    // Insert a menu.
    CommandBar_InsertMenubar (hwndCB, hInst, ID_MENU, 0);

    // Insert buttons, first add a bitmap and then the buttons.
    CommandBar_AddBitmap (hwndCB, HINST_COMMCTRL, IDB_VIEW_SMALL_COLOR,
                          VIEW_BMPS, 0, 0);

    // Add buttons to the command bar.
    CommandBar_AddButtons (hwndCB, dim(tbCBViewBtns), tbCBViewBtns);

    // Add tooltips to the command bar.
    CommandBar_AddToolTips (hwndCB, dim(pViewTips), pViewTips);

    // Add a combo box between the view icons and the sort icons.
    CommandBar_InsertComboBox (hwndCB, hInst, 75,
                               CBS_DROPDOWNLIST | WS_VSCROLL,
                               IDC_COMBO, 6);
    // Fill in combo box.
    for (i = 0; i < 10; i++) {
        wsprintf (szTmp, TEXT ("Item %d"), i);
        SendDlgItemMessage (hwndCB, IDC_COMBO, CB_INSERTSTRING, -1,
                            (LPARAM)szTmp);
    }
    SendDlgItemMessage (hwndCB, IDC_COMBO, CB_SETCURSEL, 0, 0);

    // Add exit button to command bar.
    CommandBar_AddAdornments (hwndCB, 0, 0);

    InvalidateRect (hWnd, NULL, TRUE);
    return 0;
}

//----------------------------------------------------------------------
// CreateCommandBand - Create a formatted command band control.
//
int CreateCommandBand (HWND hWnd, BOOL fFirst) {
    HWND hwndCB, hwndBand, hwndChild;
    INT i, nBand, nBtnIndex, nEditIndex;
    LONG lStyle;
    HBITMAP hBmp;
    HIMAGELIST himl;
    REBARBANDINFO rbi[NUMBANDS];

    // Create image list control for bitmaps for minimized bands.
    himl = ImageList_Create (16, 16, ILC_COLOR, 3, 0);
    // Load first two images from one bitmap.
    hBmp = LoadBitmap (hInst, TEXT ("CmdBarBmps"));
    ImageList_Add (himl, hBmp, NULL);
    DeleteObject (hBmp);
    // Load third image as a single bitmap.
    hBmp = LoadBitmap (hInst, TEXT ("CmdBarEditBmp"));
    ImageList_Add (himl, hBmp, NULL);
    DeleteObject (hBmp);
    // Create a command band.
    hwndCB = CommandBands_Create (hInst, hWnd, IDC_CMDBAND,
                                  RBS_SMARTLABELS |
                                  RBS_AUTOSIZE | RBS_VARHEIGHT, himl);

    // Initialize common REBARBANDINFO structure fields.
    for (i = 0; i < dim(rbi); i++) {
        rbi[i].cbSize = sizeof (REBARBANDINFO);
        rbi[i].fMask = RBBIM_ID | RBBIM_IMAGE | RBBIM_SIZE |
                       RBBIM_STYLE;
        rbi[i].wID = IDB_CMDBAND+i;
    }

    // If first time, initialize the restore structure since it is
    // used to initialize the band size and style fields.
    if (fFirst) {
        nBtnIndex = 1;
        nEditIndex = 2;
        cbr[0].cxRestored = 130;
        cbr[1].cxRestored = 210;
        cbr[1].fStyle = RBBS_FIXEDBMP;
        cbr[2].cxRestored = 130;
        cbr[2].fStyle = RBBS_FIXEDBMP | RBBS_CHILDEDGE;
    } else {
        // If not first time, set order of bands depending on
        // the last order.
        if (nBandOrder[1] < nBandOrder[2]) {
            nBtnIndex = 1;
            nEditIndex = 2;
        } else {
            nBtnIndex = 2;
            nEditIndex = 1;
        }
    }
    // Initialize REBARBANDINFO structure for each band.
    // 1. Menu band
    rbi[0].fStyle = RBBS_FIXEDBMP | RBBS_NOGRIPPER;
    rbi[0].cx = cbr[0].cxRestored;
    rbi[0].iImage = 0;

    // 2. Standard button band
    rbi[nBtnIndex].fMask |= RBBIM_TEXT;
    rbi[nBtnIndex].iImage = 1;
    rbi[nBtnIndex].lpText = TEXT ("Std Btns");
    // The next two parameters are initialized from saved data.
    rbi[nBtnIndex].cx = cbr[1].cxRestored;
    rbi[nBtnIndex].fStyle = cbr[1].fStyle;

    // 3. Edit control band
    hwndChild = CreateWindow (TEXT ("edit"), TEXT ("edit ctl"),
                  WS_VISIBLE | WS_CHILD | ES_MULTILINE | WS_BORDER,
                  0, 0, 10, 5, hWnd, (HMENU)IDC_EDITCTL, hInst, NULL);

    rbi[nEditIndex].fMask |= RBBIM_TEXT | RBBIM_STYLE |
                             RBBIM_CHILDSIZE | RBBIM_CHILD;
    rbi[nEditIndex].hwndChild = hwndChild;
    rbi[nEditIndex].cxMinChild = 0;
    rbi[nEditIndex].cyMinChild = 23;
    rbi[nEditIndex].cyChild = 55;
    rbi[nEditIndex].iImage = 2;
    rbi[nEditIndex].lpText = TEXT ("Edit field");
    // The next two parameters are initialized from saved data.
    rbi[nEditIndex].cx = cbr[2].cxRestored;
    rbi[nEditIndex].fStyle = cbr[2].fStyle;

    // Add bands.
    CommandBands_AddBands (hwndCB, hInst, 3, rbi);

    // Add menu to first band.
    hwndBand = CommandBands_GetCommandBar (hwndCB, 0);
    CommandBar_InsertMenubar (hwndBand, hInst, ID_MENU, 0);
    // Add standard buttons to second band.
    hwndBand = CommandBands_GetCommandBar (hwndCB, nBtnIndex);
    // Insert buttons
    CommandBar_AddBitmap (hwndBand, HINST_COMMCTRL, IDB_STD_SMALL_COLOR,
                          16, 0, 0);
    CommandBar_AddButtons (hwndBand, dim(tbCBStdBtns), tbCBStdBtns);

    // Modify the style flags of each command bar to make transparent.
    for (i = 0; i < NUMBANDS; i++) {
        hwndBand = CommandBands_GetCommandBar (hwndCB, i);
        lStyle = SendMessage (hwndBand, TB_GETSTYLE, 0, 0);
        lStyle |= TBSTYLE_TRANSPARENT;
        SendMessage (hwndBand, TB_SETSTYLE, 0, lStyle);
    }

    // If not the first time the command band has been created, restore
    // the user's last configuration.
    if (!fFirst) {
        for (i = 0; i < NUMBANDS; i++) {
            if (cbr[i].fMaximized) {
                nBand = SendMessage (hwndCB, RB_IDTOINDEX,
                                     cbr[i].wID, 0);
                SendMessage (hwndCB, RB_MAXIMIZEBAND, nBand, TRUE);
            }
        }
    }
    // Add exit button to command band.
    CommandBands_AddAdornments (hwndCB, hInst, 0, NULL);
    return 0;
}
//----------------------------------------------------------------------
// DestroyCommandBand - Destroy command band control after saving
// the current configuration.
//
int DestroyCommandBand (HWND hWnd) {
    INT i, nBand, nMaxBand = 0;

    HWND hwndCB = GetDlgItem (hWnd, IDC_CMDBAND);
    for (i = 0; i < NUMBANDS; i++) {

        // Get band index from ID value.
        nBand = SendMessage (hwndCB, RB_IDTOINDEX, IDB_CMDBAND+i, 0);

        // Save the band number to save order of bands.
        nBandOrder[i] = nBand;

        // Get the restore information.
        cbr[i].cbSize = sizeof (COMMANDBANDSRESTOREINFO);
        CommandBands_GetRestoreInformation (hwndCB, nBand, &cbr[i]);
    }
    DestroyWindow (hwndCB);
    return 0;
}

⌨️ 快捷键说明

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