closehandleevent.cpp

来自「IO函数调用测试」· C++ 代码 · 共 120 行

CPP
120
字号
#include "stdafx.h"
#include "IOExplorer.h"
#include "TraceEvent.h"
  #include "CloseHandleEvent.h"


/****************************************************************************
*                     CloseHandleEvent::CloseHandleEvent
* Inputs:
*       CString s: Name of handle
*	HANDLE  hv: Actual handle, or 0 if not known
* Effect: 
*       Initializes the CloseHandleEvent
****************************************************************************/

CloseHandleEvent::CloseHandleEvent(CString s, HANDLE hv)
    {
     h = hv;
     name = s;
    }

/****************************************************************************
*                      CloseHandleEvent::display_result
* Result: CString
*       Display string for result
****************************************************************************/

CString CloseHandleEvent::display_result()
    {
     CString s;

     if(result)
	s.LoadString(IDS_TRUE);
     else
	s.LoadString(IDS_FALSE);
     return s;
    }

/****************************************************************************
*                          CloseHandleEvent::execute
* Result: LRESULT
*       (LRESULT)TRUE if successful
*	(LRESULT)FALSE if failure
* Effect: 
*       Closes the handle whose handle value is supplied in the event block
****************************************************************************/

LRESULT CloseHandleEvent::execute()
    {

     if(h == NULL)
	return FALSE;  // bogus

     CWaitCursor c;

     result = ::CloseHandle(h);
     if(result)
        { /* success */
	 h = NULL;  // clear handle
	 lasterror = 0;
	} /* success */
     else
        { /* error */
	 lasterror = ::GetLastError();
	} /* error */
     return result;
    }

/****************************************************************************
*                          CloseHandleEvent::display
* Result: CString
*       Display string for the event
* Effect: 
*       Creates a displayable string
****************************************************************************/

CString CloseHandleEvent::display()
    {
     if(h == NULL)
        { /* no handle */
	 if(name.GetLength() == 0)
	    { /* no name */
	     CString s;
	     s.LoadString(IDS_CLOSE_HANDLE_1);
	     return s;
	    } /* no name */
	 else
	    { /* has name */
	     CString f;
	     f.LoadString(IDS_CLOSE_HANDLE_3);
	     CString s;
	     s.Format(f, (LPCTSTR)name);
	     return s;
	    } /* has name */
	} /* no handle */
     else
        { /* valid handle */
	 CString f;
	 f.LoadString(IDS_CLOSE_HANDLE_2);
	 CString s;
	 s.Format(f, h);
	 return s;
	} /* valid handle */
    }

/****************************************************************************
*                           CloseHandleEvent::copy
* Result: TraceEvent *
*       A complete copy of the handle event
* Effect: 
*       Makes a new CloseHandleEvent
****************************************************************************/

TraceEvent * CloseHandleEvent::copy()
    {
     CloseHandleEvent * e = new CloseHandleEvent(name, h);
     copyTraceData(e);
     return e;
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?