Click here to Skip to main content
15,886,067 members
Articles / Desktop Programming / MFC

The Ultimate TCP/IP Home Page

Rate me:
Please Sign up or sign in to vote.
4.98/5 (77 votes)
25 Aug 2007CPOL13 min read 2.6M   45.4K   267  
Ultimate TCP-IP is now Open Source
// UT_Finger.cpp: implementation of the CUT_FingerPage class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "UT_Finger.h"

// Suppress warnings for non-safe str fns. Transitional, for VC6 support.
#pragma warning (push)
#pragma warning (disable : 4996 )


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#include "finger_c.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CUT_FingerPage::CUT_FingerPage(LPTSTR title):CUCPage(IDD_FINGER_PAGE,title)
{
	m_HistoryCtrl.SetTimeStampFormat(_T("%c"));
}

CUT_FingerPage::~CUT_FingerPage()
{
	
}


void CUT_FingerPage::OnInitDialog(WPARAM /* wParam */, LPARAM /* lParam */)
{
	
	//attach the history window to the control
	m_HistoryCtrl.AttachHistoryWindow(m_hWnd,IDC_FINGER_HISTORY);
	//set the maximum length of the buffer of this window
	m_HistoryCtrl.SetHistoryLength(500);
	// set the font for the history window
	m_hFont = CreateFont(14,0,0,0,500,0,0,0,0,0,0,0,0,_T("Courier New"));
	m_HistoryCtrl.SetFont(m_hFont);
	
	//setup the controls
	SetDlgItemText(m_hWnd, IDC_USER_NDOMAIN,_T("help@berkeley.edu"));

    // default log file
	SetDlgItemText(m_hWnd, IDC_FINGER_LOG_FILE,_T("session.txt"));

	m_bEnableLogChecked = FALSE;
	EnableWindow(GetDlgItem(m_hWnd,IDC_FINGER_LOG_FILE),m_bEnableLogChecked);
	
	
}

void CUT_FingerPage::OnHelp(LPARAM lParam){

    HELPINFO hInfo = *((LPHELPINFO) lParam);    

	::WinHelp((HWND)hInfo.hItemHandle, _T("DSITools.hlp"),
		   HELP_WM_HELP, (DWORD)(ULONG_PTR)(LPVOID)dwFingerHelpMap);


}

void CUT_FingerPage::OnClicked(int controlId)
{
	switch (controlId)
	{
		
    case IDC_FINGER_ABOUT:
        {
		::WinHelp(m_hWnd, _T("DSITools.hlp"),
		   HELP_CONTENTS,0);
        return;
        }
		
	case IDC_FINGER_ENABLE_LOG:
		{
			if (m_bEnableLogChecked)
			{
				m_bEnableLogChecked = FALSE;
				// just disable the log
				m_HistoryCtrl.EnableLog (m_bEnableLogChecked);
			}
			else
				m_bEnableLogChecked = TRUE;
			
			
			EnableWindow(GetDlgItem(m_hWnd,IDC_FINGER_LOG_FILE),m_bEnableLogChecked);
			
			break;
			
		}
	case IDC_FINGER_BTN:
		{
			//set the cursor to an hourglass	
			SetCursor(LoadCursor(NULL,IDC_WAIT));
			_TCHAR buf[MAX_PATH];
			
			
			if (m_bEnableLogChecked)
			{
				_TCHAR	szLogFileName[MAX_PATH];
				// get the name of the file to log to
				GetDlgItemText(m_hWnd,IDC_FINGER_LOG_FILE,szLogFileName,MAX_PATH-1);
				if (_tcslen(szLogFileName) <1)
				{
					int iAnswer = IDOK;
					iAnswer = MessageBox(m_hWnd,_T("Log file name is not present, Continue without logging?"),_T("Verify"),MB_OKCANCEL);
					if (iAnswer != IDOK   )
						return;
				}
				else
				{
					// set up the log file if needed
					m_HistoryCtrl.SetLogName (szLogFileName);
					m_HistoryCtrl.EnableLog (m_bEnableLogChecked);
				}
			}
					
			//clear the history control
			m_HistoryCtrl.ClearHistory();
			//get the information to finger
			GetDlgItemText(m_hWnd, IDC_USER_NDOMAIN,buf,MAX_PATH-1);
			
			if (_tcsstr(buf, _T("@")) == NULL) {
				
				// Oops, forgot the @ symbol
				MessageBox(m_hWnd, _T("The finger address must contain the @ symbol."), 
					NULL, MB_OK | MB_ICONINFORMATION);
			}
			else {
				
                TCHAR    szDispString[MAX_PATH];
                _sntprintf(szDispString, MAX_PATH, _T("Results of finger query \"%s\":"), buf);
                m_HistoryCtrl.AddStampedLine(_T(" "));
                m_HistoryCtrl.AddLine(szDispString);
                m_HistoryCtrl.AddLine(_T(" "));

                //perform the finger
				CUT_FingerClient fc;
                int res = fc.Finger(buf);
				if(res == UTE_SUCCESS){
					//show the results
					int numLines = fc.GetNumberReturnLines();
					for(int index =0;index <numLines;index++){
						m_HistoryCtrl.AddLine(fc.GetReturnLine(index));
                    }
				}
                m_HistoryCtrl.AddLine(" ");
                m_HistoryCtrl.AddLine(CUT_ERR::GetErrorString(res));
                m_HistoryCtrl.AddLine("-----------------------------");
                m_HistoryCtrl.AddLine(" ");
				
				//set the cursor back to the arrow
				SetCursor(LoadCursor(NULL,IDC_ARROW));
			}
			
			break;
		}
	}
}

#pragma warning ( pop )

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)


Written By
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
This is a Organisation

476 members

Comments and Discussions