Link to home
Start Free TrialLog in
Avatar of Roshan Davis
Roshan DavisFlag for United States of America

asked on

Word Automation : Enable Customize Menu Item

In VB, using
application.CommandBars.DisableCustomize = False we can anble the Custimize menu item ( got info from MSDN )

How can i do this in MFC Word Automation

      _Application oApp(oDoc.GetApplication());
      _CommandBars oCB = oApp.GetCommandBars();
      oCB.????????

Rosh :)
Avatar of nonubik
nonubik

oCB.put_DisableCustomize(0);
Cause DisableCustomize is a property of _CommandBars interafce.
[id(0x60030019), propput, helpcontext(0x000007e0)] void DisableCustomize([in] VARIANT_BOOL rhs);
Avatar of Roshan Davis

ASKER

error C2039: 'DisableCustomize' : is not a member of '_CommandBars'
Showing the error
error C2039: 'put_DisableCustomize' : is not a member of '_CommandBars'

Rosh :)
Well, I searched the COM and thought your _CommandBars coclass is for _CommandBars interface.
You can just browse the _CommandBars class to see the appropriate method.
Or use COM, this should work ;)
Meanwhile I'll try myself to get a "word" header to see how's _CommanBars class.
can u explain little bit more that how to use this in COM
Hi,

I added some code in mso9.cpp like...

void _CommandBars::DisableCustomize(BOOL bNewValue)
{
      static BYTE parms[] =
            VTS_BOOL;
      InvokeHelper(0x60030019, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
             bNewValue);
}

Still it is not working...

:(
Ok. On my side I have Office XP, so the .dll and .odl full path may differ from yours

#import "c:\Program Files\Common Files\Microsoft Shared\Office10\MSO.DLL" rename_namespace("Office") named_guids
using namespace Office;

#import "C:\Program Files\Microsoft Office\Office10\MSword.olb" raw_interfaces_only named_guids

void MyFunc()
{
...//somehow get an IDispatch poiter to _Application, let's say 'Application'
CComQIPtr  spApp(Application);
CComPtr < Office::_CommandBars> spCmdBars;
spApp->get_CommandBars(&spCmdBars);
spCmdBars->put_DisableCustomize(0);
}


Anyway, depending on what Office you use, DisableCustomize property may not be impelmented or may have different DISPID.
In order to be sure:
Open OLE/COM object viewer (VS tools)
Expand 'Interfaces'
Rightclick on '_CommandBars'
Choose 'View...' and press 'ViewTypeInfo'
Expand 'Methods'
Search 'DisableCustomization' and there you'll see the dispid and so on.
I meant 'DisableCustomize' ... :)   propput
I'm able to see those methods...

And I tried these methods in MSWord Macro, that is working "Application.CommandBars.DisableCustomize = True"

But not in my MFC WOrd container (using COleDocObjectItem) appliaction

Rosh :)
ASKER CERTIFIED SOLUTION
Avatar of nonubik
nonubik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank :) I wil check that
SCODE sc = m_lpDispatch->Invoke(dwDispID, IID_NULL, 0, wFlags,
            &dispparams, pvarResult, &nArgErr);


Yes I checked that code

sc -> 0
pvarResult -> NULL
&excepInfo all contents are -> 0
nArgErr -> 0

