分享
 
 
 

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

王朝system·作者佚名  2006-03-12
窄屏简体版  字體: |||超大  

命令条设计指导

因为命令条是Windows CE应用程序中的一个主要元素,所以微软对如何使用它们给出了一个相当强的规则集合。这些规则中有许多规则同其它版本的Windows是类似的,例如对主菜单项的顺序的建议和对工具条提示的使用等。大部分规则已经成为Windows程序员的第二天性了。

菜单应该是命令条上最左边的项。主菜单项按从左到右的顺序依次为:文件(File)、视图(View)、插入(Insert)、格式(Format)、工具(Tools)和窗口(Windows)。当然,大部分应用都具有这些菜单项,这些菜单项的顺序应该遵循建议的顺序。对按钮来说,按从左到右的顺序是:用于文件操作的有新建(New)、打开(Open)、保存(Save)和打印(Print);,用于字体风格的是粗体、斜体和下划线。

CmdBar示例程序

CmdBar示例演示了命令条的基本操作。在启动的时候,创建了一个只有菜单和关闭按钮的工具条。从[视图(view)]菜单里选择不同的项来创建不同的命令条,由此展示了命令条控件的性能。源代码如清单5-1所示。

清单5-1:CmdBar 程序

CmdBar.rc

//======================================================================

// Resource file

//

// Written for the book Programming Windows CE

// Copyright (C) 2003 Douglas Boling

//======================================================================

#include "windows.h"

#include "CmdBar.h" // Program-specific stuff

//----------------------------------------------------------------------

// Icons and bitmaps

//

ID_ICON ICON "cmdbar.ico" // Program icon

DisCross BITMAP "cross.bmp" // Disabled button image

DisMask BITMAP "mask.bmp" // Disabled button image mask

SortDropBtn BITMAP "sortdrop.bmp" // Sort drop-down button image

//----------------------------------------------------------------------

// Menu

//

ID_MENU MENU DISCARDABLE

BEGIN

POPUP "&File"

BEGIN

MENUITEM "E&xit", IDM_EXIT

END

POPUP "&View"

BEGIN

MENUITEM "&Standard", IDM_STDBAR

MENUITEM "&View", IDM_VIEWBAR

MENUITEM "&Combination", IDM_COMBOBAR

END

POPUP "&Help"

BEGIN

MENUITEM "&About...", IDM_ABOUT

END

END

popmenu MENU DISCARDABLE

BEGIN

POPUP "&Sort"

BEGIN

MENUITEM "&Name", IDC_SNAME

MENUITEM "&Type", IDC_STYPE

MENUITEM "&Size", IDC_SSIZE

MENUITEM "&Date", IDC_SDATE

END

END

//----------------------------------------------------------------------

// About box dialog template

//

aboutbox DIALOG discardable 10, 10, 160, 45

STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU |

DS_CENTER | DS_MODALFRAME

CAPTION "About"

BEGIN

ICON ID_ICON, -1, 5, 5, 10, 10

LTEXT "CmdBar - Written for the book Programming Windows CE Copyright 2003 Douglas Boling"

-1, 40, 5, 110, 35

END

CmdBar.h

//======================================================================

// Header file

//

// Written for the book Programming Windows CE

// Copyright (C) 2003 Douglas Boling

//======================================================================

// Returns number of elements

#define dim(x) (sizeof(x) / sizeof(x[0]))

//----------------------------------------------------------------------

// Generic defines and data types

//

struct decodeUINT { // Structure associates

UINT Code; // messages

// with a function.

LRESULT (*Fxn)(HWND, UINT, WPARAM, LPARAM);

};

struct decodeCMD { // Structure associates

UINT Code; // menu IDs with a

LRESULT (*Fxn)(HWND, WORD, HWND, WORD); // function.

};

//----------------------------------------------------------------------

// Generic defines used by application

#define IDC_CMDBAR 1 // Command band ID

#define ID_ICON 10 // Icon resource ID

#define ID_MENU 11 // Main menu resource ID

#define IDC_COMBO 12 // Combo box on cmd bar ID

// Menu item IDs

#define IDM_EXIT 101 // File menu

#define IDM_STDBAR 111 // View menu

#define IDM_VIEWBAR 112

#define IDM_COMBOBAR 113

#define IDM_ABOUT 120 // Help menu

// Command bar button IDs

#define IDC_NEW 201

#define IDC_OPEN 202

#define IDC_SAVE 203

#define IDC_CUT 204

#define IDC_COPY 205

#define IDC_PASTE 206

#define IDC_PROP 207

#define IDC_LICON 301

#define IDC_SICON 302

#define IDC_LIST 303

#define IDC_RPT 304

#define IDC_SNAME 305

#define IDC_STYPE 306

#define IDC_SSIZE 307

#define IDC_SDATE 308

#define IDC_DPSORT 350

#define STD_BMPS (STD_PRINT+1) // Number of bmps in

// std imglist

#define VIEW_BMPS (VIEW_NEWFOLDER+1) // Number of bmps in

// view imglist

//----------------------------------------------------------------------

// Function prototypes

//

HWND InitInstance (HINSTANCE, LPWSTR, int);

int TermInstance (HINSTANCE, int);

// Window procedures

LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);

// Message handlers

LRESULT DoCreateMain (HWND, UINT, WPARAM, LPARAM);

LRESULT DoSizeMain (HWND, UINT, WPARAM, LPARAM);

LRESULT DoCommandMain (HWND, UINT, WPARAM, LPARAM);

LRESULT DoNotifyMain (HWND, UINT, WPARAM, LPARAM);

LRESULT DoDestroyMain (HWND, UINT, WPARAM, LPARAM);

// Command functions

LPARAM DoMainCommandExit (HWND, WORD, HWND, WORD);

LPARAM DoMainCommandVStd (HWND, WORD, HWND, WORD);

LPARAM DoMainCommandVView (HWND, WORD, HWND, WORD);

LPARAM DoMainCommandVCombo (HWND, WORD, HWND, WORD);

LPARAM DoMainCommandAbout (HWND, WORD, HWND, WORD);

// Dialog procedures

BOOL CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM);

CmdBar.cpp

//======================================================================

// CmdBar - Command bar demonstration

//

// Written for the book Programming Windows CE

// Copyright (C) 2003 Douglas Boling

//======================================================================

#include <windows.h> // For all that Windows stuff

#include <commctrl.h> // Command bar includes

#include "CmdBar.h" // Program-specific stuff

//----------------------------------------------------------------------

// Global data

//

const TCHAR szAppName[] = TEXT ("CmdBar");

HINSTANCE hInst; // Program instance handle

// Message dispatch table for MainWindowProc

const struct decodeUINT MainMessages[] = {

WM_CREATE, DoCreateMain,

WM_SIZE, DoSizeMain,

WM_COMMAND, DoCommandMain,

WM_NOTIFY, DoNotifyMain,

WM_DESTROY, DoDestroyMain,

};

// Command Message dispatch for MainWindowProc

const struct decodeCMD MainCommandItems[] = {

IDM_EXIT, DoMainCommandExit,

IDM_STDBAR, DoMainCommandVStd,

IDM_VIEWBAR, DoMainCommandVView,

IDM_COMBOBAR, DoMainCommandVCombo,

IDM_ABOUT, DoMainCommandAbout,

};

// Standard file bar button structure

const TBBUTTON tbCBStdBtns[] = {

// BitmapIndex Command State Style UserData String

{0, 0, 0, TBSTYLE_SEP, 0, 0},

{STD_FILENEW, IDC_NEW, TBSTATE_ENABLED,

TBSTYLE_BUTTON, 0, 0},

{STD_FILEOPEN, IDC_OPEN, TBSTATE_ENABLED,

TBSTYLE_BUTTON, 0, 0},

{STD_FILESAVE, IDC_SAVE, TBSTATE_ENABLED,

TBSTYLE_BUTTON, 0, 0},

{0, 0, 0, TBSTYLE_SEP, 0, 0},

{STD_CUT, IDC_CUT, TBSTATE_ENABLED,

TBSTYLE_BUTTON, 0, 0},

{STD_COPY, IDC_COPY, TBSTATE_ENABLED,

TBSTYLE_BUTTON, 0, 0},

{STD_PASTE, IDC_PASTE, TBSTATE_ENABLED,

TBSTYLE_BUTTON, 0, 0},

{0, 0, 0, TBSTYLE_SEP, 0, 0},

{STD_PROPERTIES, IDC_PROP, TBSTATE_ENABLED,

TBSTYLE_BUTTON, 0, 0}

};

// Standard view bar button structure

const TBBUTTON tbCBViewBtns[] = {

// BitmapIndex Command State Style UserData String

{0, 0, 0, TBSTYLE_SEP, 0, 0},

{VIEW_LARGEICONS, IDC_LICON, TBSTATE_ENABLED | TBSTATE_CHECKED,

TBSTYLE_CHECKGROUP, 0, 0},

{VIEW_SMALLICONS, IDC_SICON, TBSTATE_ENABLED,

TBSTYLE_CHECKGROUP, 0, 0},

{VIEW_LIST, IDC_LIST, 0, TBSTYLE_CHECKGROUP, 0, 0},

{VIEW_DETAILS, IDC_RPT, TBSTATE_ENABLED,

TBSTYLE_CHECKGROUP, 0, 0},

{0, 0, TBSTATE_ENABLED,

TBSTYLE_SEP, 0, 0},

{VIEW_SORTNAME, IDC_SNAME, TBSTATE_ENABLED | TBSTATE_CHECKED,

TBSTYLE_CHECKGROUP, 0, 0},

{VIEW_SORTTYPE, IDC_STYPE, TBSTATE_ENABLED,

TBSTYLE_CHECKGROUP, 0, 0},

{VIEW_SORTSIZE, IDC_SSIZE, TBSTATE_ENABLED,

TBSTYLE_CHECKGROUP, 0, 0},

{VIEW_SORTDATE, IDC_SDATE, TBSTATE_ENABLED,

TBSTYLE_CHECKGROUP, 0, 0},

{0, 0, 0, TBSTYLE_SEP, 0, 0},

};

// Tooltip string list for view bar

const TCHAR *pViewTips[] = {TEXT (""), TEXT ("Large"), TEXT ("Small"),

TEXT ("List"), TEXT ("Details"), TEXT (""),

TEXT ("Sort by Name"), TEXT ("Sort by Type"),

TEXT ("Sort by Size"), TEXT ("Sort by Date"),

};

// Combination standard and view bar button structure

const TBBUTTON tbCBCmboBtns[] = {

// BitmapIndex Command State Style UserData String

{0, 0, 0, TBSTYLE_SEP, 0, 0},

{STD_FILENEW, IDC_NEW, TBSTATE_ENABLED,

TBSTYLE_BUTTON, 0, 0},

{STD_FILEOPEN, IDC_OPEN, TBSTATE_ENABLED,

TBSTYLE_BUTTON, 0, 0},

{STD_PROPERTIES, IDC_PROP, TBSTATE_ENABLED,

TBSTYLE_BUTTON, 0, 0},

{0, 0, 0, TBSTYLE_SEP, 0, 0},

{STD_CUT, IDC_CUT, TBSTATE_ENABLED,

TBSTYLE_BUTTON, 0, 0},

{STD_COPY, IDC_COPY, TBSTATE_ENABLED,

TBSTYLE_BUTTON, 0, 0},

{STD_PASTE, IDC_PASTE, TBSTATE_ENABLED,

TBSTYLE_BUTTON, 0, 0},

{0, 0, 0, TBSTYLE_SEP, 0, 0},

{STD_BMPS + VIEW_LARGEICONS,

IDC_LICON, TBSTATE_ENABLED | TBSTATE_CHECKED,

TBSTYLE_CHECKGROUP, 0, 0},

{STD_BMPS + VIEW_SMALLICONS,

IDC_SICON, TBSTATE_ENABLED,

TBSTYLE_CHECKGROUP, 0, 0},

{STD_BMPS + VIEW_LIST,

IDC_LIST, TBSTATE_ENABLED,

TBSTYLE_CHECKGROUP, 0, 0},

{STD_BMPS + VIEW_DETAILS,

IDC_RPT, TBSTATE_ENABLED,

TBSTYLE_CHECKGROUP, 0, 0},

{0, 0, 0, TBSTYLE_SEP, 0, 0},

{STD_BMPS + VIEW_BMPS,

IDC_DPSORT,TBSTATE_ENABLED,

TBSTYLE_DROPDOWN, 0, 0}

};

//======================================================================

// Program entry point

//

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,

LPWSTR lpCmdLine, int nCmdShow) {

HWND hwndMain;

MSG msg;

int rc = 0;

// Initialize application.

hwndMain = InitInstance (hInstance, lpCmdLine, nCmdShow);

if (hwndMain == 0) return 0x10;

// Application message loop

while (GetMessage (&msg, NULL, 0, 0)) {

TranslateMessage (&msg);

DispatchMessage (&msg);

}

// Instance cleanup

return TermInstance (hInstance, msg.wParam);

}

//----------------------------------------------------------------------

// InitInstance - Instance initialization

//

HWND InitInstance (HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow){

HWND hWnd;

DWORD dwStyle = WS_VISIBLE;

int x = CW_USEDEFAULT, y = CW_USEDEFAULT;

int cx = CW_USEDEFAULT, cy = CW_USEDEFAULT;

WNDCLASS wc;

INITCOMMONCONTROLSEX icex;

#if defined(WIN32_PLATFORM_PSPC)

// If Pocket PC, allow only one instance of the application.

hWnd = FindWindow (szAppName, NULL);

if (hWnd) {

SetForegroundWindow ((HWND)(((DWORD)hWnd) | 0x01));

return 0;

}

#endif

// Register application main window class.

wc.style = 0; // Window style

wc.lpfnWndProc = MainWndProc; // Callback function

wc.cbClsExtra = 0; // Extra class data

wc.cbWndExtra = 0; // Extra window data

wc.hInstance = hInstance; // Owner handle

wc.hIcon = NULL, // Application icon

wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor

wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);

wc.lpszMenuName = NULL; // Menu name

wc.lpszClassName = szAppName; // Window class name

if (RegisterClass (&wc) == 0) return 0;

// Load the command bar common control class.

icex.dwSize = sizeof (INITCOMMONCONTROLSEX);

icex.dwICC = ICC_BAR_CLASSES;

InitCommonControlsEx (&icex);

#ifndef WIN32_PLATFORM_PSPC

dwStyle |= WS_CAPTION | WS_SIZEBOX | WS_MAXIMIZEBOX | WS_MINIMIZEBOX;

x = y = 10;

cx = GetSystemMetrics (SM_CXSCREEN) - 30;

cy = GetSystemMetrics (SM_CYSCREEN) - 50

#endif

// Save program instance handle in global variable.

hInst = hInstance;

// Create main window.

hWnd = CreateWindow (szAppName, TEXT ("CmdBar Demo"), dwStyle,

x, y, cx, cy, NULL, NULL, hInstance, NULL);

// Return fail code if window not created.

if (!IsWindow (hWnd)) return 0;

// Standard show and update calls

ShowWindow (hWnd, nCmdShow);

UpdateWindow (hWnd);

return hWnd;

}

//----------------------------------------------------------------------

// TermInstance - Program cleanup

//

