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

📄 rebar.c

📁 Most code samples included on this CD were developed with Microsoft Visual C++ version 5.0 and the M
💻 C
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************

THIS CODE AND INFORMATION IS PROVIDED AS IS WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
PURPOSE.

Copyright(c)  1999  Microsoft Corporation.  All Rights Reserved.

MODULE: 
  Rebar.c

ABSTRACT: 
  This Windows CE application shows how to register the rebar and 
  toolbar control classes, create a rebar with a toolbar and a combo
  box in it, and move the rebar up or down.

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

#ifndef STRICT
#define STRICT
#endif

#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include "resource.h"
  
#define NUMIMAGES     4     // Number of buttons in the toolbar           
#define IMAGEWIDTH    16    // Width of the buttons in the toolbar  
#define IMAGEHEIGHT   16    // Height of the buttons in the toolbar 
#define BUTTONWIDTH   0     // Width of the button images in the toolbar
#define BUTTONHEIGHT  0     // Height of the button images in the toolbar

  
#define ID_REBAR      1000  // Identifier of the rebar control
#define ID_TOOLBAR    2000  // Identifier of the button control
#define ID_COMBOBOX   2001  // Identifier of the combo box control
#define TOP           0x00    
#define BOTTOM        0x01    

HINSTANCE g_hInst;          // Handle to the application instance
HWND g_hwndCB = NULL;       // Handle to the command bar
HWND g_hwndRB = NULL;       // Handle to the rebar
HWND g_hwndMain = NULL;     // Handle to the application main window

WORD g_wSide;               // Indicates the position of the rebar
TCHAR g_szTitle[80];        // Main window name 
TCHAR g_szClassName[80];    // Main window class name
    
HWND CreateRebar (HWND);
void MoveRebar (HWND hwnd, HWND hwndRB);
LRESULT HandleMenuPopup (HMENU);
LRESULT DoNotify (HWND, WPARAM, LPARAM);
LRESULT HandleCommand (HWND, WPARAM, LPARAM);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

