How do I ... save toolbar state

D

David Thielen

Hi;

Creating a toolbar is easy. But when the user exists Word they may have
moved it, deleted/hidden it, or changed the buttons in it. I figure what they
do I want to persist (I hate how Acrobat always blasts the toolbar back up
each time Word starts).

So, how best to do this? The items I see are:
1. Where is it displayed - position and size. How do I get this and then
reset it?
2. If marked hidden, how do I create it but not show it. And how do I get
this info on close?
3. If they changed the buttons, how do I save and then recreate that?
4. If they changed the bitmaps in the buttons - how do I get that info to
save on close and how do I set this on start?

I'm hoping Word has something that does most/all of this since it must be
done for Word's own toolbars.
 
P

Peter Huang [MSFT]

Hi

Here I assume the toolbar is created by your code, because all the word's
toolbar is created by word's buildin code.
I think a better way was to delete the toolbar when the addin is loaded and
then call the Create Toolbar procedure to recreate the Toolbar, so that it
looks just as we first create it.

I think word's reset function just recreate the toolbar just as it create
at the very beginning time.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hello;

Yes it is my toolbar I create programatically.

The problem with that approach is what if the user does not want my toolbar.
Then everytime I start I put it back up there which is very annoying. Or they
do want it, but they want it docked in a different location. So each time
Word starts they have to move it.

This is terrible. Adobe Acrobat does this and it makes users dislike the
software.

So I ask again, how do I save if it's up, if so, where and is it docked, so
I can start it like that next time.

And if it is not up, how can I create it so it is not visible, but it can be
made visible by the user if they want it back?
 
P

Peter Huang [MSFT]

Hi

I think we can set/get the four property of CommandBar(Toolbar)

cb.Visible = true; //if it is up/displayed
cb.Position = MsoBarPosition.msoBarFloating;//if it is docked and where is
it docked.
cb.Left = 0; //the detailed position of the commandbar
cb.Top = 0;//the detailed position of the commandbar


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

Tom Winter

David,

Are you deleting your toolbar when your add-in shuts down? If you just leave
it there, Word will keep it around in whatever state the user left it.
Toolbar "changes" are always stored in a template (you know,
Application.CustomizationContext). I find the best way to do toolbars is to
have my own .DOT file, where the toolbar was created at DESIGN-TIME, then at
run-time, my add-in loads the .DOT file as a global add-in and then sinks up
to the buttons. Any changes the user makes are saved back into the .DOT file
by Word. For an example of this, you can check out my (VB6) sample project,
Dynamic Menus COM Add-In Sample Project:
http://www.amosfivesix.com/downloads/
 
D

David Thielen

Hi;

Ok, the Position and Visible work great using this.

However...

If the toolbar is docked and placed to the right of an existing toolbar,
Word then pushes it down below the others - so it changes Top - but not Left.

If the toolbar is floating it changes it from a a 1x6 grid to a 2x3 grid.

Any ideas?
 
P

Peter Huang [MSFT]

Hi

I think you may try TOM's suggestion that stored the information in the dot
file.
e.g.
try
{
CommandBarButton tcbb =(CommandBarButton
)wdApp.CommandBars.FindControl(oMissing,oMissing,"Test",oMissing);
if (tcbb != null)//if it has been created, we just add the event handler
{
Debug.WriteLine("Add handler");
tcbb.Click+=new _CommandBarButtonEvents_ClickEventHandler(cbb_Click);
}
else //If the commandbutton is not created before, then we create it.
{
cb = wdApp.CommandBars.Add("TestToolbar",oMissing,oMissing,false);
cb.Visible = true;
cb.Position = MsoBarPosition.msoBarFloating;
cb.Left = 0;
cb.Top = 0;
cbb =
(CommandBarButton)cb.Controls.Add(MsoControlType.msoControlButton,oMissing,o
Missing,oMissing,false);
cbb.Caption = "Test";
Debug.WriteLine(cbb.Id);
cbb.Tag = "Test";
cbb.Click+=new _CommandBarButtonEvents_ClickEventHandler(cbb_Click);
}
}
catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=,
If the toolbar is docked and placed to the right of an existing toolbar,
Word then pushes it down below the others - so it changes Top - but not Left.
Check the .RowIndex property in the Office object model Help files.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=,
thank you.
You're most welcome. I value what you've posted back to the
groups highly and am happy to help where I can :)
Have you considered writing a book on Word Add-ins? I'd buy it.
Addins? I don't know that much about COM-Addins that I'd trust
myself :) My knowledge is more in the area of the Word object
model and yes, I've considered it. There are two problems
involved though:
- most publishers (and certainly all those who publish in
English) require one to go through the IRS red-tape

- they also claim there's no market for Word books

FWIW, I'm currently working out the details for something like
this in German :) Publishing date would be end of this year, if
we can get all the wrinkles ironed out.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8
2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top