AUTOCLIK 範例:Automation 伺服應用程式

更新:2007 年 11 月

AUTOCLIK 範例是一個簡易的 Automation (先前稱為 OLE Automation) 伺服應用程式。autoclik 方案由兩個不同的專案所組成,分別是 autoclik 專案以及 autodriv 專案,前者代表 Automation 伺服程式的實作,而後者則代表驅動這個範例的用戶端。

AUTOCLIK 會示範下列幾點:

  • 由應用程式精靈所建立的 Automation 起始程式碼。

  • 可用於建立啟用 Automation 的 CCmdTarget 衍生類別,及加入 Automation 屬性和方法的選項。

  • 使用 Automation 向其他應用程式顯露現有的類別成員和函式。

  • 在單一 MFC 程式庫 (Microsoft Foundation Class Library,MFC) 應用程式中的多個分派介面。

安全性注意事項:

這個程式碼範例僅供概念說明之用,同時因為範例中的程式碼撰寫並沒有周全的顧及所有安全性問題,所以本範例不適用於實際執行的應用程式或網站中。如果使用者擅自將範例程式碼用於其他意圖而導致連帶事件或重大損害時,Microsoft 將不承擔任何責任。

若要取得範例和指示以便進行安裝:

  • 按一下 Visual Studio [說明] 功能表上的 [範例]。

    如需詳細資訊,請參閱尋找範例檔案

  • 最新版的完整範例清單可從 Visual Studio 2008 範例網頁 (英文) 取得。

  • 您也可以將範例置於電腦硬碟中。根據預設,範例和讀我檔案都會複製到 \Program Files\Visual Studio 9.0\Samples\ 下的資料夾中。對於所有的 Visual Studio Express 版,所有範例都可在線上找到。

建置範例

若要建置 AUTOCLIK 範例

  1. 開啟 autoclik.sln 方案。

  2. 在 [建置] 功能表上,按一下 [建置]。

執行範例

登錄 AUTOCLIK 應用程式之後,您就可以開始執行 AUTODRIV 應用程式。建置 IDE 的方案將會在執行 AUTODRIV 之前自動地執行 AUTODRIV 登錄。執行 AUTODRIV 應用程式,便會自動啟動 AUTOCLIK 應用程式並建立一個文件。若要測試這個範例的功能,請使用 AUTODRIV 應用程式提供的介面來管理文件。

AUTODRIV 範例是一個驅動 AUTOCLIK 範例的簡易 Automation 用戶端應用程式。AUTODRIV 範例是撰寫一個 Automation 驅動應用程式的良好示範,因為該範例會使用 COleDispatchDriver::SetPropertyCOleDispatchDriver::GetProperty 來透過 Automation 管理控制項。

如需以 Remote Automation 來同時使用 AUTOCLIK 與 AUTODRIV 的詳細資訊,請參閱使用 AUTOCLIK 和 AUTODRIV 來執行遠端 Automation

關鍵字

AUTOCLIK Automation 伺服程式範例會使用下列關鍵字:

AfxMessageBox; AfxOleInit; AfxOleLockApp; AfxOleUnlockApp; CCmdTarget::EnableAutomation; CCmdTarget::FromIDispatch; CCmdTarget::GetIDispatch; CCmdTarget::OnFinalRelease; CControlBar::EnableDocking; CControlBar::GetBarStyle; CControlBar::SetBarStyle; CDialog::DoModal; CDocument::GetFirstViewPosition; CDocument::GetNextView; CDocument::OnNewDocument; CDocument::SetModifiedFlag; CDocument::UpdateAllViews; CFrameWnd::ActivateFrame; CFrameWnd::DockControlBar; CFrameWnd::EnableDocking; CFrameWnd::LoadFrame; CObject::AssertValid; CObject::Dump; CObject::IsKindOf; CObject::Serialize; COleTemplateServer::ConnectTemplate; COleTemplateServer::UpdateRegistry; CStatusBar::Create; CStatusBar::SetIndicators; CToolBar::Create; CView::DoPreparePrinting; CView::GetDocument; CView::OnBeginPrinting; CView::OnDraw; CView::OnEndPrinting; CView::OnPreparePrinting; CWinApp::AddDocTemplate; CWinApp::EnableShellOpen; CWinApp::InitInstance; CWinApp::LoadStdProfileSettings; CWinApp::RegisterShellFileTypes; CWnd::DoDataExchange; CWnd::GetParentFrame; CWnd::OnCreate; CWnd::OnLButtonDown; CWnd::PreCreateWindow; CWnd::ShowWindow; CWnd::UpdateWindow; DragAcceptFiles; ShowWindow; TextOut

AUTODRIV Automation 用戶端範例會使用下列關鍵字:

AfxGetApp; AfxMessageBox; AfxOleInit; CDC::DrawIcon; CDC::GetSafeHdc; CDialog::DoModal; CDialog::EndDialog; COleDispatchDriver::AttachDispatch; COleDispatchDriver::GetProperty; COleDispatchDriver::InvokeHelper; COleDispatchDriver::SetProperty; CRect::Height; CRect::Width; CWinApp::InitInstance; CWinApp::LoadStdProfileSettings; CWnd::DoDataExchange; CWnd::GetClientRect; CWnd::IsIconic; CWnd::OnClose; CWnd::OnCreate; CWnd::OnPaint; CWnd::OnQueryDragIcon; CWnd::SendMessage; CWnd::ShowWindow; CWnd::UpdateData; GetSystemMetrics; LoadIcon; ShowWindow

注意事項:

部分範例 (包括本範例) 尚未經過改寫,無法反映出目前在 Visual C++ 精靈、程式庫以及編譯器方面的變更,不過還是可以示範如何完成您要進行的工作。

請參閱

其他資源

MFC 範例