Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Docking a toolbar at specified position
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Docking a toolbar at specified position

 Post Reply Post Reply
Author
Message
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 886
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post Topic: Docking a toolbar at specified position
    Posted: 01 May 2020 at 4:42pm
We allow a single toolbar docked at the top of our app under the ribbon. We want the out-of-the-box position of the bar to be centered wrt the frame.

I found the toolbar GetToolbarInfo (and Set...) APIs. Even though they are public, they are useless since the returned structure is not public. I'm not sure if will even help if I had access to the structure. I have found when I save the command bars, CJ writes an "xPos" and other data into the registry for the bar.

So I thought perhaps I could "seed" the registry on the first run of the app and get the bar to move over. But, I have found that even if I manually edit the xPos value in the registry, the bar doesn't move. If I move it dynamically by dragging it and save the bar layout, that value changes. But, changing it manually has no effect. I have stepped thru the load bar layout code and see that toolbar info being seeded with it and even a SetWindowPos call being made with the point (and I see the xPos I set in the registry is used in that call). But when the bar displays, it stays where I last put it.

So it seems the reg entry isn't really used. Except that if I delete the entire hive for that bar ("Application-Bar1" for my bar), it goes back to the default pos at the left of the dockbar/app frame. But, just delete the xPos and yPos instead and CJ still places it as the position I moved it to before saving the bar layout.

Anyone have a suggestion of either how to influence the initial position (xPos is what I care about) or just where CJ is really getting the position from?
Back to Top
dbrookes View Drop Down
Groupie
Groupie


Joined: 30 August 2019
Location: Australia
Status: Offline
Points: 70
Post Options Post Options   Thanks (1) Thanks(1)   Quote dbrookes Quote  Post ReplyReply Direct Link To This Post Posted: 03 May 2020 at 8:43pm
Hi rdhd.

We do a similar thing in our application by providing a default layout which provide a base for a user-specific layout. I think the MRUDockLeftPos key is used to offset the toolbar.

An alternative would be to do it programmatically, which may be better. At least this way you could account for different frame widths and DPI scaling.
    const CXTPClientRect rcClient(this);
    const CXTPWindowRect rcToolBar(pToolBar);
    CRect rcDock{ rcToolBar };
    rcDock.left = rcClient.Width()/2 - rcToolBar.Width()/2;
    rcDock.right = rcClient.Width()/2 + rcToolBar.Width()/2;
    pCommandBars->DockCommandBar(pToolBar, rcDock, pToolBar->GetDockBar());
I guess you would need to find a way to not do this on every startup :)
Back to Top
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 886
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post Posted: 08 May 2020 at 2:52pm
Hi dbrookes. With all the CJ stuff, I didn't even think about the MFC style docking calls.

CJ uses the ScreenToClient API when docking so I used your code with a bit of modification. I got the client rect of the app and called ClientToScreen on it. I also then added the .left member of the result to the left and right calculations.
Back to Top
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 886
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post Posted: 08 May 2020 at 3:17pm
By the way, since I call SaveCommandBars on exit and LoadCommandbars on launch, I didn't have to do anything special to detect a "first" startup. I simply dock the bar and then call LoadCommandBars. So, if I start clean and set to the middle and move the bar, I can exit and restart and it resets the pos to where I moved it to before the last exit.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.188 seconds.