我正在通过创建自定义Windows应用程序来学习C ++和Winapi;因为我希望能够给出我自己的外观我摆脱了非客户区域,我自己定义所有边框和标题栏相关的操作。控件在此测试示例中按预期工作,但它始终出现在我窗口的最左上角(仅限整个客户区)并占据整个宽度(因此也覆盖了我的MIN / MAX / CLOSE按钮)
如何使用我想要的宽度将Rebar菜单放入客户区的自定义位置,而不是自动整个窗口宽度?
我正在将Rebar控件(在单独的文件中)子类化为:
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include "TitleMenu.h"
TitleMenu::TitleMenu ()
{
/* Vars to take over params passed into class from main window */
posX = NULL; // Position of control
posY = NULL; // Position of control
width = 0; // Width of control
height = 0; // Height of control
/* Control related variables */
titleMenu = NULL; // Handle to control created as point of this class
titleMenuToolbar = NULL; // Handle to control's toolbar
}
TitleMenu::~TitleMenu ()
{
if ( titleMenu )
DestroyWindow ( titleMenu );
}
TitleMenu* TitleMenu::CreateTitleMenu ( HWND hwnd, int posX, int posY, int width, int height )
// The purpose of this function is to create control and provide pointer to it; rebar control is used
{
TitleMenu* p_titleMenu = new TitleMenu; // Control pointer
p_titleMenu->titleMenu = CreateWindowEx ( 0, REBARCLASSNAME, 0, WS_CHILD | WS_VISIBLE, posX, posY, width, height, hwnd, 0, (HINSTANCE)GetWindowLong ( hwnd, GWL_HINSTANCE ), p_titleMenu );
if ( p_titleMenu->titleMenu == NULL )
{
delete p_titleMenu;
MessageBox ( NULL, L"Problem creating the Menu.", L"Error", 0 );
return 0;
}
p_titleMenu->titleMenuToolbar = CreateWindowEx ( 0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT, posX, posY, width, height, p_titleMenu->titleMenu, 0, (HINSTANCE)GetWindowLong ( p_titleMenu->titleMenu, GWL_HINSTANCE ), NULL );
if ( p_titleMenu->titleMenuToolbar == NULL )
{
MessageBox ( NULL, L"Error creating Menu toolbar.", L"Error", 0 );
}
/* Create test buttons for Rebar control */
SendMessage ( p_titleMenu->titleMenuToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof ( TBBUTTON ), 0 );
TBBUTTON tbb [ 3 ] =
{
{ I_IMAGENONE, 0, TBSTATE_ENABLED, TBSTYLE_LIST },
{ I_IMAGENONE, 1, TBSTATE_ENABLED, TBSTYLE_LIST },
{ I_IMAGENONE, 2, TBSTATE_ENABLED, TBSTYLE_LIST },
};
SendMessage ( p_titleMenu->titleMenuToolbar, (UINT)TB_ADDBUTTONS, 3, (LPARAM)&tbb );
/* Define band info */
REBARBANDINFO rbBand;
rbBand.cbSize = REBARBANDINFO_V3_SIZE;
rbBand.fMask = RBBIM_STYLE | RBBIM_TEXT | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_COLORS;
rbBand.fStyle = RBBS_FIXEDSIZE | RBBS_HIDETITLE;
// Get the height of the buttons to be used in toolbar
DWORD dwBtnSize = (DWORD)SendMessage ( p_titleMenu->titleMenuToolbar, TB_GETBUTTONSIZE, 0, 0 );
rbBand.cx = 300;
rbBand.clrFore = RGB ( 233, 233, 233 );
rbBand.clrBack = RGB ( 18, 18, 18 );
rbBand.lpText = TEXT ( "" );
rbBand.hwndChild = p_titleMenu->titleMenuToolbar;
rbBand.cyChild = LOWORD ( dwBtnSize );
rbBand.cyMinChild = LOWORD ( dwBtnSize );
rbBand.cyMaxChild = LOWORD ( dwBtnSize );
rbBand.cxMinChild = 3 * HIWORD ( dwBtnSize );
rbBand.cyIntegral = 0;
rbBand.cxIdeal = 300;
SendMessage ( p_titleMenu->titleMenu, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand );
return p_titleMenu;
}
我通过.cx
并使用RBBIM_SIZE
来定义所需宽度,但这似乎没有任何效果。
我也试过这样发送RB_SIZETORECT
但没有成功:
RECT rc;
rc.top = 30;
rc.bottom = 60;
rc.left = 0;
rc.right = 300;
SendMessage ( p_titleMenu->titleMenu, RB_SIZETORECT, 0, (LPARAM)&rc );
消息RB_SETBANDWIDTH
也没有给出结果(来自MSDN describtion我不知道如何使用wParam参数。)
SendMessage ( p_titleMenu->titleMenu, RB_SETBANDWIDTH, 0, 300 );
我找不到与此特定问题相关的任何其他信息,所以我在这里问。谢谢!