опубликован 09-01-2002 05:49 MSK
На мой взягляд, тебе уже всё сказано. Берёшь исходники WTL и смотришь. Сколько будешь смотреть - не знаю. Вот отрывок для подключения меню:BOOL AttachMenu(HMENU hMenu)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT(::IsMenu(hMenu));
if(hMenu != NULL && !::IsMenu(hMenu))
return FALSE;
// destroy old menu, if needed, and set new one
if(m_hMenu != NULL && (m_dwExtendedStyle & CBR_EX_SHAREMENU) == 0)
::DestroyMenu(m_hMenu);
m_hMenu = hMenu;
if(m_bAttachedMenu) // Nothing else in this mode
return TRUE;
// Build buttons according to menu
SetRedraw(FALSE);
// Clear all
BOOL bRet;
int nCount = GetButtonCount();
for(int i = 0; i < nCount; i++)
{
bRet = DeleteButton(0);
ATLASSERT(bRet);
}
// Add buttons for each menu item
if(m_hMenu != NULL)
{
int nItems = ::GetMenuItemCount(m_hMenu);
T* pT = static_cast<T*>(this);
pT; // avoid level 4 warning
TCHAR szString[pT->_nMaxMenuItemTextLength];
for(int i = 0; i < nItems; i++)
{
CMenuItemInfo mii;
mii.fMask = MIIM_TYPE | MIIM_STATE | MIIM_SUBMENU;
mii.fType = MFT_STRING;
mii.dwTypeData = szString;
mii.cch = pT->_nMaxMenuItemTextLength;
bRet = ::GetMenuItemInfo(m_hMenu, i, TRUE, &mii);
ATLASSERT(bRet);
// If we have more than the buffer, we assume we have bitmaps bits
if(lstrlen(szString) > pT->_nMaxMenuItemTextLength - 1)
{
mii.fType = MFT_BITMAP;
::SetMenuItemInfo(m_hMenu, i, TRUE, &mii);
szString[0] = 0;
}
// NOTE: Command Bar currently supports only drop-down menu items
ATLASSERT(mii.hSubMenu != NULL);
TBBUTTON btn;
btn.iBitmap = 0;
btn.idCommand = i;
btn.fsState = (BYTE)(((mii.fState & MFS_DISABLED) == 0) ? TBSTATE_ENABLED : 0);
btn.fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE | TBSTYLE_DROPDOWN;
btn.dwData = 0;
btn.iString = 0;
bRet = InsertButton(-1, &btn);
ATLASSERT(bRet);
TBBUTTONINFO bi;
memset(&bi, 0, sizeof(bi));
bi.cbSize = sizeof(TBBUTTONINFO);
bi.dwMask = TBIF_TEXT;
bi.pszText = szString;
bRet = SetButtonInfo(i, &bi);
ATLASSERT(bRet);
}
}
SetRedraw(TRUE);
Invalidate();
UpdateWindow();
return TRUE;
}