代码移开工具栏

代码移动工具栏
问题1:


tb_addbitmap用法不对


#define NUM_BUTTONS 2
#define ID_TOOLBAR 4000



HWND hWndToolbar;
TBADDBITMAP tb;


// Create the toolbar.
hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, 
WS_CHILD |WS_VISIBLE| TBSTYLE_WRAPABLE, 0, 0, 0, 0, 
hWndParent, NULL, hInst, NULL);

if(hWndToolbar==NULL)
return NULL;

TBBUTTON tbButtons [NUM_BUTTONS] = 
{
{0, IDM_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{0, IDM_OPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
}; 

SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
SendMessage(hWndToolbar, TB_ADDBUTTONS,       (WPARAM)NUM_BUTTONS,       (LPARAM)&tbButtons);

tb.hInst = GetModuleHandle(NULL);
tb.nID =(UINT_PTR)LoadIcon(tb.hInst,MAKEINTRESOURCE(IDI_ICON2));
SendMessage (hWndToolbar, TB_ADDBITMAP, 1, (LPARAM)&tb);

msdn解释:

hInst
Type: HINSTANCE
Handle to the module instance with the executable file that contains a bitmap resource. To use bitmap handles instead of resource IDs, set this member to NULL.

nID
Type: UINT_PTR
If hInst is NULL, set this member to the bitmap handle of the bitmap with the button images. Otherwise, set it to the resource identifier of the bitmap with the button images.

 强调了一个概念:句柄,既然是句柄,所以就loadicon,  




可是2个按钮都没有图标.


问题2: movewindow移动不了工具栏, 怎么回事?》


------解决方案--------------------
可以移动呀,如

CRect rect(100,100,200,200);
m_Toolbar.MoveWindow(rect);//移动工具栏在父窗口的位置
m_Toolbar.ShowWindow(SW_SHOW);//显示工具栏


是不是你CRect写错了?断点调试下看看。

------解决方案--------------------
参考:


// Toolbar buttons
TBBUTTON tbButtons [] = 
{
{STD_FILENEW, IDM_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{STD_FILEOPEN, IDM_OPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{STD_FILESAVE, IDM_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, 0},
{VIEW_LARGEICONS, IDM_LARGEICON, TBSTATE_ENABLED, TBSTYLE_BUTTON, 
0L, 0},
{VIEW_SMALLICONS, IDM_SMALLICON, TBSTATE_ENABLED, TBSTYLE_BUTTON, 
0L, 0},
{VIEW_LIST, IDM_LISTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 
0L, 0},
{VIEW_DETAILS, IDM_REPORTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 
0L, 0},
}; 
//
HWND CreateTheToolbar (HWND hWndParent)
{
HWND hWndToolbar;
TBADDBITMAP tb;
int index, stdidx;

hWndToolbar = CreateToolbarEx (hWndParent, 
WS_CHILD 
------解决方案--------------------