📄 testfileencryptdlg.cpp
字号:
// TestFileEncryptDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TestFileEncrypt.h"
#include "TestFileEncryptDlg.h"
#include "..\\FileEncrypt\\FileEncrypt.h"
#include "..\\FileEncrypt\\FileEncrypt_i.c"
// 定义接口变量指针 [5/12/2008 By willing]
IJDIOInter* ptrJDIOInter = NULL;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
typedef struct
{
int nDesModID; // 目标模块的编号
int nSrcModID; // 源模块的编号
WORD wDataType; // 数据类型
long lParam1; // 参数1
long lParam2; // 参数2 (保留)
}ST_IODATATYPE;
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestFileEncryptDlg dialog
CTestFileEncryptDlg::CTestFileEncryptDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestFileEncryptDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestFileEncryptDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestFileEncryptDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestFileEncryptDlg)
DDX_Control(pDX, IDC_LIST1, m_lstBox);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestFileEncryptDlg, CDialog)
//{{AFX_MSG_MAP(CTestFileEncryptDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_INIT, OnBtnInit)
ON_BN_CLICKED(IDC_BTN_RUN, OnBtnRun)
ON_BN_CLICKED(IDC_BTN_STOP, OnBtnStop)
ON_BN_CLICKED(IDC_BTN_SET, OnBtnSet)
ON_BN_CLICKED(IDC_BTN_GET, OnBtnGet)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestFileEncryptDlg message handlers
BOOL CTestFileEncryptDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CoInitialize(NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestFileEncryptDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestFileEncryptDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTestFileEncryptDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTestFileEncryptDlg::OnBtnInit()
{
// TODO: Add your control notification handler code here
if (NULL != ptrJDIOInter)
{
return;
}
HRESULT hr ;
hr = ::CoCreateInstance(CLSID_JDIOInter,NULL,CLSCTX_ALL,IID_IJDIOInter,(LPVOID*)(&ptrJDIOInter));
if (FAILED(hr))
{
MessageBox("查找接口失败","提示",MB_ICONINFORMATION|MB_OK);
return ;
}
}
void CTestFileEncryptDlg::OnBtnRun()
{
// TODO: Add your control notification handler code here
if (NULL == ptrJDIOInter)
{
MessageBox("请先初始化","提示",MB_ICONINFORMATION|MB_OK);
return;
}
ptrJDIOInter->Run(0);
}
void CTestFileEncryptDlg::OnBtnStop()
{
// TODO: Add your control notification handler code here
if (NULL == ptrJDIOInter)
{
MessageBox("已经停止","提示",MB_ICONINFORMATION|MB_OK);
return;
}
ptrJDIOInter->Stop(0);
ptrJDIOInter->Release();
ptrJDIOInter = NULL;
}
void CTestFileEncryptDlg::OnBtnSet()
{
// TODO: Add your control notification handler code here
char pszXML[] = "<POLICY>"
"<ITEM NAME='DES' VALUE='0' ALARM='' />"
"<ITEM NAME='3DES' VALUE='0' ALARM='' />"
"<ITEM NAME='ENCTYPE' VALUE='2' ALARM='' />"
"<ITEM NAME='PWDLEN' VALUE='1' ALARM='' />"
"</POLICY>";
ST_IODATATYPE ioDataType;
ioDataType.lParam1 = 0;
ioDataType.lParam2 = 0;
ioDataType.nDesModID = 17;
ioDataType.nSrcModID = 4;
ioDataType.wDataType = 2000;
long len = strlen(pszXML);
ptrJDIOInter->SetPacket((long*)&ioDataType,(long*)pszXML,len);
}
void CTestFileEncryptDlg::OnBtnGet()
{
// TODO: Add your control notification handler code here
ST_IODATATYPE ptrIODataType;
char* pszTemp = NULL;
long lsize = 0;
if (NULL == ptrJDIOInter)
{
MessageBox("请先初始化点击运行按钮","提示",MB_ICONINFORMATION|MB_OK);
return;
}
HRESULT hr = ptrJDIOInter->GetPacket((long*)&ptrIODataType,(long*)&pszTemp,&lsize);
if (FAILED(hr))
{
MessageBox("无输出数据","提示",MB_ICONINFORMATION|MB_OK);
return;
}
if (0 != lsize)
{
MessageBox(pszTemp,"提示",MB_ICONINFORMATION|MB_OK);
ptrJDIOInter->FreeMemory((long*)pszTemp);
pszTemp = NULL;
}
}
DWORD CTestFileEncryptDlg::Run()
{
m_hExitFlag = ::CreateEvent(NULL, TRUE, FALSE, NULL);
if (NULL == m_hExitFlag)
{
return -1;
}
m_handleThread = CreateThread( NULL, 0, GetThread,
( LPVOID )this, NULL, &m_dwThreadID );
if (NULL == m_handleThread)
{
return -2;
}
return 0;
}
DWORD WINAPI CTestFileEncryptDlg::GetThread(LPVOID lParam)
{
if (NULL == lParam)
{
return -1;
}
CTestFileEncryptDlg* _this = (CTestFileEncryptDlg*)lParam;
if (NULL == ptrJDIOInter)
{
//MessageBox("请先初始化点击运行按钮","提示",MB_ICONINFORMATION|MB_OK);
return -2;
}
HRESULT hr = ptrJDIOInter->GetPacket((long*)&ptrIODataType,(long*)&pszTemp,&lsize);
if (FAILED(hr))
{
//MessageBox("无输出数据","提示",MB_ICONINFORMATION|MB_OK);
return;
}
if (0 != lsize)
{
//MessageBox(pszTemp,"提示",MB_ICONINFORMATION|MB_OK);
ptrJDIOInter->FreeMemory((long*)pszTemp);
pszTemp = NULL;
}
return 0;
}
// 停止工作线程 [5/12/2008 By willing]
void CTestFileEncryptDlg::Stop()
{
if (NULL != m_hExitFlag)
{
::SetEvent(m_hExitFlag);
}
if (NULL != m_handleThread)
{
DWORD dwReCode = ::WaitForSingleObject(this->m_handleThread, 2000);
if (WAIT_TIMEOUT == dwReCode)
{
// 如果等待超时就强制退出 [5/12/2008 By willing]
::TerminateThread(m_handleThread,0);
}
}
if(this->m_hExitFlag != NULL)
{
::CloseHandle(this->m_hExitFlag);
this->m_hExitFlag = NULL;
}
this->m_handleThread = NULL;
return ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -