testdllone.cpp
来自「《Visual C++视频技术方案宝典》配套光盘」· C++ 代码 · 共 122 行
CPP
122 行
// TestDllOne.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "TestDllOne.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CTestDllOneApp
BEGIN_MESSAGE_MAP(CTestDllOneApp, CWinApp)
//{{AFX_MSG_MAP(CTestDllOneApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDllOneApp construction
CTestDllOneApp::CTestDllOneApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CTestDllOneApp object
CTestDllOneApp theApp;
class _declspec(dllexport) CPlugClass
{
protected:
HICON m_HIcon; //图标资源索引
LPTSTR m_Text; //菜单和工具栏按钮的文本
public:
virtual void PlugDone() ; //插件执行的动作
virtual HICON GetIconRes() const ; //获取图标资源
virtual LPTSTR GetCmdText() const ; //获取菜单和工具栏按钮的文本
virtual void SetIconRes(HICON hIcon); //设置菜单或工具栏按钮图标
virtual void SetCmdText(LPTSTR CmdText) ; //设置菜单和工具栏按钮的文本
CPlugClass()
{
m_HIcon =::LoadIcon(AfxFindResourceHandle(
MAKEINTRESOURCE(IDI_ICON1), RT_ICON), MAKEINTRESOURCE(IDI_ICON1));
}
virtual void Release()
{ delete this ;}//DestroyIcon(m_HIcon);}
};
void CPlugClass::PlugDone()
{
ShellExecute(NULL,"Open","calc.exe",NULL,NULL,SW_SHOW );
}
HICON CPlugClass::GetIconRes() const
{
return m_HIcon;
}
LPTSTR CPlugClass::GetCmdText()const
{
return m_Text;
}
void CPlugClass::SetIconRes(HICON hIcon)
{
m_HIcon = hIcon;
}
void CPlugClass::SetCmdText(LPTSTR CmdText)
{
m_Text = CmdText;
}
BOOL __stdcall CreatePlugObj(void** pPlugObj)
{
*pPlugObj= new CPlugClass;
((CPlugClass*)*pPlugObj)->SetCmdText("计算器");
return *pPlugObj != NULL;
}
void ReleasePlugObj(CPlugClass* pPlugObj)
{
delete pPlugObj;
pPlugObj = NULL;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?