Disable Popup Menu in MS Office

You can disable or delete the context menu item in MS Word or Excel by VBA programming.

Word:

OA1.CreateNew “Word.Document”
Set objWord = OA1.ActiveDocument
objWord.Application.CommandBars(”Text”).Controls(”Cu&t”).Enabled = False
objWord.Application.CommandBars(”Text”).Controls(”&Copy”).Enabled = False
objWord.Application.CommandBars(”Text”).Controls(”&Paste”).Enabled = False
‘delete item directly
‘objWord.Application.CommandBars(”Text”).Controls(1).Delete
‘objWord.Application.CommandBars(”Text”).Controls(2).Delete ….

Excel

OA1.Open “c:\text.xls”
Set objExcel = OA1.ActiveDocument
objExcel .Application.CommandBars(”Cell”).Controls(”Cu&t”).Enabled = False
objExcel .Application.CommandBars(”Cell”).Controls(”&Copy”).Enabled = False
objExcel .Application.CommandBars(”Cell”).Controls(”&Paste”).Enabled = False
‘delete item directly
‘objExcel .Application.CommandBars(”Cell”).Controls(1).Delete
‘objExcel .Application.CommandBars(”Cell”).Controls(2).Delete ….

How to verify whether the open document is modified

If you are developing the destop application with the office viewer component, you can use the “IsDirty” method to verify whether the open document is modified. When the open file has any modification, the IsDirty method return TRUE. After you save the document, the IsDirty return False again.

But if you are developing the web application, you need to add some extra codes. Because you are opening a file from remote server and the component can’t watch the file like destop application.

A good method is set another variable in your application. When you save the document, you set the variable true. Any time you can judge the dirty by the IsDirty method and your own variable.

BOOL GetIsDirty(){

if(OA.IsDirty()==Flase) return False;

else return m_bDirty;

}

event OnDocumentOpened()

 

 

{

 

 

m_bDirty = false;

 

 

}

function UploadFile()

{

……

m_bDirty = False;

}

 

How to disable the file command buttons

The Office Viewer Component provides the method “EnableFileCommand” to allow the developers to disable the File command in the MS office program.

If you are developing a web application, you can set the initial functions in the “NotifyCtrlReady” event.

function OA1_NotifyCtrlReady() {
document.OA1.EnableFileCommand(0) = false; //FileNew = 0
}
<SCRIPT LANGUAGE=javascript FOR=OA1 EVENT=NotifyCtrlReady>
<!–
OA1_NotifyCtrlReady();
//–>
</SCRIPT>

More File Command ENUMS:

typedef enum FileCommandType
{
FileNew = 0,
FileOpen,
FileClose,
FileSave,
FileSaveAs,
FilePrint,
FilePageSetup,
FileProperties,
FilePrintPreview
} FileCommandType;

Pass optional parameters when you call a function in Visual C++

When you call a method that has optional parameters from Visual C++, you cannot omit the optional parameters. You need to pass a special VARIANT instead.

Some methods have “optional” parameters. In Visual Basic, you can omit them when calling the method. However, when calling with Visual C++, you have to pass a special VARIANT whose .vt field has the value VT_ERROR and .scode field has the value DISP_E_PARAMNOTFOUND. That is:

VARIANT varOpt;
varOpt.vt = VT_ERROR;
varOpt.scode = DISP_E_PARAMNOTFOUND;
OfficeViewer1.OfficeProtectDocument(varOpt);

Hide the Office ActiveX Control in Runtime

If you would like to hide the EDraw Office Viewer ActiveX Control in runtime, you need call the “OfficeObjectVisable” method.

For example: axOfficeViewer1.OfficeObjectVisable = false;

The follow code will lead to an error in C#.

axOfficeViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
axOfficeViewer2.Visible = false;
axOfficeViewer3.Visible = false;

PDF Viewer Component - Disables the Save, Print, Copy Buttons

DisableSaveToolbarButton
Function: boolean DisableSaveToolbarButton (boolean bDisable);
Description: Disables the Save button at the toolbars. The method must be call after the PDF file opened.

DisablePrintToolbarButton
Function: boolean DisablePrintToolbarButton ();
Description: Disables the Print button at the toolbars. The method must be call after the PDF file opened.

DisableCopyToolbarButton
Function: boolean DisableCopyToolbarButton ();
Description: Disables the Copy button at the toolbars. The method must be call after the PDF file opened.

DisableSpecialToolbarButton
Function: boolean DisableSpecialToolbarButton(BSTR nameButton);
Description: Disables the special button at the toolbars. The method must be call after the PDF file opened.
Params:
nameButton: If you want to disable the special button at the toolbars, you need know the button’s name in the Adobe Reader. For examples: the Save button has a name as “SaveFileAs”. You can also use the follow values: Save, Print, CreatePDF, SendMail, Collaborate, Search, Copy.

Events in the PDF Viewer Component

PDF Viewer Component Events

1. Ready to Open Document Event
Event: HRESULT NotifyCtrlReady();
Description: Ready to open document.
When the component finished the initialization the NotifyCtrlReady event is raised. The event allows you to open a new document after the component has released all the resources are ready to open a new document.
HTML + JScript
&lt;html&gt;
&lt;script language=javascript id=clientEventHandlersJS&gt;
function NotifyCtrlReadyEvent ()
{
PDFViewer1.Open “http://www.ocxt.com/demo/sample.pdf”
}
&lt;/script&gt;

&lt;body&gt;
&lt;object classid=”clsid: 44A8091F-8F01-43B7-8CF7-4BBA71E61E04 ” id=”PDFViewer1″ width=”657″ height=”452″&gt;
&lt;param name=”Toolbars” value=”0″&gt;
&lt;/object&gt;
&lt;/body&gt;

&lt;script language=”JScript” for=PDFViewer1 event=” NotifyCtrlReady ()”&gt;
NotifyCtrlReadyEvent ();
&lt;/script&gt;
&lt;/html&gt;

2. Document Opened Event
Event: void OnDocumentOpened([in] BSTR FileName);
Description: Called when document is opened or new document added.
Every time a user opened a file successfully, the OnDocumentOpened event is raised. The event allows you to override the default behavior for the control and supply your own custom actions and dialog boxes to do normal file operations.
HTML + JScript
&lt;script language=”JScript” for=PDFViewer1 event=” OnDocumentOpened(FileName)”&gt;
OnDocumentOpenedEvent(FileName);
&lt;/script&gt;
&lt;script language=javascript&gt;
function OnDocumentOpenedEvent(FileName)
{
Alert(“Respond the Document Opened Event.”);
}
&lt;/script&gt;

3. Document Close Event
Event: void OnDocumentClosed();
Description: Called when document is closed.
Every time a user closed a file successfully, the OnDocumentClosed event is raised. The event allows you to override the default behavior for the control and supply your own custom actions and dialog boxes to do normal file operations.
HTML + JScript
&lt;script language=”JScript” for= PDFViewer1 event=” OnDocumentClosed()”&gt;
OnDocumentClosedEvent();
&lt;/script&gt;
&lt;script language=javascript&gt;
function OnDocumentClosedEvent()
{
Alert(“Respond the Document Close Event.”);
}
&lt;/script&gt;

4. Before Document Closed Event
Event: void BeforeDocumentClosed( [in,out] VARIANT* Cancel);
Description: Called before document is closed (may be canceled).
Every time before a user closed a document the OnActivationChange event is raised. The event allows you to override the default behavior for the control and supply your own custom actions and dialog boxes to do normal file operations.
HTML + JScript
&lt;script language=”JScript” for= PDFViewer1 event=” BeforeDocumentClosed (Cancel)”&gt;
OnBeforeDocumentClosedEvent(GoingActive);
&lt;/script&gt;
&lt;script language=javascript&gt;
function OnBeforeDocumentClosedEvent (GoingActive)
{
Alert(“Respond the Before Document Closed Event.”);
}
&lt;/script&gt;

5. Before Document Saved Event
Event: void BeforeDocumentSaved( [in,out] VARIANT* Cancel);
Description: Called before document is saved (may be canceled).
Every time a user opens a new document or closes a document the OnActivationChange event is raised. The event allows you to override the default behavior for the control and supply your own custom actions and dialog boxes to do normal file operations.
HTML + JScript
&lt;script language=”JScript” for= PDFViewer1 event=” BeforeDocumentSaved( Cancel)”&gt;
OnBeforeDocumentSavedEvent(GoingActive);
&lt;/script&gt;

&lt;script language=javascript&gt;
function OnBeforeDocumentSavedEvent ( Cancel)
{
Alert(“Respond the Before Document Saved Event.”);
}
&lt;/script&gt;

6. Before Right Click the Window
Event: HRESULT OnWindowBeforeRightClick();
Description: Called before right click the component. The event needs the DisableViewRightClickMenu method or DisableToolbarRightClickMenu method is called.

7. Before Double Click the Window
Event: HRESULT OnWindowBeforeDoubleClick ();
Description: Called before double click the component.

8. Before Download File
Event: HRESULT BeforeDownloadFile ();
Description: Called before downloading the file.

9. Download File Completed
Event: HRESULT DownloadFileComplete ();
Description: Called when the file was downloaded completely.

PDF Viewer Component - Disables the Hot Keys such as Save, Copy, Print.

Enable the developers to disables the Hot Keys such as Save, Copy, Print in the PDF Viewer Component.
Function: void DisableHotKeyPrint();
  void DisableHotKeySave();
  void DisableHotKeyCopy();
  void DisableHotKeyShowBookMarks();
  void DisableHotKeyShowThumnails();
  void DisableHotKeyShowToolbars();
  void DisableHotKeySearch();
Description: Disables the hotkeys at the Adobe Reader.

PDF Viewer Component - Disable File Toolbar

Function: boolean DisableFileToolbar (boolean bDisable);
Description: Disables the File toolbars. The method must be call after the PDF file opened.

PDF Viewer Component - Disable View Right Click Menu

Function: boolean DisableViewRightClickMenu (boolean bDisable);
Description: Disables the right click menu at the view. The method must be call after the PDF file opened.