// The TBBUTTON structure contains information about the toolbar 
// buttons.
TBBUTTON tbButton[] =
{
  {0, IDM_VIEW_TOP,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
  {1, IDM_VIEW_BOTTOM,  TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
  {0, 0,                TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0},
  {2, IDM_HELP_ABOUT,   TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
  {0, 0,                TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0},
  {3, IDM_FILE_EXIT,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
};

// The toolbar tips
TCHAR * szToolTips[] = 
{
  TEXT("Top"), 
  TEXT("Bottom"), 
  TEXT("About"), 
  TEXT("Exit")
};

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

FUNCTION: 
  InitApplication

PURPOSE:
  Initializes and registers a windows class.

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

  wndclass.style = CS_HREDRAW | CS_VREDRAW;
  wndclass.lpfnWndProc = (WNDPROC)WndProc;
  wndclass.cbClsExtra = 0;
  wndclass.cbWndExtra = 0;
  wndclass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_REBAR));
  wndclass.hInstance = hInstance;
  wndclass.hCursor = NULL;
  wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
  wndclass.lpszMenuName = NULL;
  wndclass.lpszClassName = g_szClassName;
  
  return RegisterClass (&wndclass);
}

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

FUNCTION: 
  InitInstance

PURPOSE: 
  Creates and displays the main window.

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

  g_hwndMain = CreateWindow (
                  g_szClassName,  // Registered class name          
                  g_szTitle,      // Application window name
                  WS_VISIBLE,     // Window style
                  0,              // Horizontal position of the window
                  0,              // Vertical position of the 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 (!g_hwndMain)
    return FALSE;

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


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

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;

  // Load the window and window class name strings.
  LoadString (hInstance, IDS_TITLE, g_szTitle, 
              sizeof (g_szTitle) / sizeof (TCHAR));

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

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

  if (!InitInstance (hInstance, nCmdShow))
    return 0;
  
  while (GetMessage (&msg, NULL, 0, 0))
  {
    TranslateMessage (&msg);
    DispatchMessage (&msg);
  }
  
  return msg.wParam;
}

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

FUNCTION: 
  WndProc

PURPOSE: 
  Processes messages sent to the main window.
                                          
***********************************************************************/
LRESULT CALLBACK WndProc (HWND hwnd, UINT uMsg, WPARAM wParam, 
                          LPARAM lParam)
{
  switch (uMsg)
   {
    case WM_CREATE:
      g_wSide = TOP;

      // Create the command bar and insert the menu.
      g_hwndCB = CommandBar_Create (g_hInst, hwnd, 1);
      CommandBar_InsertMenubar (g_hwndCB, g_hInst, IDR_REBAR, 0);

      // Add the close button (X) to the command bar.
      CommandBar_AddAdornments (g_hwndCB, 0, 0);

      // Create the rebar control.
      g_hwndRB = CreateRebar (hwnd);

      return 0;

    case WM_NOTIFY:
      return DoNotify (hwnd, wParam, lParam);
   
    case WM_INITMENUPOPUP:
      HandleMenuPopup ((HMENU) wParam);
      break;
   
    case WM_COMMAND:
      HandleCommand (hwnd, wParam, lParam);
      break;

    case WM_SIZE:
      MoveRebar (hwnd, g_hwndRB);
      return 0;

    case WM_CLOSE:
      CommandBar_Destroy (g_hwndCB);
      DestroyWindow (g_hwndRB);
      DestroyWindow (hwnd);
      return 0;
    
    case WM_DESTROY:
      PostQuitMessage (0);
      return 0;
   }
  return DefWindowProc (hwnd, uMsg, wParam, lParam);
}


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

FUNCTION: 
  AboutDialogProc

PURPOSE: 
  Processes messages sent to the About dialog box window.

***********************************************************************/
BOOL CALLBACK AboutDialogProc (
                         HWND hwndDlg,    // Handle to the dialog box
                         UINT uMsg,       // Message
                         WPARAM wParam,   // First message parameter
                         LPARAM lParam)   // Second message parameter
{
  switch (uMsg)
  {
    case WM_INITDIALOG:
      return TRUE;  

    case WM_COMMAND:
      switch (LOWORD (wParam))
      {
        case IDOK:
          EndDialog (hwndDlg, IDOK);
          return TRUE;

        case IDCANCEL:
          EndDialog (hwndDlg, IDCANCEL);
          return TRUE;
      }
      break;
  }
  return FALSE;
}

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

FUNCTION: 
  CreateRebar

PURPOSE: 
  Registers the rebar and toolbar control classes, and creates a rebar 
  with a toolbar and a combo box in it.

***********************************************************************/
HWND CreateRebar (HWND hwnd)
{
  HWND hwndRB = NULL,         // Handle to the rebar control
       hwndTB = NULL,         // Handle to the toolbar
       hwndCombo = NULL;      // Handle to the combobox control
  DWORD dwStyle;              // Window style used in CreateWindowEx
  int index;                  // Integer index
  RECT rect;                  // RECT structure
  TCHAR szString[64];         // Temperary string
  HICON hIcon;                // Handle to a icon
  REBARINFO rbi;              // Contains information that describes 
                              // rebar control characteristics
  HIMAGELIST himlRB;          // Handle to an image list
  REBARBANDINFO rbbi[2];      // Contains information that defines bands
                              // in the rebar control
  INITCOMMONCONTROLSEX iccex; // Carries information used to load the  
                              // rebar control classes

  // Initialize the INITCOMMONCONTROLSEX structure.   
  iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);

  // Load rebar and toolbar control classes.  
  iccex.dwICC = ICC_COOL_CLASSES | ICC_BAR_CLASSES;

  // Register rebar and toolbar control classes from the common control 
  // dynamic-link library (DLL). 
  InitCommonControlsEx (&iccex);

⌨️ 快捷键说明

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