Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need CToolBar Help

33 views
Skip to first unread message

Tomas Vera

unread,
Mar 7, 2003, 12:51:26 PM3/7/03
to
Hello All,
I'm trying to maintain an app that was written by someone else. I'm pretty new
to MFC and am having trouble with a CToolBar object. I have a tool bar that
behaves differently in different dialogs and I need help understanding why.

I have two different dialogs that contains (among other things) a tab strip, a
CToolBar, a TreeView and a CListCtrl object. The CToolBar creates a an owner
draw DropDown control (derived from CComboBox) and places it in the first
position in the CToolBar. This dropdown hold the current path in piecemeal
fashion (e.g. C:\Windows\System32 would hold 3 places in the drop down control:
C:, Windows, and System32). The user can use this dropdown to work his way back
up the path.

The dialog works as expected when using a mouse. However, keyboard navigation
has a problem.

As the user tabs along the dialog, the focus goes as follows:
Dialog 1:
TabStrip -> Toolbar -> OwnerDraw controls ->TreeView -> ListView -> Buttons

Dialog2:
TabStrip -> Toolbar -> TreeView -> ListView (No buttons on this dialog)

In dialog 1, when the user tabs into the toolbar, the first button after the
owner draw control ("Button2", position "1" in zero based notation) get the
focus. From here the user can use the arrow keys to access the rest of the
buttons but not the owner draw control. However, when the user hits the TAB key,
the focus jumps to the owner draw control. This is unexpected, but the user gets
access to all the item in the toolbar.

In dialog 2, when the user tabs into the toolbar, the focus again goes to the
first button after the owner draw control. The user can access the rest of the
buttons with the arrow keys, but the owner draw control is not accessible.
However, when the user hits TAB, the focus jumps to the TreeView and the owner
draw control is bypassed.

We are using the same class for the toolbar, so I don't think the problem is
there. I suspect that the dialog classes are setting up something differntly,
but I'm not sure where to start looking.

Questions:
1. Since the owner draw control is added (using the CComboBox::Create(...)
function) to the toolbar in position 0, shouldn't it get the focus when the user
tabs to the CToolBar control?
2. Why would the focus jump from the tool bar to the owner draw control in
reponse to a TAB key? Isn't all the same control?

How should I trouble shoot this?

Thanks,
-tomas

Here are some code snippets used to set up the toolbar and add the DropDown
control. Please let me know if you see something out of place (error checking
omitted for clarity):

BOOL Dialog1::CreateToolBar() // this one works, kind of
{
m_wndToolbar.Create(this, WS_CHILD| WS_VISIBLE| WS_TABSTOP|
CBRS_ALIGN_TOP| CBRS_SIZE_FIXED| CBRS_TOOLTIPS| CBRS_FLYBY,
IDC_VIEW_TOOLBAR);
int toolbarId = MY_TOOLBAR_ID; // comes from somewhere else
m_wndToolbar.LoadToolBar(toolbarID);
m_wndToolbar.SetupDropDown(); // create ownerdraw control
m_wndToolbar.SetButtonStyle(4, TBBS_CHECKGROUP);
m_wndToolbar.SetButtonStyle(5, TBBS_CHECKGROUP);
m_wndToolBar.GetToolBarCtrl().CheckButton(ID_TB_BUTTON4);
return TRUE;
}

void Dialog2::CreateToolBar()
{
DWORD dwStyle = WS_CHILD| WS_VISIBLE| CBRS_ALIGN_TOP|
CBRS_SIZE_FIXED| CBRS_TOOLTIPS| CBRS_FLYBY;

dwStyle |= WS_TABSTOP; // if drop down needed, gets called OK
m_pwndToolbar = new CMyToolBar;
m_pwndToolbar.Create(this, dwStyle, IDC_VIEW_TOOLBAR);
int toolbarId = MY_TOOLBAR_ID; // comes from somewhere else
m_pwndToolbar.LoadToolBar(toolbarId);
m_pwndToolbar.SetupDropDown();
m_pwndToolbar.SetButtonStyle(4, TBBS_CHECKGROUP);
m_pwndToolbar.SetButtonStyle(5, TBBS_CHECKGROUP);
m_pwndToolbar.SetButtonStyle(6, TBBS_CHECKGROUP);
m_pwndToolbar.SetButtonStyle(7, TBBS_CHECKGROUP);
}

BOOL CMyToolBar::SetupDropDown()
{
SetButtonInfo(0, ID_PATH, TBBS_SEPARATOR, XBU(90));
CRect rc;
GetItemRect(0, &rc);
rc.bottom = rc.top + YBU(100);
m_wndPathCtrl.Create(CBS_DROPDOWNLIST| CBS_OWNERDRAWVARIABLE|
CBS_HASSTRINGS| WS_VISIBLE| WS_TABSTOP| WS_VSCROLL|
WS_GROUP,
rc, this, ID_PATH);
m_pwndPathCtrl.UpdateList(); // refreshes the list of items
return TRUE;
}

Tomas Vera

unread,
Mar 7, 2003, 2:47:24 PM3/7/03
to
OK. Found the basic problem:
Other code is disabling the Owner Draw control. That's why you don't go to it
when using the arrows. However, still don't know why you can "tab" over to
it.....
0 new messages