Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » How to set focus to a control-bar? Collapse All
Subject Author Date
Offer Har Nov 6, 2008 - 2:20 PM

I need to set focus to a control-bar when the user clicks on a button - how to do this?


Thanks.

Technical Support Nov 14, 2008 - 12:14 PM

Please compile and run the <span class="newgreen">ProfStudio</code> sample application. You can press the Ctrl+Shift+C keys. This will activate the Class View bar and its child window will become focused. Now you can try to hide the Class View bar, auto-hide it, float it, dock it into some tabbed group with other bars, make it non-selected bar in tabbed group and do everything else with it. You can press the Ctrl+Shift+C keys after each operation with the Class View bar. It will become visible again. Its child window will become focused again. The Class View bar is created in the <span class="newgreen">ProfStudio</code> sample application using the ID_VIEW_BAR_CLASS_VIEW identifier. This identifier is also present in menu and it’s used in the accelerator table entry with the Ctrl+Shift+C key combination. Believe or not, pressing the Ctrl+Shift+C keys is just sending the WM_COMMAND message to the main frame window and specifying the ID_VIEW_BAR_CLASS_VIEW value in its WPARAM parameter.

Offer Har Nov 17, 2008 - 9:47 AM

Yep... it was all in the flag.


By the way, this is much simpler then how you explained it, all I had to do for this is a one-line:


 



CExtControlBar::DoFrameBarCheckCmd(pParentFrame, pBar->GetDlgCtrlID(), false);



 

Offer Har Nov 17, 2008 - 9:13 AM

Dear Support,


I think I know why we have this miss-communication...


I use the main-frame OnBarCheck like this:



BOOL CBaseMainFrm::OnBarCheck(UINT nID)
{
    return CExtControlBar::DoFrameBarCheckCmd(this, GetSmallID(nID), true);
}


Note that last parameter is true, and in the help file it’s written:


<dt>bResizableCheckmarks </dt>
Check mark mode (for resizable control bars only). If this mode is set to true, the show/hide command turns on or turns off visibility of the resizable bar. If false, the method shows the invisible bar wherever it is and sets focus on it.

So, I use the command to show/hide the control bar, and I need in another place to set focus to it even if it shown, that is, call the same function with true, so your approach of sending WM_COMMAND will not work.


I see in the help that I can also just call  DoFrameBarCheckCmd, in the article How to show a hidden control bar, and then I can set the third parameter to false, and the focus will be handled correctly.


Can it be that we were having this long conversation over one flag...?

Technical Support Nov 7, 2008 - 5:09 AM

No problem. The following code activates/showa a control bar in any state, set focus on it:

CExtControlBar * pBar = . . .
CFrameWnd * pMainFrame = . . .
                pMainFrame->SendMessage( WM_COMMAND, WPARAM( pBar->GetDlgCtrlID() ) );
This makes the control bar’s child window focused. This child window also can forward focus to any of its child windows.

Offer Har Nov 7, 2008 - 2:30 PM

Would like to add that this should work also when the control-bars are tabbed, in which case the tab of the control-bar should be selected. The proposed solution does not work for such case.

Technical Support Nov 10, 2008 - 11:52 AM

The proposed solution works for tabbed case, for auto-hidden case, for floating case. Sending the WM_COMMAND message is exactly the same what popup menu do when you are displaying control bar via invoking menu command. The proposed solution may not work if some or all of your control bars does not have message map entries in main frame’s message map. And of course, it requires the CMainFrame::OnBarCheck() and CMainFrame::OnUpdateControlBarMenu() methods like implemented in the main frame class of the ProfStudio sample application.

Offer Har Nov 10, 2008 - 4:01 PM

Dear Support,


I think you do not understand why I ask.


The control-bar is already displayed, but does not have the focus - i want to bring him to the front - it is already shown... but in the z orer he’s not on top.

Technical Support Nov 11, 2008 - 9:27 AM

) If you have some resizable control bar with ID_MY_BAR identifier in your main frame window:

CExtControlBar * pBar = . . .
CFrameWnd * pMainFrame = . . .

2) If your main frame has valid message map entries for this bar:
    ON_COMMAND_EX( ID_MY_BAR, OnBarCheck )
                ON_UPDATE_COMMAND_UI( ID_MY_BAR, OnUpdateControlBarMenu )

3) And, finally, if your main frame window has correctly implemented OnBarCheck() and OnUpdateControlBarMenu() handler methods:
 void CMainFrame::OnUpdateControlBarMenu(CCmdUI* pCmdUI)
{
                CExtControlBar::DoFrameBarCheckUpdate(
                                this,
                                pCmdUI,
                                false // ATTENTION: this parameter is false - not true
                                );
}

BOOL CMainFrame::OnBarCheck(UINT nID)
{
                return
                                CExtControlBar::DoFrameBarCheckCmd(
                                                this,
                                                nID,
                                                false // ATTENTION: this parameter is false - not true
                                                );
}

Then the following code will do what you need:
pMainFrame->SendMessage( WM_COMMAND, WPARAM(pBar->GetDlgCtrlID()) );

And the following code is exactly the same:
pMainFrame->SendMessage( WM_COMMAND, ID_MY_BAR );

Sending the WM_COMMAND to main frame window with bar’s identifier in WPARAM parameter will show control bar, make its caption active and its children window focused. This command will show auto-hidden control bar or hidden control bar floating or docked. It will bring to top tab page in tabbed bar group. It will activate already shown bar and set focus to bar’s child window. Of course, the items 1, 2 and 3 in the list above should be true

Offer Har Nov 13, 2008 - 8:15 AM

This is all nice, and I have this implemented, but this DOES NOT bring the control-bar to the front of the Z-Order, and DOES NOT faint it’s title bar in in orange in the black theme.


I need something that will simulate the click on the title-bar of teh control-bar so it will move to front.


The scenario is that I have a lot of control-bars open, and when the user is clicking on some button, he expect to see the control-bar he is looking for in front of all teh others.

Technical Support Nov 13, 2008 - 1:29 PM

You asked a very simple question. Our answer was also very simple: you should send a WM_COMMAND message to your main frame window and specify control bar’s dialog control identifier in the WPARAM parameter. This is the same as clicking on the caption of displayed control bar. This is the same as invoking control bar displaying command from menu or toolbar. If this simple and extremely often used thing is not working in your application, then the control bar displaying command in menu must also not work. This is the first and the most important thing to check. Both programmatically send WM_COMMAND message should work equally in your project or may not work. If the both are not working, then you didn’t implemented message map entry like we asked you in one of our recent messages or you have some other magic issue(s) in your project. If the WM_COMMAND is not working when the menu item is OK or vice versa, then you need to get a coffee break and only then check everything as carefully and accurately as possible.

Offer Har Nov 13, 2008 - 1:42 PM

Let me give you an example why your approach is wrong - what happens if the control-bar is displayed... it will be hidden... this is wrong. I just want it to get focus!

Offer Har Nov 13, 2008 - 1:39 PM

I tried it and it did not work... I wouldn’t have been asking again and again had it worked. Aperantly it is  not the same as clikcing the control-bar title.


Why can’t there be some simple function in the control-bar SetFocus()?

Offer Har Nov 7, 2008 - 2:14 PM

Tried it, but it did not work.


If there are two control bars, and the one I want to give the focus to is below another it does not comes to front.


Is there any way to simulate the click on the title of the control bar?