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

📄 cmdbar.cpp

📁 Most code samples included on this CD were developed with Microsoft Visual C++ version 5.0 and the M
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      // Set the initial view.
      buttonview = STD;

      // Get the menu handle.
      hMenu=CommandBar_GetMenu (hwndCB, 0);

      // Set dPrevMenu to default.
      dPrevMenu= IDM_SHOW_STD;

      // Check the default menu item.
      CheckMenuItem (hMenu, IDM_SHOW_STD, MF_CHECKED);

      return 0;
  
    case WM_COMMAND:
      switch (GET_WM_COMMAND_ID (wp, lp))
      {
        case IDM_SHOW_STD:
          // If current buttonview is not STD, then change the 
          // command bar.
          if (buttonview != STD)
          {
            CommandBar_Destroy (hwndCB);
            hwndCB = CommandBar_Create (hInst, hwnd, 1);
            CommandBar_AddToolTips (hwndCB, uNumSmallTips, szSmallTips);
            CommandBar_AddBitmap (hwndCB, HINST_COMMCTRL, 
                                  IDB_STD_SMALL_COLOR, 15, 16, 16);
            CommandBar_InsertMenubar (hwndCB, hInst, IDM_MAIN_MENU, 0);
            CommandBar_AddButtons (
                              hwndCB, 
                              sizeof (tbSTDButton) / sizeof (TBBUTTON),
                              tbSTDButton);
            CommandBar_AddAdornments (hwndCB, WM_HELP | CMDBAR_OK, 0);
            SendMessage (hwnd, WM_PAINT, NULL, NULL);
            buttonview = STD;
            hMenu=CommandBar_GetMenu (hwndCB, 0);

            // Uncheck the previous menu item.
            CheckMenuItem (hMenu, dPrevMenu, MF_UNCHECKED);

            // Check the new menu item.
            CheckMenuItem (hMenu, IDM_SHOW_STD, MF_CHECKED);
          }
          return 0;

        case IDM_SHOW_VIEW:
          // If the current button view is not VIEW, then change 
          // command bar.
          if (buttonview != VIEW)
          {
            CommandBar_Destroy (hwndCB);
            hwndCB = CommandBar_Create (hInst, hwnd, 1);
            CommandBar_AddToolTips (hwndCB, uNumViewTips, szViewTips);
            CommandBar_AddBitmap (hwndCB, HINST_COMMCTRL, 
                                  IDB_VIEW_SMALL_COLOR, 12, 16, 16);
            CommandBar_InsertMenubar (hwndCB, hInst, IDM_MAIN_MENU, 0);
            CommandBar_AddButtons (
                              hwndCB, 
                              sizeof (tbVIEWButton) / sizeof (TBBUTTON),
                              tbVIEWButton);
            CommandBar_AddAdornments (hwndCB, WM_HELP | CMDBAR_OK, 0);
            SendMessage (hwnd, WM_PAINT, NULL, NULL);
            buttonview = VIEW;
            hMenu=CommandBar_GetMenu (hwndCB, 0);
            CheckMenuItem (hMenu, dPrevMenu, MF_UNCHECKED);
            CheckMenuItem (hMenu, IDM_SHOW_VIEW, MF_CHECKED);
          }
          return 0;

        case IDM_SHOW_MIX:
          // If the current button view is not MIX, then change the 
          // command bar.
          if (buttonview != MIX)
          {
            CommandBar_Destroy (hwndCB);
            hwndCB = CommandBar_Create (hInst, hwnd, 1);
            CommandBar_AddToolTips (hwndCB, uNumMixTips, szMIXTips);
            CommandBar_AddBitmap (hwndCB, HINST_COMMCTRL, 
                                  IDB_STD_SMALL_COLOR, 15, 16, 16);
            CommandBar_AddBitmap (hwndCB, HINST_COMMCTRL, 
                                  IDB_VIEW_SMALL_COLOR, 12, 16, 16);
            CommandBar_InsertMenubar (hwndCB, hInst, IDM_MAIN_MENU, 0);
            CommandBar_AddButtons (
                              hwndCB, 
                              sizeof (tbMIXButton) / sizeof (TBBUTTON), 
                              tbMIXButton);
            CommandBar_AddAdornments (hwndCB, WM_HELP | CMDBAR_OK, 0);
            SendMessage (hwnd, WM_PAINT, NULL, NULL);
            buttonview = MIX;
            hMenu=CommandBar_GetMenu (hwndCB, 0);
            CheckMenuItem (hMenu, dPrevMenu, MF_UNCHECKED);
            CheckMenuItem (hMenu, IDM_SHOW_MIX, MF_CHECKED);
          }
          return 0;

        case IDM_EXIT:
          SendMessage (hwnd, WM_CLOSE, 0, 0);
          return 0;
      }
      break;
  
    case WM_CLOSE:
      CommandBar_Destroy (hwndCB);
      DestroyWindow (hwnd);
      return 0;

    case WM_DESTROY:
      PostQuitMessage (0);
      return 0;
  }
  return DefWindowProc (hwnd, msg, wp, lp);
}


