Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Remote Processes and Machine control of Windows NT based systems (2000/XP)

, 1 Apr 2012
Control certain aspects of machines sitting remotely, without having to install and trigger an application on the remote machine.
#include <afxwin.h>
#include "GlobalMFCHelperFunc.h"
#include "RemoteAdminView.h"
#include "MachineView.h"
#include "RemoteAdminDoc.h"
#include "MainFrame.h"
#include "RemoteAdmin.h"

CRemoteAdminDoc* MFC_DocView::GetAppDocument()
{
    CDocManager* pDocManager = ::AfxGetApp()->m_pDocManager;

    // As only one document template exits , we can avoid the check, as to at
    // which position in the template list our document template is stored
    // We know it is at the first position.
    POSITION posDocTemplate = pDocManager->GetFirstDocTemplatePosition();
    CSingleDocTemplate* pDocTemplate = static_cast<CSingleDocTemplate*>(pDocManager->GetNextDocTemplate(posDocTemplate));

    POSITION posDoc = pDocTemplate->GetFirstDocPosition();
    CRemoteAdminDoc* pDoc = static_cast<CRemoteAdminDoc*>(pDocTemplate->GetNextDoc(posDoc));

    ASSERT_VALID(pDoc);
	ASSERT_KINDOF(CRemoteAdminDoc, pDoc);
    
	return pDoc;
}

CRemoteAdminView* MFC_DocView::GetRemoteAdminView()
{
    CRemoteAdminDoc* pDoc = MFC_DocView::GetAppDocument();

	POSITION pos = pDoc->GetFirstViewPosition();
    CView* t_pView = NULL;

    while(pos != NULL)
	{
		t_pView = pDoc->GetNextView(pos);
		if(t_pView->IsKindOf(RUNTIME_CLASS(CRemoteAdminView)))
        {
            return static_cast<CRemoteAdminView*>(t_pView);
        }
			
	}
	
    // Could not get the Remote Admin View
    ASSERT(NULL);

	return NULL;
}

CMachineView* MFC_DocView::GetMachineView()
{
    CRemoteAdminDoc* pDoc = MFC_DocView::GetAppDocument();

	POSITION pos = pDoc->GetFirstViewPosition();
    CView* t_pView = NULL;

	while(pos != NULL)
	{
	    t_pView = pDoc->GetNextView(pos);
		if(t_pView->IsKindOf(RUNTIME_CLASS(CMachineView)))
        {
            return (static_cast<CMachineView*>(t_pView));
        }
	}
	
    // Could not get the Machine View
    ASSERT(NULL);

	return NULL;
}

CMainFrame* MFC_DocView::GetMainFrame()
{
    CMainFrame* pMainFrame = static_cast<CMainFrame*>(::AfxGetMainWnd());
    
    ASSERT(pMainFrame);
    ASSERT_KINDOF(CMainFrame, pMainFrame);

    return pMainFrame;
}


/* Helps in removing the casting problem while using AfxGetApp(), as it returns a (CWinApp*)
   not a (CRemoteAdminApp*).  So we can use the application pointer directly. */
CRemoteAdminApp* MFC_DocView::GetApp()	
{
	CRemoteAdminApp* pApp = static_cast<CRemoteAdminApp*>(::AfxGetApp());
	ASSERT(pApp);

	/* Can't use ASSERT_KINDOF as the CRamoteAdminApp class is not built with
	 the macros DELARE_DYNAMIC() or DECALRE_SERIAL() */
//	ASSERT_KINDOF(CRemoteAdminApp, pApp);

	return pApp;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Prateek Kaul
Web Developer
India India
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 1 Apr 2012
Article Copyright 2003 by Prateek Kaul
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid