Implementing Autoclik’s ShowWindow

In the following procedure, you will add and implement ShowWindow as a method. You need this method because AutoClik leaves its frame window hidden when it is initially launched by the Automation client. This is the default behavior implemented by AppWizard, which is appropriate for most Automation servers. Typically, the Automation server gives the Automation client control over when the server window is shown or hidden. If you want your Automation server to show its frame window right at the time it is launched by the Automation client, simply remove the RunAutomated condition in the following if statement provided by AppWizard in the application’s InitInstance routine (in AutoClik.cpp):

BOOL CAutoClickApp::InitInstance()
{
   ...

      // Check to see if launched as OLE server
   if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
   {
      // Application was run with /Embedding or /Automation.  Don't show the
      //  main window in this case.
      return TRUE;
   }

   ...

// The main window has been initialized, so show and update it.
   pMainFrame->ShowWindow(m_nCmdShow);
   pMainFrame->UpdateWindow();

   return TRUE;

}

To add the ShowWindow method

  1. From the View menu, click ClassWizard.

  2. Click the Automation tab.

  3. In the Class name box, select CAutoClickDoc, if it is not already selected, and click Add Method.

    The Add Method dialog box appears.

  4. In the External name box, type ShowWindow, and accept ClassWizard’s proposal to reuse this as the Internal name, which is the name of the class member function.

  5. In the Return type box, select void.

    Click OK to return to the Automation tab (this method has no parameters).

  6. Click Edit Code.

    This takes you to the starter implementation of ShowWindow created in AutoClickDoc.cpp by ClassWizard.

  7. Implement ShowWindow with the following code:
    POSITION pos = GetFirstViewPosition();
    CView* pView = GetNextView(pos);
    if (pView != NULL)
    {
    CFrameWnd* pFrameWnd = pView->GetParentFrame();
    pFrameWnd->ActivateFrame(SW_SHOW);
    pFrameWnd = pFrameWnd->GetParentFrame();
    if (pFrameWnd != NULL)
    pFrameWnd->ActivateFrame(SW_SHOW);
    }