Click to See Complete Forum and Search --> : how to create a toolbar in a dialog


pengkx
September 12th, 2003, 09:51 PM
I create a win32 SDK dialog
DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_MAINDLG),NULL,(DLGPROC)MainDlgProc,0);

case WM_INITDIALOG:
hwndRebar = CreateWindowEx(
WS_EX_TOOLWINDOW,
REBARCLASSNAME,
NULL,
WS_VISIBLE |
WS_BORDER |
WS_CHILD |
WS_CLIPCHILDREN |
WS_CLIPSIBLINGS |
CCS_NODIVIDER |
CCS_NOPARENTALIGN |
RBS_VARHEIGHT |
RBS_BANDBORDERS,
0, 0, 0, 0,
hwndParent,
(HMENU)0x2000,
hInst,
NULL);

but return value is zero,I fail to call CreateWindowEx,but if I create a window with CreateWindow instead of DialogBoxParam,I can succeed to call CreateWindowEx [I have called InitCommonControlsEx before],why ?

Bengi
September 13th, 2003, 04:35 PM
i already posted a code somewhere, but here we go again.


HWND CreateToolBar(HWND hWnd, HINSTANCE hInst)
{
/*
Function:
---------
"CreateToolBar"

Parameters:
-----------
1. HWND hWnd - Window handler to create toolbar on
2. HINSTANCE hInst - Our exe handler

Return Values:
--------------
Function returns Window Handler of the tool-bar

Usage:
--------
This function will create a tool bar.
and will set up the neccery buttons,
pictures on buttons, as well as the
styles and position !
*/

HIMAGELIST hImglBtn, hImglBtnHot; // Toolbar images handlers
TBBUTTON tbb[5]; // Button struct for tool bar
HBITMAP hBtn; // bitmaps handle
static HWND hWndTB; // Toolbar window handler

// begin ToolBar window creation
hWndTB = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT | TBSTYLE_AUTOSIZE, 0, 0, 0, 0,
hWnd, (HMENU)ID_TOOLBAR, GetModuleHandle(NULL), NULL);

// create image List
hImglBtn = ImageList_Create(24, 22, ILC_COLOR32 | ILC_MASK , 4, 1);
hBtn = (HBITMAP)LoadImage(hInst, MAKEINTRESOURCE(IDB_TOOLBAR), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
// use transperacy
ImageList_AddMasked(hImglBtn, hBtn, RGB(255, 0, 255));
DeleteObject(hBtn); // Kill image object

// create image List Hot Bar
hImglBtnHot = ImageList_Create(24, 22, ILC_COLOR32 | ILC_MASK , 4, 1);
hBtn = (HBITMAP)LoadImage(hInst, MAKEINTRESOURCE(IDB_TOOLBARHOT), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
// use transperacy
ImageList_AddMasked(hImglBtnHot, hBtn, RGB(255, 0, 255));
DeleteObject(hBtn); // Kill image object

// Attach the image lists to the window handler
SendMessage(hWndTB, TB_SETIMAGELIST, (WPARAM)0, (WPARAM)hImglBtn);
SendMessage(hWndTB, TB_SETHOTIMAGELIST, (WPARAM)0, (WPARAM)hImglBtnHot);

// button 1 properties
tbb[0].iBitmap = 0; // Array of picture to show
tbb[0].idCommand = 0;
tbb[0].fsState = TBSTATE_ENABLED; // button status
tbb[0].fsStyle = TBSTYLE_BUTTON; // button style
tbb[0].dwData = 0;
tbb[0].iString = 0;
tbb[0].idCommand=IDC_LOAD_FILE; // button identifier

// button 2 properties
tbb[1].iBitmap = 1;
tbb[1].idCommand = 0;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON;
tbb[1].dwData = 0;
tbb[1].iString = 0;
tbb[1].idCommand=IDC_SAVE_DISASM;

// seperator properties
tbb[2].iBitmap = 0;
tbb[2].idCommand = 0;
tbb[2].fsState = TBSTATE_ENABLED;
tbb[2].fsStyle = TBSTYLE_SEP;
tbb[2].dwData = 0;
tbb[2].iString = 0;

// button 4 properties
tbb[3].iBitmap = 2;
tbb[3].idCommand = 0;
tbb[3].fsState = TBSTATE_ENABLED;
tbb[3].fsStyle = TBSTYLE_BUTTON;
tbb[3].dwData = 0;
tbb[3].iString = 0;
tbb[3].idCommand=IDC_PE_EDITOR;

// button 5 properties
tbb[4].iBitmap = 3;
tbb[4].idCommand = 0;
tbb[4].fsState = TBSTATE_ENABLED;
tbb[4].fsStyle = TBSTYLE_BUTTON;
tbb[4].dwData = 0;
tbb[4].iString = 0;
tbb[4].idCommand=ID_PROCESS_SHOW;

// Add the buttons
SendMessage(hWndTB, TB_ADDBUTTONS, (WPARAM)5, (LPARAM)(LPTBBUTTON)&tbb); // add buttons
// Auto Disable buttons on startup
SendMessage(hWndTB, TB_ENABLEBUTTON, IDC_PE_EDITOR, (LPARAM)FALSE); // Disable Buttons
SendMessage(hWndTB, TB_ENABLEBUTTON, IDC_SAVE_DISASM, (LPARAM)FALSE); // at first run

// Kill image object
DeleteObject(hBtn);

// Return tool bar window handler
return hWndTB;
}



and call it like this in ur WM_INITDIALOG message:
hWndTB=CreateToolBar(hWnd,hInst);

u will need a bmp with the icons on it so they can appear in ur tool bar

pengkx
September 13th, 2003, 09:10 PM
I can see code like yours in msdn,but still thank you very much,I want to create a Rebar with CreateWindowEx( WS_EX_TOOLWINDOW,
REBARCLASSNAME,......),then place toolbars,buttons and combos on it