📄 cmdbar.cpp
字号:
// 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) {
// This only needed if the window can be resized
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);
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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -