Чтобы вставляемый на тулбар контрол не перекрывал кнопки создайте под ним сепаратор и в качестве битмапа укажите желаемую ширину в пикселах.
//----------------------------------------------------------------------------//
#include <windows.h>
#include <commctrl.h>
HWND hEdit, hLabel, hButton, hClrLbl, hBtnFnt,hToolBar, htool2,hcool,
hCombo, hStatus, hList1, hList2, hBtnClr;
HMENU hFileMenu, hHelpMenu, hSubMenu, hMenu, hPopUp;
const IDM_Enable_Disable = 0;
const IDM_Exit = 1;
const IDM_About = 2;
const IDP_File=3;
const IDP_Help = 4;
const IDM_Bitmap =5;
const ToolBtns = 13;
//----------------------------------------------------------------------------//
long __stdcall MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY: { PostQuitMessage( 0 ); return 0;}
case WM_NOTIFY:
{
LPNMTOOLBAR lpnmtb = (LPNMTOOLBAR) lParam;
LPNMHDR lpnm = (LPNMHDR) lParam;
switch (lpnm->code)
{
case TBN_DROPDOWN:
{
switch (lpnmtb->iItem)
{
case 301:
RECT rc;
SendMessage( hToolBar, TB_GETRECT, lpnmtb->iItem, (LPARAM)&rc);
POINT pp;
ZeroMemory( &pp, sizeof(pp));
ClientToScreen( hToolBar, &pp );
TrackPopupMenuEx( hFileMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL,
rc.left+pp.x, rc.bottom+pp.y, hWnd, NULL);
break;
}
}
}
return 0;
}
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
//----------------------------------------------------------------------------//
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
WNDCLASS wc = { CS_HREDRAW | CS_VREDRAW , MsgProc, 0L, 0L, hInstance,
LoadIcon(0, IDI_EXCLAMATION), LoadCursor(0, IDC_ARROW),
(HBRUSH)16, NULL, "Window" };
RegisterClass( &wc );
HWND hWnd = CreateWindow( "Window", "Интерфейс на WinAPI", WS_OVERLAPPEDWINDOW,// |WS_MINIMIZEBOX| WS_SYSMENU,
200, 200, 560, 270, NULL, NULL, wc.hInstance, NULL );
INITCOMMONCONTROLSEX icc={ sizeof(icc), ICC_BAR_CLASSES|ICC_COOL_CLASSES };
InitCommonControlsEx( &icc );
DWORD ws = WS_CHILD | WS_VISIBLE, ws2 = ws | WS_TABSTOP;
TBBUTTON tbb[ToolBtns];
int tbs[ToolBtns]={STD_FILENEW, STD_FILEOPEN, STD_FILESAVE, -1,150,-1, STD_CUT,
STD_COPY, STD_PASTE, -1, STD_UNDO, STD_REDOW, STD_HELP};
ZeroMemory( &tbb, sizeof(tbb));
for(int i=0; i<11; i++)
{
tbb[i].iBitmap=tbs[i];
tbb[i].idCommand=300+i;
tbb[i].fsState=TBSTATE_ENABLED;
if(tbs[i]==-1) tbb[i].fsStyle=TBSTYLE_SEP; else
tbb[i].fsStyle=TBSTYLE_BUTTON ;
tbb[i].iString=0;
}
tbb[4].fsStyle=TBSTYLE_SEP;
tbb[1].fsStyle=TBSTYLE_DROPDOWN ;
hToolBar = CreateToolbarEx( hWnd, /*CCS_ADJUSTABLE |*/WS_VISIBLE |TBSTYLE_FLAT|TBSTYLE_REGISTERDROP, 299, 15, HINST_COMMCTRL,
IDB_STD_SMALL_COLOR, 0, 0, 16,16, 15,15, sizeof(TBBUTTON) );
DWORD EXST = (DWORD) SendMessage( hToolBar, TB_GETEXTENDEDSTYLE, 0, 0 );
SendMessage( hToolBar, TB_SETEXTENDEDSTYLE, 0, EXST|TBSTYLE_EX_DRAWDDARROWS );
hCombo = CreateWindowEx(WS_EX_CLIENTEDGE , "COMBOBOX", NULL, ws2 |WS_VSCROLL |
CBS_DISABLENOSCROLL | CBS_AUTOHSCROLL | CBS_DROPDOWN ,
90, 0, 150, 150, hToolBar, (HMENU)513, wc.hInstance, NULL); //hCtrls[2] = hCombo;
SetWindowText( hCombo, "<< Выберите пункт >>");
SendMessage( hCombo, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Изменить заголовок" );
SendMessage( hCombo, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Добавить строку" );
SendMessage( hCombo, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Выход из программы" );
SendMessage( hCombo, CB_SETDROPPEDWIDTH, 200, 0 );
AppendMenu((hSubMenu=CreatePopupMenu()), MF_GRAYED | MF_STRING, 100,"Submenu 1 >");
AppendMenu( hSubMenu, MF_ENABLED | MF_STRING, 100,"Submenu 2");
AppendMenu((hFileMenu=CreatePopupMenu()), MF_ENABLED | MF_STRING, IDM_Enable_Disable, "&Enable exit");
AppendMenu( hFileMenu, MF_SEPARATOR, 0,"");
AppendMenu( hFileMenu, MF_ENABLED | MF_STRING | MF_POPUP,(UINT) hSubMenu,"&Right ->");
AppendMenu( hFileMenu, MF_GRAYED | MF_STRING, (IDM_Exit+200),"E&xit");
SendMessage( hToolBar, TB_ADDBUTTONS, (UINT)11, (LPARAM)(LPTBBUTTON) &tbb );
{
ShowWindow ( hWnd, SW_SHOWDEFAULT ), UpdateWindow( hWnd );
MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
if(!IsDialogMessage( hWnd, &msg ))
TranslateMessage( &msg ),
DispatchMessage ( &msg );
}
UnregisterClass( "Window", wc.hInstance );
}
//----------------------------------------------------------------------------//