:(
Well, a sc of 0 means S_OK HRESULT. The call succeeded.
But you didn't get the desired result?
yes, I think the problem is only for "Customize" itz deisabled in default...
But i can enable/disable other buttons like "Print"
            _Document oDoc;
            IDispatch *pDisp;
            pItem->m_lpObject->QueryInterface(IID_IDispatch,(void**)&pDisp);
            oDoc.AttachDispatch(pDisp);

            _CommandBars oComms(oDoc.GetCommandBars());
            VARIANT vtIndex;
            vtIndex.vt = VT_BSTR;
            CString csIndex("Standard");
            vtIndex.bstrVal = csIndex.AllocSysString();
            CommandBar oComm(oComms.GetItem(vtIndex));
            VARIANT vtType,vtID,vtNull;
            vtType.vt = VT_I4;
            vtID.vt = VT_I4;
            vtType.lVal = 1;
            vtID.lVal = 2521;
            vtNull.vt = VT_ERROR;
            vtNull.scode = DISP_E_PARAMNOTFOUND;
            CommandBarControl oCCtr(oComm.FindControl(vtType,vtID,vtNull,vtNull,vtNull));
            oCCtr.SetEnabled(false);

:(
You can find the similar project with *SAME* problem in codeproject also

http://www.codeproject.com/com/xoffice.asp

Rosh
I will increase points to 1000 :)
lol
I'm Leaving for the day...
You can find the same problem in the given sample project (in the link)
Rosh :)
Well, I'm not registered on codeproject ;)
But I implemented the _CommandBars class using the type lib from my office 10 mso.dll and it HAS the SetDisableCustomize.
And it's the same implementation as you posted. Now, I didn't test it if it really works. Maybe it doesn't work on office2k...
Well, I downloaded mso9.dll, open it with typelib and the _CommandBars interface does not have DisableCustomize property at all. The DisplayFonts property (dispid 0x60030017) is the last one.
So it seems that in office XP they added 2 more properties.

If you say you use office 9 (2k) that's the problem (you mentioned a "mso9.cpp").
But I'm using Office 2003 in my machine... :(
I can send you that Codeproject code, so u can see the same thing in ur machine also
What typelib do you import in your project?
mso9.dll, mso.dll form Office10? Cause that's important, not necessarly the Office version used on your machine. Tha fact that you have Office 2003 installed allows you to use office 10 mso.dll.
I'm using mso9.dll

I wil check mso.dll

Rosh :)
with any luck? :)
no luck, becoz most of the clients who r using the Office 2000 only...so i cannot change that to mso.dll :(
In this case, you cannot call DisableCustomize. Not implemented in mso9.dll (_CommandBars interface)

But I found out some workaround (which I think it's the exact implementation of DisableCustomize for office10 and up ;)


The following sample subroutine turns off the Toolbar List shortcut menu and deletes the Customize menu option, which prevents others from modifying the menus and toolbars in a custom application:
Sub DisableCustomize()
        Application.CommandBars("Tools").Controls("&Customize...").Delete
        CommandBars("Toolbar List").Enabled = False
   End Sub

you can figure out the C++ syntax for that :)
enjoy.
Actually I started from that code only :(
And the 'Customize...' item is still there?
I'm dazzled.
still showing in disable state :(
I can change other items like "Options..."
Still having the issue, but I'm closing this thread
thankx for ur helpful comments

Rosh :)
cleanup time :)
:)
Hi friend,

I think u can solve thism, I will assign 500pts for you..
How can I change the default template of Embded Word of my application..

Rosh :)
:)  Hi,

You refer to the Normal.dot or what template exactly?
Yes Normal.dot

I hav some other template say "Roshan.dot". I hav to set this template as default while opening a document

Rosh :)
Gimme 15mins (approx)
Found one function in the class "_Document"

Function Name is "SetAttachedTemplate"

But the same thing in VB ("AttachedTemplate") showing error
Application.Documents(1).AttachedTemplate = "Roshan.dot"

Error is
Run-time error '5947':
Could not change document template.


I copied that DOT to Templates folder, also checked with Full Path mode
You can use Add method of the _Document object to create a new document using a custom template. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/off2000/html/womthAddDocumentsObj.asp

Do you want to change the template of an already open (created) document ?
>>Do you want to change the template of an already open (created) document ?

No. Any document opening after setting "Roshan.dot " should open in this document ... is that possible ?

Rosh :)
>> Gimme 15mins

Take 16 mins ;-)
Don't mind, Can u quote some code
But I'm able to set the Normal.dot by assigning thru string value

eg:
Application.Documents(1).AttachedTemplate = "Normal"       or