/***********************************************************************

FUNCTION: 
  InitInstance

PURPOSE: 
  Creates and displays the main window.

***********************************************************************/
BOOL InitInstance (HINSTANCE hInstance, int nCmdShow)
{
  hInst = hInstance;

  hwndMain = CreateWindow (
                  szClassName,    // Registered class name          
                  szTitle,        // Application window name
                  WS_VISIBLE,     // Window style
                  0,              // Horizontal position of window
                  0,              // Vertical position of window
                  CW_USEDEFAULT,  // Window width
                  CW_USEDEFAULT,  // Window height
                  NULL,           // Handle to the parent window
                  NULL,           // Handle to the menu identifier
                  hInstance,      // Handle to the application instance
                  NULL);          // Pointer to the window-creation data

  // If it failed to create the window, return FALSE.
  if (!hwndMain)
    return FALSE;

  ShowWindow (hwndMain, nCmdShow);
  UpdateWindow (hwndMain);
  return TRUE;
}


/***********************************************************************

FUNCTION: 
  InitApplication

PURPOSE: 
  Initializes and registers a windows class.

***********************************************************************/
BOOL InitApplication (HINSTANCE hInstance)
{
  WNDCLASS wc;

  LoadString (hInstance, IDS_CLASSNAME, szClassName, 
              sizeof (szClassName) / sizeof (TCHAR));

  LoadString (hInstance, IDS_TITLE, szTitle, 
              sizeof (szTitle) / sizeof (TCHAR));

  wc.style = CS_HREDRAW | CS_VREDRAW ;
  wc.lpfnWndProc = (WNDPROC)WndProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hIcon = NULL;
  wc.hInstance = hInstance;
  wc.hCursor = NULL;
  wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = szClassName;
  
  return RegisterClass (&wc);
}


/***********************************************************************

FUNCTION: 
  WinMain

PURPOSE: 
  Called by the system as the initial entry point for this Windows 
  CE-based application.

***********************************************************************/
int WINAPI WinMain (
            HINSTANCE hInstance,      // Handle to the current instance
            HINSTANCE hPrevInstance,  // Handle to the previous instance
            LPWSTR lpCmdLine,         // Pointer to the command line
            int nCmdShow)             // Show state of the window
{
  MSG msg;

  if (!hPrevInstance)
  {
    if (!InitApplication (hInstance))
      return FALSE; 
  }

  if (!InitInstance (hInstance, nCmdShow))
    return FALSE;

  while (GetMessage (&msg, NULL, 0, 0))
  {
    TranslateMessage (&msg);
    DispatchMessage (&msg);
  }

  return msg.wParam;
}
// END CMDBAR.CPP

⌨️ 快捷键说明

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