int TermInstance (HINSTANCE hInstance, int nDefRC) {

return nDefRC;

}

//======================================================================

// Message handling procedures for MainWindow

//----------------------------------------------------------------------

// MainWndProc - Callback function for application window

//

LRESULT CALLBACK MainWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,

LPARAM lParam) {

int i;

//

// Search message list to see if we need to handle this

// message. If in list, call procedure.

//

for (i = 0; i < dim(MainMessages); i++) {

if (wMsg == MainMessages[i].Code)

return (*MainMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);

}

return DefWindowProc (hWnd, wMsg, wParam, lParam);

}

//----------------------------------------------------------------------

// DoCreateMain - Process WM_CREATE message for window.

//

LRESULT DoCreateMain (HWND hWnd, UINT wMsg, WPARAM wParam,

LPARAM lParam) {

HWND hwndCB;

// 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);

return 0;

}

//----------------------------------------------------------------------

// DoSizeMain - Process WM_SIZE message for window.

//

LRESULT DoSizeMain (HWND hWnd, UINT wMsg, WPARAM wParam,

LPARAM lParam) {

#ifndef WIN32_PLATFORM_PSPC

HWND hwndCB = GetDlgItem (hWnd, IDC_CMDBAR);

// Tell the command bar to resize itself and reposition Close button.

SendMessage(hwndCB, TB_AUTOSIZE, 0L, 0L);

CommandBar_AlignAdornments(hwndCB);

#endif //WIN32_PLATFORM_PSPC

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 pNotifyHeader;

LPNMTOOLBAR pNotifyToolBar;

RECT rect;

TPMPARAMS tpm;

HMENU hMenu;

// Get pointer to notify message header.

pNotifyHeader = (LPNMHDR)lParam;

if (pNotifyHeader->code == TBN_DROPDOWN) {

// Get pointer to toolbar notify structure.

pNotifyToolBar = (LPNMTOOLBAR)lParam;

if (pNotifyToolBar->iItem == IDC_DPSORT) {

// Get the rectangle of the drop-down button.

SendMessage (pNotifyHeader->hwndFrom, TB_GETRECT,

pNotifyToolBar->iItem, (LPARAM)&rect);

// Convert rect to screen coordinates. The rect is

// considered here to be an array of 2 POINT structures.

MapWindowPoints (pNotifyHeader->hwndFrom, HWND_DESKTOP,

(LPPOINT)&rect, 2);

// Prevent the menu from covering the button.

tpm.cbSize = sizeof (tpm);

CopyRect (&tpm.rcExclude, &rect);

hMenu = GetSubMenu (LoadMenu (hInst, TEXT ("popmenu")),0);

TrackPopupMenuEx (hMenu, TPM_LEFTALIGN | TPM_VERTICAL,

rect.left, rect.bottom, hWnd, &tpm);

}

}

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;

}

//----------------------------------------------------------------------

// DoMainCommandViewStd - Displays a standard edit-centric command bar

//

LPARAM DoMainCommandVStd (HWND hWnd, WORD idItem, HWND hwndCtl,

WORD wNotifyCode) {

HWND hwndCB;

// If a command bar exists, kill it.

if (hwndCB = GetDlgItem (hWnd, IDC_CMDBAR))

CommandBar_Destroy (hwndCB);

// Create a command bar.

hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);

// Insert a menu.

CommandBar_InsertMenubar (hwndCB, hInst, ID_MENU, 0);

// Insert buttons.

CommandBar_AddBitmap (hwndCB, HINST_COMMCTRL, IDB_STD_SMALL_COLOR,

STD_BMPS, 0, 0);

CommandBar_AddButtons (hwndCB, dim(tbCBStdBtns), tbCBStdBtns);

// Add exit button to command bar.

CommandBar_AddAdornments (hwndCB, 0, 0);

return 0;

}

//----------------------------------------------------------------------

// DoMainCommandVView - Displays a standard edit-centric command bar

//

