Roshan Davis
asked on
Word Automation : Enable Customize Menu Item
In VB, using
application.CommandBars.Di sableCusto mize = 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 :)
application.CommandBars.Di
How can i do this in MFC Word Automation
_Application oApp(oDoc.GetApplication()
_CommandBars oCB = oApp.GetCommandBars();
oCB.????????
Rosh :)
oCB.put_DisableCustomize(0 );
Cause DisableCustomize is a property of _CommandBars interafce.
[id(0x60030019), propput, helpcontext(0x000007e0)] void DisableCustomize([in] VARIANT_BOOL rhs);
[id(0x60030019), propput, helpcontext(0x000007e0)] void DisableCustomize([in] VARIANT_BOOL rhs);
ASKER
error C2039: 'DisableCustomize' : is not a member of '_CommandBars'
ASKER
Showing the error
error C2039: 'put_DisableCustomize' : is not a member of '_CommandBars'
Rosh :)
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.
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.
ASKER
can u explain little bit more that how to use this in COM
ASKER
Hi,
I added some code in mso9.cpp like...
void _CommandBars::DisableCusto mize(BOOL bNewValue)
{
static BYTE parms[] =
VTS_BOOL;
InvokeHelper(0x60030019, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
bNewValue);
}
Still it is not working...
:(
I added some code in mso9.cpp like...
void _CommandBars::DisableCusto
{
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(&sp CmdBars);
spCmdBars->put_DisableCust omize(0);
}
Anyway, depending on what Office you use, DisableCustomize property may not be impelmented or may have different DISPID.
#import "c:\Program Files\Common Files\Microsoft Shared\Office10\MSO.DLL" rename_namespace("Office")
using namespace Office;
#import "C:\Program Files\Microsoft Office\Office10\MSword.olb
void MyFunc()
{
...//somehow get an IDispatch poiter to _Application, let's say 'Application'
CComQIPtr spApp(Application);
CComPtr < Office::_CommandBars> spCmdBars;
spApp->get_CommandBars(&sp
spCmdBars->put_DisableCust
}
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.
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
ASKER
I'm able to see those methods...
And I tried these methods in MSWord Macro, that is working "Application.CommandBars.D isableCust omize = True"
But not in my MFC WOrd container (using COleDocObjectItem) appliaction
Rosh :)
And I tried these methods in MSWord Macro, that is working "Application.CommandBars.D
But not in my MFC WOrd container (using COleDocObjectItem) appliaction
Rosh :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank :) I wil check that
ASKER
SCODE sc = m_lpDispatch->Invoke(dwDis pID, IID_NULL, 0, wFlags,
&dispparams, pvarResult, &nArgErr);
Yes I checked that code
sc -> 0
pvarResult -> NULL
&excepInfo all contents are -> 0
nArgErr -> 0
:(
&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?
But you didn't get the desired result?
ASKER
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->QueryIn terface(II D_IDispatc h,(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(vtInd ex));
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(vt Type,vtID, vtNull,vtN ull,vtNull ));
oCCtr.SetEnabled(false);
:(
But i can enable/disable other buttons like "Print"
_Document oDoc;
IDispatch *pDisp;
pItem->m_lpObject->QueryIn
oDoc.AttachDispatch(pDisp)
_CommandBars oComms(oDoc.GetCommandBars
VARIANT vtIndex;
vtIndex.vt = VT_BSTR;
CString csIndex("Standard");
vtIndex.bstrVal = csIndex.AllocSysString();
CommandBar oComm(oComms.GetItem(vtInd
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(vt
oCCtr.SetEnabled(false);
:(
ASKER
You can find the similar project with *SAME* problem in codeproject also
http://www.codeproject.com/com/xoffice.asp
Rosh
http://www.codeproject.com/com/xoffice.asp
Rosh
ASKER
I will increase points to 1000 :)
lol
ASKER
I'm Leaving for the day...
ASKER
You can find the same problem in the given sample project (in the link)
Rosh :)
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...
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").
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").
ASKER
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
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.
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.
ASKER
I'm using mso9.dll
I wil check mso.dll
Rosh :)
I wil check mso.dll
Rosh :)
with any luck? :)
ASKER
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("T ools").Con trols("&Cu stomize... ").Delete
CommandBars("Toolbar List").Enabled = False
End Sub
you can figure out the C++ syntax for that :)
enjoy.
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("T
CommandBars("Toolbar List").Enabled = False
End Sub
you can figure out the C++ syntax for that :)
enjoy.
ASKER
Actually I started from that code only :(
And the 'Customize...' item is still there?
I'm dazzled.
I'm dazzled.
ASKER
still showing in disable state :(
ASKER
I can change other items like "Options..."
ASKER
Still having the issue, but I'm closing this thread
thankx for ur helpful comments
Rosh :)
thankx for ur helpful comments
Rosh :)
cleanup time :)
ASKER
:)
ASKER
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 :)
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?
You refer to the Normal.dot or what template exactly?
ASKER
Yes Normal.dot
I hav some other template say "Roshan.dot". I hav to set this template as default while opening a document
Rosh :)
I hav some other template say "Roshan.dot". I hav to set this template as default while opening a document
Rosh :)
Gimme 15mins (approx)
ASKER
Found one function in the class "_Document"
Function Name is "SetAttachedTemplate"
But the same thing in VB ("AttachedTemplate") showing error
Function Name is "SetAttachedTemplate"
But the same thing in VB ("AttachedTemplate") showing error
ASKER
Application.Documents(1).A ttachedTem plate = "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
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 ?
ASKER
>>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 :)
No. Any document opening after setting "Roshan.dot " should open in this document ... is that possible ?
Rosh :)
ASKER
>> Gimme 15mins
Take 16 mins ;-)
Take 16 mins ;-)
I think you have to pass a Template object to AttachedTemplate property.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/office97/html/output/F1/D4/S5ABEA.asp
http://msdn.microsoft.com/library/en-us/off2000/html/woobjtemplate.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/office97/html/output/F1/D4/S5ABEA.asp
http://msdn.microsoft.com/library/en-us/off2000/html/woobjtemplate.asp
ASKER
Don't mind, Can u quote some code
ASKER
But I'm able to set the Normal.dot by assigning thru string value
eg:
Application.Documents(1).A ttachedTem plate = "Normal" or
Application.Documents(1).A ttachedTem plate = "Normal.dot"
Rosh :)
eg:
Application.Documents(1).A
Application.Documents(1).A
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.
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"
Then you can get it from the Templates collection object (I hope :) and pass it to AttachedTemplate property.
ASKER
I will try this, probably tomorrow, nd will assign points
Thankx
Thankx
np, hope it helps
ASKER
Hi,
ASKER
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\\WordScri pt.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(v tTemplate) ;
But it is crashing in the line oDocs.Add :(
VARIANT vtTemplate, vtFalse, vtTrue;
_Application oApp(oDoc.GetApplication()
Documents oDocs(oApp.GetDocuments())
Template oTmpl = oApp.GetNormalTemplate();
CString csDOT("D:\\Share\\WordScri
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
oDoc.SetAttachedTemplate(v
But it is crashing in the line oDocs.Add :(
ASKER
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
:((
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
:((
ASKER
:))
Very near to the result...
Plz tell me How can I use the below function in VC++ automation
Application.AddIns.Add("C: \Roshan.do t")
I cannot find any "AddIns" class in mso9.cpp, but I found GetAddins() function for _Application class....
Rosh :)
Very near to the result...
Plz tell me How can I use the below function in VC++ automation
Application.AddIns.Add("C:
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 ;)
ASKER
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);
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(
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,
ASKER
Ok then :)
Sorry for being so late at the office ;) (just kiddin')
Sorry for being so late at the office ;) (just kiddin')
ASKER
ha ha :)
ASKER
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.OLERequestPendingTimeo ut = 99999
I didn'y find anything in VC++, plz help i wil add 500 points...
"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.OLERequestPendingTimeo
I didn'y find anything in VC++, plz help i wil add 500 points...
ASKER
Yes I got thankx
AfxOleGetMessageFilter()-> EnableBusy Dialog(FAL SE);
AfxOleGetMessageFilter()->
Glad you found :)
...Again, just arrived at the office
...Again, just arrived at the office