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

📄 menubar.cpp

📁 windows CE上的菜单栏示例程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:

    // Parse the parameters.
    idItem = (WORD) LOWORD (wParam);
    wNotifyCode = (WORD) HIWORD (wParam);
    hwndCtl = (HWND) lParam;

    Add2List (hWnd, TEXT ("WM_COMMAND id:%d code:%d"), idItem, 
              wNotifyCode);
    // 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) {
    PNMNEWMENU lpNewMenu;
    LPNMHDR lpnhr = (LPNMHDR)lParam;

    Add2List (hWnd, TEXT ("WM_NOTIFY id:%d event:%d"), lpnhr->idFrom, 
              lpnhr->code);
	// This code only works when compiling on a Pocket PC
#if defined(WIN32_PLATFORM_PSPC)    // See if new menu being displayed.
    if (lpnhr->code == NMN_GETAPPREGKEY) {
        lpNewMenu = (PNMNEWMENU) lParam;
        AppendMenu (lpNewMenu->hMenu, MF_ENABLED, IDM_MYNEWMENUITEM, 
                    TEXT("My own New menu item"));
        AppendMenu (lpNewMenu->hMenu, MF_SEPARATOR, 0, 0);
    // Permanent new menu item selected
    } else if (lpnhr->code == NMN_INVOKECOMMAND) {
        lpNewMenu = (PNMNEWMENU) lParam;
        // See if it is NewMenuX. 
        if (IsEqualIID (lpNewMenu->clsid, CLSID_NewMenuX)) {
            int rc = MessageBox (hWnd, 
                                 TEXT ("Do you want to launch Calc?"),
                                 szAppName, MB_YESNO);
            if (rc == IDYES)
                return 0;
            else
                return 1;
        }
    }