Application.Documents(1).AttachedTemplate = "Normal.dot"

Rosh :)
Yep, because it is allready in the Templates collection object.
First you need to add your template to the Templates collection object by one of the four methods in the link above You can try
Documents.Add("Roshan.dot", False, wdNewBlankDocument, False) . Here I added an invisible one.

Then you can get it from the Templates collection object (I hope :) and pass it to AttachedTemplate property.
I will try this, probably tomorrow, nd will assign points

Thankx
np, hope it helps
Hi,

I added the code like thsi

      VARIANT vtTemplate, vtFalse, vtTrue;

      _Application oApp(oDoc.GetApplication());
      Documents oDocs(oApp.GetDocuments());

      Template oTmpl = oApp.GetNormalTemplate();
            
      CString csDOT("D:\\Share\\WordScript.dot");

      vtTemplate.vt = VT_BSTR;
      vtTemplate.bstrVal = csDOT.AllocSysString();

      vtFalse.vt = VT_BOOL;
      vtFalse.boolVal = VARIANT_FALSE;

      vtTrue.vt = VT_BOOL;
      vtTrue.boolVal = VARIANT_TRUE;

      vtNull.vt = VT_ERROR;
      vtNull.scode = DISP_E_PARAMNOTFOUND;

      Template oTemplate = oDocs.Add(&vtTemplate, &vtFalse, &vtNull, &vtFalse);  <---------------------- CRAAAAAAASHING HERE


      oDoc.SetUpdateStylesOnOpen(TRUE);
      oDoc.SetAttachedTemplate(vtTemplate);

But it is crashing in the line oDocs.Add :(
I debugged and got the exception message

T.h.e. .A.d.d. .m.e.t.h.o.d. .o.r. .p.r.o.p.e.r.t.y. .i.s. .n.o.t. .a.v.a.i.l.a.b.l.e. .b.e.c.a.u.s.e. .t.h.i.s. .d.o.c.u.m.e.n.t. .i.s. .i.n. .a.n.o.t.h.e.r. .a.p.p.l.i.c.a.t.i.o.n.....

So is there any workaround for this

:((
:))

Very near to the result...
Plz tell me How can I use the below function in VC++ automation

Application.AddIns.Add("C:\Roshan.dot")

I cannot find any "AddIns" class in mso9.cpp, but I found GetAddins() function for _Application class....


Rosh :)
Just arrived at the office, I'll drink my coffee and dig for you ;)
Thank you friend, Got the solution

Added the following code nd Its working... ur comments helped me so much... will give u 500 pts ;)

      _Application oApp(oDoc.GetApplication());

      OLECHAR *polechAdd = L"Add";
      DISPID dispID = 0;

      LPDISPATCH lpDispatch = oApp.GetAddIns();

      lpDispatch->GetIDsOfNames(IID_NULL, &polechAdd, 1,
                              LOCALE_SYSTEM_DEFAULT,
                              &dispID);

    VARIANT vtArg[1];
    DISPPARAMS dpAdd;
    dpAdd.cArgs = 1;
    dpAdd.cNamedArgs = 0;
    dpAdd.rgvarg = vtArg;

      vtArg[0].vt = VT_BSTR;        
    vtArg[0].bstrVal = vtTemplate.bstrVal;

      lpDispatch->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &dpAdd, NULL, NULL, NULL);
Plz collect ur points http:Q_21051568.html

Rosh :)
Ok then :)
Sorry for being so late at the office ;)   (just kiddin')
ha ha :)
Automation giving the error while invoking the SpellCheck

"This action cannot be completed because the other program is busy. Choose 'Swtich To' to activate the busy program and correct the problem"

The solution in VB is

App.OLERequestPendingTimeout = 99999


I didn'y find anything in VC++, plz help i wil add 500 points...
Yes I got thankx

      AfxOleGetMessageFilter()->EnableBusyDialog(FALSE);       
Glad you found :)
...Again, just arrived at the office