LPARAM DoMainCommandVView (HWND hWnd, WORD idItem, HWND hwndCtl,

WORD wNotifyCode) {

INT i;

HWND hwndCB;

TCHAR szTmp[64];

HBITMAP hBmp, hMask;

HIMAGELIST hilDisabled, hilEnabled;

// If a command bar exists, kill it.

if (hwndCB = GetDlgItem (hWnd, IDC_CMDBAR))

CommandBar_Destroy (hwndCB);

// Create a command bar.

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);

// Load bitmaps for disabled image.

hBmp = LoadBitmap (hInst, TEXT ("DisCross"));

hMask = LoadBitmap (hInst, TEXT ("DisMask"));

// Get the current image list and copy.

hilEnabled = (HIMAGELIST)SendMessage (hwndCB, TB_GETIMAGELIST, 0, 0);

hilDisabled = ImageList_Duplicate (hilEnabled);

// Replace a button image with the disabled image.

ImageList_Replace (hilDisabled, VIEW_LIST, hBmp, hMask);

// Set disabled image list.

SendMessage (hwndCB, TB_SETDISABLEDIMAGELIST, 0,

(LPARAM)hilDisabled);

// 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);

return 0;

}

//----------------------------------------------------------------------

// DoMainCommandVCombo - Displays a combination of file and edit buttons

//

LPARAM DoMainCommandVCombo (HWND hWnd, WORD idItem, HWND hwndCtl,

WORD wNotifyCode) {

HWND hwndCB;

// If a command bar exists, kill it.

if (hwndCB = GetDlgItem (hWnd, IDC_CMDBAR))

CommandBar_Destroy (hwndCB);

// Create a command bar.

hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);

// Insert a menu.

CommandBar_InsertMenubar (hwndCB, hInst, ID_MENU, 0);

// Add two bitmap lists plus custom bmp for drop-down button.

CommandBar_AddBitmap (hwndCB, HINST_COMMCTRL, IDB_STD_SMALL_COLOR,

STD_BMPS, 0, 0);

CommandBar_AddBitmap (hwndCB, HINST_COMMCTRL, IDB_VIEW_SMALL_COLOR,

VIEW_BMPS, 0, 0);

CommandBar_AddBitmap (hwndCB, NULL,

(int)LoadBitmap (hInst, TEXT ("SortDropBtn")),

1, 0, 0);

CommandBar_AddButtons (hwndCB, dim(tbCBCmboBtns), tbCBCmboBtns);

// Add exit button to command bar.

CommandBar_AddAdornments (hwndCB, 0, 0);

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;

}

CmdBar所创建的每个命令条都演示了命令条控件的不同能力。在例程DoMainCommandVStd中创建了第一个命令条,带有一个菜单和一组按钮。按钮结构的定义位于CmdBar.cpp文件顶部位置的tbCBStdBtns数组里。

在例程DoMainCommandVView中创建了第二个命令条,包含了由组合框分隔开的两组复选框按钮。该命令条也演示了用于失效按钮的分隔图的用法。命令条上第三个按钮--列表视图按钮--是失效的。用于按钮的失效图像是一个看上去像X的位图,该位图位于失效按钮图象列表里。

在例程DoMainCommandVCombo中创建了第三个命令条。该命令条为下拉按钮提供了标准位图以及定制位图。演示了如何在包含多个位图的图象列表中引用图象的技术。下拉按钮使用了DoNotifyMain例程,当收到TBN_DROPDOWN通知后,该例程会装载和显示一个弹出式菜单。

当CmdBar最终被编译成Windows CE的嵌入式版本时,受CreateWindow中的风格标志影响,使其看上去有点不同。主窗口有标题栏,但不会占据整个屏幕。您可以通过拖拉窗口的边缘来调整窗口,通过拖动标题栏来移动窗口。通过借鉴WM_SIZE消息处理函数里的一些代码,该程序演示了命令条调整自身的能力。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有