#endif
   return 0;
}
//----------------------------------------------------------------------
// DoSettingChangeMain - Process WM_SETTINGCHANGE message for window.
//
LRESULT DoSettingChangeMain (HWND hWnd, UINT wMsg, WPARAM wParam, 
                             LPARAM lParam) {

    // Notify shell of our WM_SETTINGCHANGE message.
    SHHandleWMSettingChange(hWnd, wParam, lParam, &sai);
    return 0;
}
//----------------------------------------------------------------------
// DoActivateMain - Process WM_ACTIVATE message for window.
//
LRESULT DoActivateMain (HWND hWnd, UINT wMsg, WPARAM wParam, 
                        LPARAM lParam) {

    // Notify shell of our activate message.
    SHHandleWMActivate(hWnd, wParam, lParam, &sai, 0);
    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;
}
//----------------------------------------------------------------------
// DoMainCommandAbout - Process Tools About command.
//
LPARAM DoMainCommandAbout (HWND hWnd, WORD idItem, HWND hwndCtl,
                           WORD wNotifyCode) {
    // Use DialogBox to create modal dialog.
    DialogBox (hInst, TEXT ("aboutbox"), hWnd, AboutDlgProc);
    return 0;
}
//----------------------------------------------------------------------
// DoMainCommandSimpleNew - Process Simple new menu command.
//
LPARAM DoMainCommandSimpleNew (HWND hWnd, WORD idItem, HWND hwndCtl,
                               WORD wNotifyCode) {
    if (IsWindow (hwndMenuBar))
        DestroyWindow (hwndMenuBar);

    // Create a menu bar.
    hwndMenuBar = MyCreateMenuBar (hWnd, ID_TOOLBAR1);
    MyCheckMenu (IDM_DOSIMPLENEW);
    return 0;
}
//----------------------------------------------------------------------
// DoMainCommandSharedNew - Process Shared new menu command.
//
LPARAM DoMainCommandSharedNew (HWND hWnd, WORD idItem, HWND hwndCtl,
                               WORD wNotifyCode) {
    // Delete the old menu bar.
    if (IsWindow (hwndMenuBar))
        DestroyWindow (hwndMenuBar);

    // Create the menu bar.
    hwndMenuBar = MyCreateMenuBar (hWnd, ID_TOOLBAR2);

    // Add the standard view bitmap.
    CommandBar_AddBitmap (hwndMenuBar, HINST_COMMCTRL, 
                          IDB_STD_SMALL_COLOR, STD_PRINT, 16, 16);
    MyCheckMenu (IDM_DOSHAREDNEW);          // Set menu checkmark.
    return 0;
}
//======================================================================
// About Dialog procedure
//
BOOL CALLBACK AboutDlgProc (HWND hWnd, UINT wMsg, WPARAM wParam,
                            LPARAM lParam) {
    switch (wMsg) {
        case WM_INITDIALOG:
        {
            SHINITDLGINFO idi;
            idi.dwMask = SHIDIM_FLAGS;
            idi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIZEDLGFULLSCREEN |
                          SHIDIF_SIPDOWN;
            idi.hDlg = hWnd;
            SHInitDialog (&idi);
        }
        break;
        case WM_COMMAND:
            switch (LOWORD (wParam)) {
                case IDOK:
                case IDCANCEL:
                    EndDialog (hWnd, 0);
                    return TRUE;
        }
        break;
    }
    return FALSE;
}
//----------------------------------------------------------------------
// MyCreateMenuBar - Creates a menu bar
//
HWND MyCreateMenuBar (HWND hWnd, int idToolbar) {
    SHMENUBARINFO mbi;

    // Create a menu bar.
    memset(&mbi, 0, sizeof(SHMENUBARINFO)); // Zero structure
    mbi.cbSize = sizeof(SHMENUBARINFO);     // Size field
    mbi.hwndParent = hWnd;                  // Parent window
    mbi.nToolBarId = idToolbar;             // ID of toolbar resource
    mbi.hInstRes = hInst;                   // Inst handle of app
    mbi.nBmpId = ID_TOOLBMPS;               // ID of bitmap resource
    mbi.cBmpImages = 3;                     // Num of images in bitmap 

    SHCreateMenuBar(&mbi);
    return mbi.hwndMB;                      // Return the menu bar handle.
}
//----------------------------------------------------------------------
// MyCheckMenu - Places a check next to a menu item
//
void MyCheckMenu (int idMenu) {
    HMENU hSubMenu;

    // The handle for the view menu
    hSubMenu = (HMENU)SendMessage (hwndMenuBar, SHCMBM_GETMENU, 0, 0);
    if (idMenu == IDM_DOSIMPLENEW) {
        CheckMenuItem (hSubMenu, IDM_DOSIMPLENEW, MF_BYCOMMAND | 
                       MFS_CHECKED);
        CheckMenuItem (hSubMenu, IDM_DOSHAREDNEW, MF_BYCOMMAND | 
                       MFS_UNCHECKED);
    } else {
        CheckMenuItem (hSubMenu, IDM_DOSIMPLENEW, MF_BYCOMMAND | 
                       MFS_UNCHECKED);
        CheckMenuItem (hSubMenu, IDM_DOSHAREDNEW, MF_BYCOMMAND | 
                       MFS_CHECKED);
    }
    return;
}
//----------------------------------------------------------------------
// Add2List - Add string to the report list box. 
//
void Add2List (HWND hWnd, LPTSTR lpszFormat, ...) {
    int nBuf, i;
    TCHAR szBuffer[512];

    va_list args;
    va_start(args, lpszFormat);

    nBuf = _vstprintf(szBuffer, lpszFormat, args);

    i = SendDlgItemMessage (hWnd, IDC_RPTLIST, LB_ADDSTRING, 0, 
                            (LPARAM)(LPCTSTR)szBuffer);

    if (i != LB_ERR)
        SendDlgItemMessage (hWnd, IDC_RPTLIST, LB_SETTOPINDEX, i, 
                            (LPARAM)(LPCTSTR)szBuffer);
    va_end(args);
}

⌨️ 快捷键说明

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