Thread: Creating a toolbar using CreateWindowEX()

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    30

    Question Creating a toolbar using CreateWindowEX()

    Im trying to create a tool bar for a text editor using CreateWindowEX().
    The tool bar will show up fine, but then when you click on the button nothing will happen. Also, when you start typing in the edit box it just types over the tool bar and it eventually disapears.
    I have included commctrl.h and linked comctl32.lib.
    I have also called InitCommonControls();

    heres the code that i used to create the tool bar
    Code:
    void Document::CreateToolBar(const HWND &hwnd)
    {
    	TBBUTTON tbbutton;//struct for buttons
    	TBADDBITMAP tbbit;//struct for bitmaps on the buttons
    
    
    	//create toolbar
    	htool=CreateWindowEx(0, TOOLBARCLASSNAME,/*constant in commctrl.h*/ NULL, WS_CHILD | WS_VISIBLE, 0,0,0,0,
    				hwnd/*handle to the window i want it in*/,NULL, GetModuleHandle(NULL), NULL);
    
    	//send TB_BUTTONSTRUCTSIZE msg for backwards compatibility
    	SendMessage(htool,TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
    
    	//add standard bitmaps
    	tbbit.hInst= HINST_COMMCTRL; //defined in header file
    	tbbit.nID = IDB_STD_SMALL_COLOR;
    	SendMessage(htool,TB_ADDBITMAP, 0, (LPARAM)&tbbit);
    
    	//add buttons
    	//ZeroMemory(tbbutton, sizeof(tbbutton));
        tbbutton.iBitmap = STD_FILEOPEN;
        tbbutton.fsState = TBSTATE_ENABLED;
        tbbutton.fsStyle = TBSTYLE_BUTTON;
        tbbutton.idCommand = M_OPEN;
    
    	SendMessage(htool,TB_ADDBUTTONS, sizeof(tbbutton)/sizeof(TBBUTTON), (LPARAM) &tbbutton);
    									//above tells how many buttons we have
    	
    }//end of Document::CreateToolBar()
    This function is called in WinMain after the creation of my window and the hwnd for my window is used as the parameter.

    I think that it might be relevant to put in the code that I used to create the edit box also:
    Code:
    void Document::CreateEditBox(const HWND &hwnd, const LPARAM &lparam, HWND &edit,const RECT &rect)
    {
    	//create the edit box
    	//"EDIT" = a predefined window
    	//WS_CHILD = child to window, uses same WndProc
    	//ES_NOHIDEESEL = won't hid it when its not in focus
    	//ES_WANTRETURN = <enter>will be a carriage return
    	//((LPCREATESTRUCT)lparam)->hInstance = digs up the hinstance
    	// 
    	edit=CreateWindow("EDIT",NULL,WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL |
    								ES_AUTOVSCROLL | ES_LEFT | ES_MULTILINE |
    								ES_NOHIDESEL | WS_VSCROLL | WS_HSCROLL | 
    								WS_BORDER | ES_WANTRETURN,
    								0, 0, rect.right, rect.bottom, hwnd, (HMENU)EDIT_BOX,
    								((LPCREATESTRUCT)lparam)->hInstance, NULL);
    }//end of CreateEditBox()
    Any help is appreciated.

    Thank you in advance.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Make sure you set the top of your edit control to below the base of the toolbar and that should get rid of the disappearing edit control problem. You can do this in the WM_SIZE handler for the parent window.

    It may be that you couldn't get a response from your toolbar buttons because the edit control was somehow in the way. Once you have moved the edit control down a little, it may also eliminate this problem.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Making/Using toolbars: BlackSun Research Facility

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    30

    Thankyou

    Thanks for your help Ken. That did the trick.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  3. Toolbar color
    By mrafcho001 in forum Windows Programming
    Replies: 2
    Last Post: 04-17-2006, 10:55 AM
  4. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  5. Dockable Toolbar (Like taskbar or office toolbar)
    By om3ga in forum Windows Programming
    Replies: 2
    Last Post: 11-20-2005, 03:09 AM