Code:
case WM_CREATE:
{
CLIENTCREATESTRUCT ccs;
UINT iButton, iImageOffset;
TBADDBITMAP tbAddBitmap;
INT idCommands[COUNT_BUTTONS];
HWND hStatus;
int statwidths[] = {100, -1};
// Toolbar buttons...
TBBUTTON tbb [COUNT_BUTTONS] = {
{STD_FILENEW, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
{STD_FILEOPEN, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
{STD_FILESAVE, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
{STD_CUT, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
{STD_COPY, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
{STD_PASTE, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
{STD_UNDO, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
{5, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0},
{TBICON_FIND, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0 }, // Find
{HIST_FORWARD, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0 }, // Goto
{5, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0},
{TBICON_WORD_WRAP, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0 }, // Wordwrap
{TBICON_CONV_LINE_BREAKS, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0 }, // Convert line breaks
{5, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0},
{TBICON_CALCULATOR, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0 }, // Calculator
};
// Toolbar captions. Supposedly strings should be double null terminated...
const LPTSTR szToolbarCaptions[] = {
TEXT("New\0"), TEXT("Open\0"), TEXT("Save\0"), NULL,
TEXT("Cut\0"), TEXT("Copy\0"), TEXT("Paste\0"), TEXT("Undo\0"), NULL,
TEXT("Find\0"), TEXT("Goto\0"), NULL,
TEXT("Toggle Word Wrap\0"), TEXT("Convert Unix Style Line Breaks\0"), NULL,
TEXT("Calculator\0"),
};
ccs.hWindowMenu = GetSubMenu(GetMenu(hwnd), 2);
ccs.idFirstChild = ID_MDI_FIRSTCHILD;
g_hMDIClient = CreateWindowEx(WS_EX_CLIENTEDGE, "mdiclient", NULL,
WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hwnd, (HMENU)IDC_MAIN_MDI, GetModuleHandle(NULL), (LPVOID)&ccs);
if(g_hMDIClient == NULL)
MessageBox(hwnd, "Could not create MDI client.", "Error", MB_OK | MB_ICONERROR);
// Create a toolbar that has ToolTips associated with it...
g_hToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
WS_CHILD | TBSTYLE_TOOLTIPS | WS_CLIPSIBLINGS, 0, 0, 0, 0,
hwnd, (HMENU) IDC_MAIN_TOOL, (HINSTANCE)GetModuleHandle(0), NULL);
if (!g_hToolbar) return;
// Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility...
SendMessage(g_hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
// Prevent text from displaying under buttons...
SendMessage(g_hToolbar, TB_SETMAXTEXTROWS, 0, 0);
// Get the correct menu ids for our OS...
//GetCommandIds(idCommands);
for (iButton = 0;iButton < COUNT_BUTTONS;iButton++) {
// Set correct menu(command) id for each button...
tbb[iButton].idCommand = idCommands[iButton];
// Add button captions to toolbar string pool...
if (szToolbarCaptions[iButton] != NULL)
tbb[iButton].iString = SendMessage(g_hToolbar, TB_ADDSTRING, 0,
(LPARAM) szToolbarCaptions[iButton]);
else
tbb[iButton].iString = 0;
}
// Disable goto button on NT 4.0 as it does not exist...
if (tbb[10].idCommand == 0) tbb[10].fsState = 0; // Turn off TBSTATE_ENABLED
// Add standard image list...
tbAddBitmap.hInst = HINST_COMMCTRL;
tbAddBitmap.nID = IDB_STD_SMALL_COLOR;
SendMessage(g_hToolbar, TB_ADDBITMAP, 0, (LPARAM) &tbAddBitmap);
// Add history image list...
tbAddBitmap.hInst = HINST_COMMCTRL;
tbAddBitmap.nID = IDB_HIST_SMALL_COLOR;
iImageOffset = SendMessage(g_hToolbar, TB_ADDBITMAP, 0, (LPARAM) &tbAddBitmap);
tbb[10].iBitmap += iImageOffset; // Goto button
// Add custom images...
tbAddBitmap.hInst = hInstance;
tbAddBitmap.nID = TOOLBAR_ICONS;
iImageOffset = SendMessage(g_hToolbar, TB_ADDBITMAP, 5, (LPARAM) &tbAddBitmap);
tbb[9].iBitmap += iImageOffset; // Find button
tbb[12].iBitmap += iImageOffset; // Toggle Word Wrap button
tbb[13].iBitmap += iImageOffset; // Convert line breaks button
tbb[15].iBitmap += iImageOffset; // Calculator button
// Add buttons to toolbar...
SendMessage(g_hToolbar, TB_ADDBUTTONS, COUNT_BUTTONS, (LPARAM) &tbb);
// Send a WM_SIZE message to layout controls...
SendWMSizeMessage(hwnd);
// Show toolbar...
ShowWindow(g_hToolbar, SW_SHOWNORMAL);
hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL,
WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0,
hwnd, (HMENU)IDC_MAIN_STATUS, GetModuleHandle(NULL), NULL);
SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Hi there :)");
}
thanx again