smphndlr.cpp

来自「C++、MFC源代码Singleton_demo」· C++ 代码 · 共 49 行

CPP
49
字号
// SmpHndlr.cpp - Implementation of CSmpHndlr class

// CSmpHndlr is dervied from CMsgHndlr and it displays the message in an AfxMessageBox, 
// when HandleMessage method is called

// Written by : T. Kulathu Sarma

// This file is part of Singleton application to demonstrate the concept of Singleton classes.
// This file is provided "as is" with no expressed or implied warranty.

#include "stdafx.h"
#include "SmpHndlr.h"
#include "MsgHndlrReg.h"

// Register CSmpHndlr agent in the message handler registry
static CMsgHndlrRegistry< CSmpHndlr > gSmpHndlr( RUNTIME_CLASS( CSmpHndlr ), "SMPHNDLR" );

IMPLEMENT_DYNCREATE( CSmpHndlr, CMsgHndlr )

// CSmpHndlr - Implementation

CSmpHndlr::CSmpHndlr()
{
}

CSmpHndlr::~CSmpHndlr()
{
}

// HandleMessage displays the message with an AfxMessageBox, but this
// can be changed to display the message on any given window
// Application data is ignored in this method
INT CSmpHndlr::HandleMessage( LPCSTR lpszMessage, INT nType, DWORD /* dwAppData */ )
{
	INT nIcon = MB_ICONINFORMATION;

	// Step 1 - Set the icon based on nType
	if( nType == WARNING_TYPE )
	{
		nIcon = MB_ICONEXCLAMATION;
	}
	else if( nType == ERROR_TYPE )
	{
		nIcon = MB_ICONSTOP;
	}
	// Step 2 - Display the message using AfxMessageBox with appropriate icons
	AfxMessageBox( CString( "Simple Message Handler : " ) + lpszMessage, MB_OK | nIcon );
	return SUCCESS;
}

⌨️ 快捷键说明

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