Skip to content

Commit

Permalink
插件添加选项设置接口;添加插件管理界面
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyang219 committed Aug 27, 2021
1 parent 87ea7a7 commit 9567d05
Show file tree
Hide file tree
Showing 28 changed files with 506 additions and 24 deletions.
34 changes: 34 additions & 0 deletions PluginDemo/OptionsDlg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// OptionsDlg.cpp: 实现文件
//

#include "pch.h"
#include "PluginDemo.h"
#include "OptionsDlg.h"
#include "afxdialogex.h"


// COptionsDlg 对话框

IMPLEMENT_DYNAMIC(COptionsDlg, CDialog)

COptionsDlg::COptionsDlg(CWnd* pParent /*=nullptr*/)
: CDialog(IDD_OPTIONS_DIALOG, pParent)
{

}

COptionsDlg::~COptionsDlg()
{
}

void COptionsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(COptionsDlg, CDialog)
END_MESSAGE_MAP()


// COptionsDlg 消息处理程序
23 changes: 23 additions & 0 deletions PluginDemo/OptionsDlg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once


// COptionsDlg 对话框

class COptionsDlg : public CDialog
{
DECLARE_DYNAMIC(COptionsDlg)

public:
COptionsDlg(CWnd* pParent = nullptr); // 标准构造函数
virtual ~COptionsDlg();

// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_OPTIONS_DIALOG };
#endif

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持

DECLARE_MESSAGE_MAP()
};
1 change: 1 addition & 0 deletions PluginDemo/PluginDemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {

__declspec(dllexport) IPluginItem* TMPluginCreateInstance(int index);
__declspec(dllexport) void TMPluginInfoRequired();
__declspec(dllexport) void TMPluginOptions();

#ifdef __cplusplus
}
Expand Down
106 changes: 106 additions & 0 deletions PluginDemo/PluginDemo.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// ����(���壬�й�) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END

3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END

#endif // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

IDD_OPTIONS_DIALOG DIALOGEX 0, 0, 310, 178
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "ʱ�ں���������"
FONT 9, "΢���ź�", 400, 0, 0x0
BEGIN
DEFPUSHBUTTON "ȷ��",IDOK,199,157,50,14
PUSHBUTTON "ȡ��",IDCANCEL,253,157,50,14
END


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_OPTIONS_DIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 303
TOPMARGIN, 7
BOTTOMMARGIN, 171
END
END
#endif // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// AFX_DIALOG_LAYOUT
//

IDD_OPTIONS_DIALOG AFX_DIALOG_LAYOUT
BEGIN
0
END

#endif // ����(���壬�й�) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

10 changes: 10 additions & 0 deletions PluginDemo/PluginDemo.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,30 @@
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -162,14 +166,17 @@
<ClInclude Include="..\include\PluginInterface.h" />
<ClInclude Include="DataManager.h" />
<ClInclude Include="framework.h" />
<ClInclude Include="OptionsDlg.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="PluginDemo.h" />
<ClInclude Include="PluginSystemDate.h" />
<ClInclude Include="PluginSystemTime.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="DataManager.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="OptionsDlg.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
Expand All @@ -179,6 +186,9 @@
<ClCompile Include="PluginSystemDate.cpp" />
<ClCompile Include="PluginSystemTime.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="PluginDemo.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
14 changes: 14 additions & 0 deletions PluginDemo/PluginDemo.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
<ClInclude Include="..\include\PluginInterface.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="OptionsDlg.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand All @@ -53,5 +59,13 @@
<ClCompile Include="DataManager.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="OptionsDlg.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="PluginDemo.rc">
<Filter>资源文件</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
42 changes: 26 additions & 16 deletions PluginDemo/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@
#include "PluginSystemTime.h"
#include "PluginDemo.h"
#include "DataManager.h"
#include "OptionsDlg.h"


BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
//BOOL APIENTRY DllMain( HMODULE hModule,
// DWORD ul_reason_for_call,
// LPVOID lpReserved
// )
//{
// switch (ul_reason_for_call)
// {
// case DLL_PROCESS_ATTACH:
// case DLL_THREAD_ATTACH:
// case DLL_THREAD_DETACH:
// case DLL_PROCESS_DETACH:
// break;
// }
// return TRUE;
//}

IPluginItem* TMPluginCreateInstance(int index)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());

switch (index)
{
case 0:
Expand All @@ -38,6 +40,7 @@ IPluginItem* TMPluginCreateInstance(int index)

void TMPluginInfoRequired()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
//获取时间和日期
SYSTEMTIME system_time;
GetSystemTime(&system_time);
Expand All @@ -47,3 +50,10 @@ void TMPluginInfoRequired()
swprintf_s(buff, L"%.2d:%.2d:%.2d", system_time.wHour, system_time.wMinute, system_time.wSecond);
CDataManager::Instance().m_cur_time = buff;
}

void TMPluginOptions()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
COptionsDlg dlg;
dlg.DoModal();
}
20 changes: 18 additions & 2 deletions PluginDemo/framework.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#pragma once

#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容
// Windows 头文件
#include <windows.h>
//// Windows 头文件
//#include <windows.h>

#include <SDKDDKVer.h>

#include <afxwin.h> // MFC 核心组件和标准组件
#include <afxext.h> // MFC 扩展
#include <afxdisp.h> // MFC 自动化类

#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
2 changes: 2 additions & 0 deletions PluginDemo/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
// 添加要在此处预编译的标头
#include "framework.h"

#include "resource.h"

#endif //PCH_H
17 changes: 17 additions & 0 deletions PluginDemo/resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// 供 PluginDemo.rc 使用
//
#define IDD_DIALOG1 101
#define IDD_OPTIONS_DIALOG 101

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
7 changes: 7 additions & 0 deletions TrafficMonitor/BaseDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ void CBaseDialog::SaveConfig() const
ini.Save();
}

void CBaseDialog::EnableDlgCtrl(UINT id, bool enable)
{
CWnd* pWnd = GetDlgItem(id);
if (pWnd != nullptr)
pWnd->EnableWindow(enable);
}

void CBaseDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
Expand Down
1 change: 1 addition & 0 deletions TrafficMonitor/BaseDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CBaseDialog : public CDialog

protected:
virtual CString GetDialogName() const = 0;
void EnableDlgCtrl(UINT id, bool enable);

virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持

Expand Down
Loading

0 comments on commit 9567d05

Please sign in to comment.