[翻译]-Windows CE 程序设计 (3rd 版)--5.2 公共控件(九) (续)

//LRESULT DoPaintMain (HWND hWnd, UINT wMsg, WPARAM wParam,                     LPARAM lParam) {    PAINTSTRUCT ps;    HWND hwndCB;    RECT rect;    HDC hdc;    POINT ptArray[2];       // 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));       hdc = BeginPaint (hWnd, &ps);    ptArray[0].x = rect.left;    ptArray[0].y = rect.top;    ptArray[1].x = rect.right;    ptArray[1].y = rect.bottom;    Polyline (hdc, ptArray, 2);       ptArray[0].x = rect.right;    ptArray[1].x = rect.left;    Polyline (hdc, ptArray, 2);       EndPaint (hWnd, &ps);    return 0;}//----------------------------------------------------------------------// DoCommandMain - Process WM_COMMAND message for window.//LRESULT DoCommandMain (HWND hWnd, UINT wMsg, WPARAM wParam,                       LPARAM lParam) {    WORD idItem, wNotifyCode;    HWND hwndCtl;    INT i;    // Parse the parameters.    idItem = (WORD) LOWORD (wParam);    wNotifyCode = (WORD) HIWORD (wParam);    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) {    LPNMHDR pnmh;       // Parse the parameters.    pnmh = (LPNMHDR)lParam;       if (pnmh->code == RBN_HEIGHTCHANGE) {        InvalidateRect (hWnd, NULL, TRUE);       }       return 0;}//----------------------------------------------------------------------// DoDestroyMain - Process WM_DESTROY message for window.//LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam,                       LPARAM lParam) {    PostQuitMessage (0);    return 0;   }//======================================================================// Command handler routines//----------------------------------------------------------------------// DoMainCommandExit - Process Program Exit command.//LPARAM DoMainCommandExit (HWND hWnd, WORD idItem, HWND hwndCtl,                          WORD wNotifyCode) {       SendMessage (hWnd, WM_CLOSE, 0, 0);    return 0;}//----------------------------------------------------------------------// DoMainCommandVCmdBarStd - Process View | Std Command bar command.//LPARAM DoMainCommandViewCmdBar (HWND hWnd, WORD idItem, HWND hwndCtl,                                WORD wNotifyCode) {    HWND hwndCB;       hwndCB = GetDlgItem (hWnd, IDC_CMDBAND);    if (hwndCB)        DestroyCommandBand (hWnd);    else        return 0;       // Create a minimal command bar that has only a menu and    // an exit button.    hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);       // Insert the menu.    CommandBar_InsertMenubar (hwndCB, hInst, ID_MENU, 0);    // Add exit button to command bar.    CommandBar_AddAdornments (hwndCB, 0, 0);    InvalidateRect (hWnd, NULL, TRUE);    return 0;}//----------------------------------------------------------------------// DoMainCommandVCmdBand - Process View | Command band command.//LPARAM DoMainCommandVCmdBand (HWND hWnd, WORD idItem, HWND hwndCtl,                              WORD wNotifyCode) {    HWND hwndCB;    hwndCB = GetDlgItem (hWnd, IDC_CMDBAR);    if (hwndCB)        CommandBar_Destroy (hwndCB);    else        return 0;       CreateCommandBand (hWnd, FALSE);    InvalidateRect (hWnd, NULL, TRUE);    return 0;}//----------------------------------------------------------------------// DoMainCommandAbout - Process the Help | About menu command.//LPARAM DoMainCommandAbout(HWND hWnd, WORD idItem, HWND hwndCtl,                          WORD wNotifyCode) {    // Use DialogBox to create modal dialog box.    DialogBox (hInst, TEXT ("aboutbox"), hWnd, AboutDlgProc);    return 0;}//======================================================================// About Dialog procedure//BOOL CALLBACK AboutDlgProc (HWND hWnd, UINT wMsg, WPARAM wParam,                            LPARAM lParam) {    switch (wMsg) {        case WM_COMMAND:            switch (LOWORD (wParam)) {                case IDOK:                case IDCANCEL:                    EndDialog (hWnd, 0);                    return TRUE;            }        break;    }       return FALSE;}//----------------------------------------------------------------------// DestroyCommandBand - Destroy command band control after saving// the current configuration.//int DestroyCommandBand (HWND hWnd) {    HWND hwndCB;    INT i, nBand, nMaxBand = 0;      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;}//----------------------------------------------------------------------// 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);       // Load bitmap used as background for command bar.    hBmp = LoadBitmap (hInst, TEXT ("CmdBarBack"));    // 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_BACKGROUND | RBBIM_STYLE;        rbi[i].wID = IDB_CMDBAND+i;        rbi[i].hbmBack = hBmp;    }       // 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;}CmdBand示例中,在CreateCommandBand例程里创建了命令带。该例程最初在DoCreateMain中被调用,随后又在菜单处理函数DoMain-CommandVCmdBand中被调用。程序使用RBS_SMARTLABELS风格创建了命令带控件,在最小化和被还原或最大化时使用图像列表和文本标签来标记每个带区。图像列表被创建,并使用位图初始化,当带区被最小化时需要使用这些位图。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值