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
The Add Method dialog box appears.
ShowWindow
, and accept ClassWizard’s proposal to reuse this as the Internal name, which is the name of the class member function.Click OK to return to the Automation tab (this method has no parameters).
This takes you to the starter implementation of ShowWindow
created in AutoClickDoc.cpp by ClassWizard.
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);
}