Thread: Buttons & Toolbars Problem.

  1. #1
    Registered User dug's Avatar
    Join Date
    Jun 2003
    Posts
    66

    Buttons & Toolbars Problem.

    I have this pretty straight forward code where i have a toolbar, i add some buttons to the toolbar and then do the appropriate message mapping etc.

    However, for some reason when i press the button the code isn't executed... here's some sample code:

    Code:
    BEGIN_MESSAGE_MAP(CSessionFrameToolbar, CToolBar)
    	ON_WM_CREATE()
    	ON_COMMAND(IDC_SF_ZOOMIN, OnPressZoomIn)
    	ON_UPDATE_COMMAND_UI(IDC_SF_ZOOMIN, OnUpdateZoomIn)
    	ON_CBN_SELENDOK(IDC_SF_COMBOBOX, OnSelectCam)
    END_MESSAGE_MAP()
    
    //setup the buttons etc. in OnCreate()
    
    afx_msg void CSessionFrameToolbar::OnPressZoomIn()
    {
    	((CSessionFrame*)sess_frame)->zoomIn();
    }
    
    afx_msg void CSessionFrameToolbar::OnUpdateZoomIn(CCmdUI *pcmd)
    {
    	pcmd->SetCheck(FALSE);
    }
    now the line "((CSessionFrame*)sess_frame)->zoomIn();" should be reached when the IDC_SF_ZOOMIN button is pressed... BUT when i run in Debug mode, and i press the button, nothing happens, i set a break there and it is never reached, but what i get at the debug output is "Warning: no message line prompt for ID 0x9C49".

    seems like this should be pretty straight forward.... can anyone see anything criminally obvious?

    cheers.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Use ON_BN_CLICK.

    And the warning means that you don't have a string resource with the same ID as the button - MFC uses those for displaying text in the status bar and in tooltips:

    String resource:
    Id: IDC_CONTROL
    Value: "Text for statusbar\nTooltiptext"
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User dug's Avatar
    Join Date
    Jun 2003
    Posts
    66
    i used ON_BN_CLICK, but got 'undeclared identifier' at compile.
    "take the long road.... and walk it."

  4. #4
    Registered User dug's Avatar
    Join Date
    Jun 2003
    Posts
    66
    ON_WM_LBUTTONDOWN doesn't seem to work either.
    "take the long road.... and walk it."

  5. #5
    Registered User dug's Avatar
    Join Date
    Jun 2003
    Posts
    66
    just thought i'd add this...

    this toolbar class is a subclass of CToolBar, and the message handlers are in the toolbar source.... is this correct? or should the message handlers be in the ChildFrame that 'hosts' the ToolBar? the weird thing is that the combobox works just fine....

    i dunno...
    "take the long road.... and walk it."

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Sorry, it's ON_BN_CLICKED.
    (You could have found out by using the help.)

    or should the message handlers be in the ChildFrame that 'hosts' the ToolBar?
    Depends on the message. Parent notifications can be caught in the frame if they are the external interface of the toolbar. Notifications that are part of the toolbar itself should be caught by the toolbar using the reflection macros.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User dug's Avatar
    Join Date
    Jun 2003
    Posts
    66
    sorry thought you were takin the ........ with ON_BN_CLICK..... didn't think it was real...

    ON_BN_CLICKED still doesn't work....

    here's the create code in case there's anything i'm missing there... but i don't think so

    Code:
    int CSessionFrameToolbar::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    	if (CToolBar::OnCreate(lpCreateStruct) == -1)
    		return -1;
    
    	LoadToolBar(IDR_SF_TOOLBAR);
    	
    	pan_mode = TRUE;
    	uvs_mode = FALSE;
    	uvm_mode = FALSE;
    
    	SetButtonStyle(0, TBBS_CHECKBOX);
    	SetButtonStyle(1, TBBS_CHECKBOX);
    	
    	SetButtonStyle(2, TBBS_SEPARATOR);
    
    	SetButtonStyle(3, TBBS_CHECKBOX);
    	SetButtonStyle(4, TBBS_CHECKBOX);
    	SetButtonStyle(5, TBBS_CHECKBOX);
    	
    	SetButtonStyle(6, TBBS_SEPARATOR);
    	
    	SetButtonInfo(7, IDC_SF_COMBOBOX, TBBS_SEPARATOR, 200);
    
    	SetButtonStyle(8, TBBS_SEPARATOR);
    
    	CRect combo_rect;
    	GetItemRect(7, &combo_rect);
    	combo_rect.bottom = combo_rect.top + 144;
    	combo_box.Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|CBS_SORT|CBS_DROPDOWNLIST, combo_rect, this, IDC_SF_COMBOBOX);
    	combo_box.ShowWindow(SW_SHOW);
    	
    	return 1;
    }
    i dunno, seems like this should be easy.... what am i missing?
    "take the long road.... and walk it."

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Oh, so it's a toolbar button. I thought it was a real one.

    Try ON_COMMAND in the frame.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Registered User dug's Avatar
    Join Date
    Jun 2003
    Posts
    66
    OK moved everything to the frame, so now the buttons work.... but the combobox doesn't.... argh.
    "take the long road.... and walk it."

  10. #10
    Registered User dug's Avatar
    Join Date
    Jun 2003
    Posts
    66
    working now... thanks for yer help.
    "take the long road.... and walk it."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM