Thursday, July 5, 2007

How to hide Office menu especially Word 2007 Ribbon?

From Dmwiki

Jump to: navigation, search

There is a requirement that wrapped CHtmlView into a COM for previewing all kinds of office document. It must hide all menu and toolbars for increase the viewing area and should support office XP\2003\2007.

For Office 2003 it is easy to do that. But for Word 2007, It doesn’t work! It stumppe us for several weeks. I googled and also posted this question in msdn newsgroup, nobody gives the correct solution.

Some MVP of Office said the new Office interface was consciously designed to NOT allow the developer as much freedom with which tools are provided to the user. You won't be able to recover this realestate completely.

Solution for Office 2003:

 Dim iCounter As Integer 
 For iCounter = 1 To CommandBars.Count 
 Application.CommandBars(iCounter).Enabled = False 
 Next

Possible solution for Word 2007 we have tried:

One possibility would be to define and include an XML part for the Ribbon in the document's file structure. The Ribbon XML can set the ribbon to start from scratch( startFromScratch=TRUE) in CustomUI.xml. which would make it "empty". But you can't get rid of the big, round "Office" button that will contain a limited number of basic commands. But this could not hide all the ribbon area completely.The big round button and quick access area and some other command,such as "help",will remain.


Beyond that, the object model provides ToggleRibbon method, which will cycle between "collapsing" the ribbon to look like an old-style MenuBar and expanding it again.


The third possible solution is trying the Windows API to find the windows handle of the ribbon, and then use API to hide the windows. This solution did could hide the ribbon but another problem is we could not minimize it.

Correct Solution for Word 2007:

When an Office app is OLE hosted, you can toggle on and off the UI using an OLE command. Like this:

   #include "exdispid.h"
   OLECMDF cmd = QueryStatusWB( OLECMDID_HIDETOOLBARS);
   if( !(cmd & OLECMDF_LATCHED))
       ExecWB(OLECMDID_HIDETOOLBARS, OLECMDEXECOPT_PROMPTUSER, NULL, NULL);

 

No comments: