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);

Print MS Word Document to the special printer

When you use the PrintOut method to print the word document with the  component, you maybe get the follow error.

This error can appear if a default printer has not been designated or if the application is unable to locate an existing default printer. To correct this problem, try one of the following in Microsoft Windows:
If a printer is not available in the Print dialog box, add a printer.
If the application cannot find an existing printer that is already installed, set the printer as the default printer.
If a default printer is installed but the application is unable to use it, uninstall the printer driver, and then install the latest version of the printer driver.
If the printer is on a print server, make sure the printer is available, the network is functioning, the server is not stalled, the printer is not out of paper, or the printer is not suspended by the administrator. Printing issues associated with a network printer are best handled by your local network administrator.
For more information about setting up and troubleshooting printer connections, see Windows Help and Support. (Click the Start button, and then click Help and Support.)

Word cannot print. There is no printer installed.

There are some solutions for it.

1. Call the ShowDialog 4 to use the default printer.

2. Word:
    CWordApplication app(m_wnd.get_Application()); 
    CString strOldPrinter = app.get_ActivePrinter();
    app.put_ActivePrinter(strPrinter); 
    app.PrintOut(varFalse, varOptional, varOptional, varOptional,
        varOptional, varOptional, varOptional, varOptional, varOptional,
        varOptional, varOptional, varOptional, varOptional, varOptional,
        varOptional, varOptional, varOptional, varOptional, varOptional); 
    app.put_ActivePrinter(strOldPrinter);

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
<html>
<script language=javascript id=clientEventHandlersJS>
function NotifyCtrlReadyEvent ()
{
PDFViewer1.Open “http://www.ocxt.com/demo/sample.pdf”
}
</script>

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

<script language=”JScript” for=PDFViewer1 event=” NotifyCtrlReady ()”>
NotifyCtrlReadyEvent ();
</script>
</html>

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
<script language=”JScript” for=PDFViewer1 event=” OnDocumentOpened(FileName)”>
OnDocumentOpenedEvent(FileName);
</script>
<script language=javascript>
function OnDocumentOpenedEvent(FileName)
{
Alert(“Respond the Document Opened Event.”);
}
</script>

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
<script language=”JScript” for= PDFViewer1 event=” OnDocumentClosed()”>
OnDocumentClosedEvent();
</script>
<script language=javascript>
function OnDocumentClosedEvent()
{
Alert(“Respond the Document Close Event.”);
}
</script>

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
<script language=”JScript” for= PDFViewer1 event=” BeforeDocumentClosed (Cancel)”>
OnBeforeDocumentClosedEvent(GoingActive);
</script>
<script language=javascript>
function OnBeforeDocumentClosedEvent (GoingActive)
{
Alert(“Respond the Before Document Closed Event.”);
}
</script>

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
<script language=”JScript” for= PDFViewer1 event=” BeforeDocumentSaved( Cancel)”>
OnBeforeDocumentSavedEvent(GoingActive);
</script>

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

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.

PDF Viewer Component - Disable the Toolbar Right Click

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

PDF Viewer Component - Disable Toolbars in the Adobe Reader

Function: boolean DisableToolbar(boolean bDisable)
Description: Disables all the toolbars in the Adobe Reader. The method must be call after the PDF file opened.

Tips:
 If you want to disable the toobars when you load a pdf file, you need put the method at OnDocumentOpened event.
 <SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
 function PDFViewer1_NotifyCtrlReady()
 {
        document.PDFViewer1.LoadFile (”e:\\OA_Reference2.pdf”);
 }
 function PDFViewer1_OnDocumentOpened(FileName)
 {
        document.PDFViewer1.DisableToolbar (true);
 }
 </SCRIPT>
 <SCRIPT LANGUAGE=javascript FOR=PDFViewer1 EVENT=NotifyCtrlReady>
 <!–
 PDFViewer1_NotifyCtrlReady();
 //–>
 </SCRIPT>
 <SCRIPT LANGUAGE=javascript FOR=PDFViewer1 EVENT=OnDocumentOpened(FileName)>
 <!–
 PDFViewer1_OnDocumentOpened(FileName);
 //–>
 </SCRIPT>