我有一个标准的Win32应用程序,它有一个Toolbar和一个Rebar控件,我首先创建Toolbar控件,作为主窗口的子窗口,然后创建Rebar,在Toolbar中添加一个带。
夹点出现在工具栏底部,这是意外的:
下面是我的创建代码(从MSDN复制):
HIMAGELIST g_hImageList = NULL;
HWND CreateSimpleToolbar(HWND hWndParent)
{
// Declare and initialize local constants.
const int ImageListID = 0;
const int numButtons = 3;
const int bitmapSize = 16;
const DWORD buttonStyles = BTNS_AUTOSIZE;
// Create the toolbar.
HWND hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
WS_CHILD | TBSTYLE_FLAT | TBSTYLE_LIST, 0, 0, 0, 0,
hWndParent, NULL, hInst, NULL);
if (hWndToolbar == NULL)
return NULL;
// Create the image list.
g_hImageList = ImageList_Create(bitmapSize, bitmapSize, // Dimensions of individual bitmaps.
ILC_COLOR16 | ILC_MASK, // Ensures transparent background.
numButtons, 0);
// Set the image list.
SendMessage(hWndToolbar, TB_SETIMAGELIST,
(WPARAM)ImageListID,
(LPARAM)g_hImageList);
// Load the button images.
SendMessage(hWndToolbar, TB_LOADIMAGES,
(WPARAM)IDB_STD_SMALL_COLOR,
(LPARAM)HINST_COMMCTRL);
// Initialize button info.
// IDM_NEW, IDM_OPEN, and IDM_SAVE are application-defined command constants.
TBBUTTON tbButtons[numButtons] =
{
{ MAKELONG(STD_FILENEW, ImageListID), 100, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Back"},
{ MAKELONG(STD_FILEOPEN, ImageListID), 101, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Forward"},
{ MAKELONG(STD_FILESAVE, ImageListID), 102, 0, buttonStyles, {0}, 0, (INT_PTR)L"Save"}
};
// Add buttons.
SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
SendMessage(hWndToolbar, TB_ADDBUTTONS, (WPARAM)numButtons, (LPARAM)&tbButtons);
// Resize the toolbar, and then show it.
SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);
ShowWindow(hWndToolbar, TRUE);
return hWndToolbar;
}
#define NUMBUTTONS 3
HWND CreateRebar(HWND hwndOwner, HWND hwndNavbar)
{
// Check parameters.
if ((hwndNavbar == NULL))
{
return NULL;
}
// Initialize common controls.
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_COOL_CLASSES | ICC_BAR_CLASSES;
InitCommonControlsEx(&icex);
// Create the rebar.
HWND hwndRebar = CreateWindowEx(WS_EX_TOOLWINDOW,
REBARCLASSNAME,
NULL,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | RBS_VARHEIGHT |
CCS_NODIVIDER | RBS_BANDBORDERS,
0, 0, 0, 0,
hwndOwner,
NULL,
hInst, // global instance handle
NULL);
if (!hwndRebar)
{
return NULL;
}
// Initialize band info used by both bands.
REBARBANDINFO rbBand = { REBARBANDINFOA_V3_SIZE };
rbBand.fMask =
RBBIM_STYLE // fStyle is valid.
| RBBIM_TEXT // lpText is valid.
| RBBIM_CHILD // hwndChild is valid.
| RBBIM_CHILDSIZE // child size members are valid.
| RBBIM_SIZE; // cx is valid
rbBand.fStyle = RBBS_CHILDEDGE | RBBS_GRIPPERALWAYS;
// Get the height of the toolbar.
DWORD dwBtnSize = (DWORD)SendMessage(hwndNavbar, TB_GETBUTTONSIZE, 0, 0);
// Set values unique to the band with the toolbar.
rbBand.lpText = LPWSTR("");
rbBand.hwndChild = hwndNavbar;
rbBand.cyChild = LOWORD(dwBtnSize);
rbBand.cxMinChild = NUMBUTTONS * HIWORD(dwBtnSize);
rbBand.cyMinChild = LOWORD(dwBtnSize);
// The default width is the width of the buttons.
rbBand.cx = 0;
// Add the band that has the toolbar.
if (!SendMessage(hwndRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand))
{
MessageBox(NULL,
_T("Could not create band!"),
_T("pXview"),
NULL);
}
return (hwndRebar);
}
它是在窗口显示和更新后创建的,如下所示:
HWND toolbar = CreateSimpleToolbar(hWnd);
CreateRebar(hWnd, toolbar);
我试过改变风格,钢筋乐队的方式是大小和位置等,但不能修复它。
1条答案
按热度按时间sbdsn5lh1#
您正在将工具栏创建为主窗口的子项,然后将钢筋创建为主窗口的子项,位于工具栏的下方。请改为将工具栏创建为钢筋的子项,然后将工具栏指定给钢筋标注栏。请参阅creating rebar control and introduction a band with toolbar into the rebar