📄 rwerdlg.cpp
字号:
// RWerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "RWer.h"
#include "RWerDlg.h"
#include "CustomizeDialog.h"
#include "WRproc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//class RWThread;
TEST buffer[MAX_SIZE];
PARAM param[MAX_SIZE];
//PARAM *hparam;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
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()
/////////////////////////////////////////////////////////////////////////////
// CRWerDlg dialog
CRWerDlg::CRWerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRWerDlg::IDD, pParent),listMutex(),
RcountMutex(),writeMutex(),S(),WcountMutex()
{
// m_preadResource=NULL;
Rcount=0;s=0;
Rtemp=0;
Wcount=0;
Wtemp=0;totalThread=0;//总线程数
readTotal=0;
writeTotal=0;
Wwait=Rwait=0;
finish=0;
//{{AFX_DATA_INIT(CRWerDlg)
m_pathName = _T("");
m_write_priority = 1;
m_Rmax = 4;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CRWerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRWerDlg)
DDX_Control(pDX, IDC_LISTBOX, m_listBox);
DDX_Text(pDX, IDC_EDIT_PATH_NAME, m_pathName);
DDX_Radio(pDX, IDC_WRITE_PRIORITY, m_write_priority);
DDX_CBIndex(pDX, IDC_COMBO3, m_Rmax);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRWerDlg, CDialog)
ON_THREAD_MESSAGE(WM_READ_START,ReadStart)
ON_THREAD_MESSAGE(WM_R_WAIT,RWait)
ON_THREAD_MESSAGE(WM_READ_END,ReadEnd)
ON_THREAD_MESSAGE(WM_W_WAIT,WWait)
ON_THREAD_MESSAGE(WM_WRITE_START,WriteStart)
ON_THREAD_MESSAGE(WM_WRITE_END,WriteEnd)
//{{AFX_MSG_MAP(CRWerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
ON_BN_CLICKED(IDC_CUSTOMIZE, OnCustomize)
ON_BN_CLICKED(IDC_LOAD, OnLoad)
ON_BN_CLICKED(IDC_START, OnStart)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_CLEAR, OnClear)
ON_BN_CLICKED(IDC_SAVE, OnSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRWerDlg message handlers
BOOL CRWerDlg::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
// m_preadResource=NULL;
Rcount=0;
Rtemp=0;
GetDlgItem(IDC_START)->EnableWindow(FALSE);
GetDlgItem(IDC_LOAD)->EnableWindow(FALSE);
GetDlgItem(IDC_CUSTOMIZE)->EnableWindow(TRUE);
GetDlgItem(IDC_BROWSE)->EnableWindow(TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CRWerDlg::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 CRWerDlg::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 CRWerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CRWerDlg::OnBrowse()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_START)->EnableWindow(FALSE);
GetDlgItem(IDC_CUSTOMIZE)->EnableWindow(TRUE);
GetDlgItem(IDC_BROWSE)->EnableWindow(TRUE);
CFileDialog dlg(true);
dlg.m_ofn.lpstrFilter="测试数据文件(*.rwt)\0*.rwt\0\0";
dlg.m_ofn.lpstrInitialDir=".";
//dlg.m_ofn.Flags=
if(dlg.DoModal()==IDOK)
{
m_pathName=dlg.GetPathName();
filetobuffer(m_pathName,buffer);
//m_pPathName->SetWindowText(m_PathName);
totalThread=buffer[10].TStart;
getRWtotal(readTotal, writeTotal);
Rwait=readTotal;Wwait=writeTotal;
setInit();
GetDlgItem(IDC_LOAD)->EnableWindow(TRUE);
}
else
{
m_pathName = _T("");
}
UpdateData(FALSE);
}
void CRWerDlg::OnCustomize()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_START)->EnableWindow(FALSE);
GetDlgItem(IDC_CUSTOMIZE)->EnableWindow(TRUE);
GetDlgItem(IDC_BROWSE)->EnableWindow(TRUE);
CCustomizeDialog dlg;
if(dlg.DoModal()==IDOK)
{
GetDlgItem(IDC_LOAD)->EnableWindow(TRUE);
getRWtotal(readTotal, writeTotal);
totalThread=readTotal+writeTotal;
Rwait=readTotal;Wwait=writeTotal;
setInit();
CFileDialog dlg(false);
dlg.m_ofn.lpstrFilter="测试数据文件(*.rwt)\0*.rwt\0\0";
dlg.m_ofn.lpstrInitialDir=".";
//dlg.m_ofn.Flags=
if(dlg.DoModal()==IDOK)
{
m_pathName=dlg.GetPathName();
if(m_pathName.Right(4)!=".rwt")
m_pathName=dlg.GetPathName()+".rwt";
buffertofile(buffer,m_pathName);
totalThread=buffer[10].TStart;
}
else
{
m_pathName = _T("");
}
UpdateData(FALSE);
//m_PathName=dlg.GetPathName();
//m_pPathName->SetWindowText(m_PathName);
}
else
{
//m_PathName = _T("");
}/**/
}
void CRWerDlg::buffertofile(const TEST buffer[], CString pathname)
{
int strlength=pathname.GetLength();
char* name=new char[strlength+1];
for(int i=0;i<strlength;i++)
name[i]=pathname[i];
name[i]=0;
CFile file(name,CFile::modeCreate|CFile::modeWrite);
delete name;
for(i=0;buffer[i].index!=0;i++);
int len=i;
//buffer[10].TStart=len;
file.Write(&len,sizeof(len));
for(i=0;i<len;i++)
{
file.Write((void *)&buffer[i].index,sizeof(buffer[i].index));
file.Write((void*)&buffer[i].type,sizeof(buffer[i].type));
file.Write((void*)&buffer[i].TContinu,sizeof(buffer[i].TContinu));
file.Write((void*)&buffer[i].TStart,sizeof(buffer[i].TStart));
}
file.Close();
}
LONG CRWerDlg::ReadStart(UINT wParam,LONG lParam)
{
SetDlgItemInt(IDC_READING,Rcount,FALSE);
return 0;
}
LONG CRWerDlg::RWait(UINT wParam,LONG lParam)
{ SetDlgItemInt(IDC_R_WAIT,Rwait,FALSE);return 0;}
LONG CRWerDlg::ReadEnd(UINT wParam,LONG lParam)
{ SetDlgItemInt(IDC_rFINISHED,Rtemp,FALSE);return 0;}
LONG CRWerDlg::WriteStart(UINT wParam,LONG lParam)
{
SetDlgItemInt(IDC_WITING,Wcount,FALSE);
return 0;
}
LONG CRWerDlg::WWait(UINT wParam,LONG lParam)
{
SetDlgItemInt(IDC_W_WAIT,Wwait,FALSE);
return 0;
}
LONG CRWerDlg::WriteEnd(UINT wParam,LONG lParam)
{ SetDlgItemInt(IDC_wFINISHED,Wtemp,FALSE);return 0;}
////////////////////////////////////////////////////////////
CCustomizeDialog::CCustomizeDialog(CWnd* pParent /*=NULL*/)
: CDialog(CCustomizeDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CCustomizeDialog)
m_threadCount = 1;
m_start1 = 0;
m_start2 = 0;
m_start3 = 0;
m_start4 = 0;
m_start5 = 0;
m_start6 = 0;
m_start7 = 0;
m_start8 = 0;
m_start9 = 0;
m_start10 = 0;
m_continu1 = 5;
m_continu2 = 5;
m_continu3 = 5;
m_continu4 = 5;
m_continu5 = 5;
m_continu6 = 5;
m_continu7 = 5;
m_continu8 = 5;
m_continu9 = 5;
m_continu10 = 5;
//}}AFX_DATA_INIT
}
BOOL CCustomizeDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CEdit* m_edit=(CEdit*)GetDlgItem(IDC_THREAD_COUNT);//编辑框只可输入数字
long wl=GetWindowLong(m_edit->m_hWnd, GWL_STYLE);
SetWindowLong(m_edit->m_hWnd, GWL_STYLE, wl | ES_NUMBER);
m_tpye1.SetCurSel(0);
m_type2.SetCurSel(0);
m_type3.SetCurSel(0);
m_type4.SetCurSel(0);
m_type5.SetCurSel(0);
m_type6.SetCurSel(0);
m_type7.SetCurSel(0);
m_type8.SetCurSel(0);
m_type9.SetCurSel(0);
m_type10.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CCustomizeDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCustomizeDialog)
DDX_Control(pDX, IDC_COMBO9, m_type9);
DDX_Control(pDX, IDC_COMBO8, m_type8);
DDX_Control(pDX, IDC_COMBO7, m_type7);
DDX_Control(pDX, IDC_COMBO6, m_type6);
DDX_Control(pDX, IDC_COMBO5, m_type5);
DDX_Control(pDX, IDC_COMBO4, m_type4);
DDX_Control(pDX, IDC_COMBO3, m_type3);
DDX_Control(pDX, IDC_COMBO2, m_type2);
DDX_Control(pDX, IDC_COMBO10, m_type10);
DDX_Control(pDX, IDC_COMBO1, m_tpye1);
DDX_Text(pDX, IDC_THREAD_COUNT, m_threadCount);
DDV_MinMaxInt(pDX, m_threadCount, 0, 10);
DDX_Text(pDX, IDC_EDIT01, m_start1);
DDX_Text(pDX, IDC_EDIT02, m_start2);
DDX_Text(pDX, IDC_EDIT03, m_start3);
DDX_Text(pDX, IDC_EDIT04, m_start4);
DDX_Text(pDX, IDC_EDIT05, m_start5);
DDX_Text(pDX, IDC_EDIT06, m_start6);
DDX_Text(pDX, IDC_EDIT07, m_start7);
DDX_Text(pDX, IDC_EDIT08, m_start8);
DDX_Text(pDX, IDC_EDIT09, m_start9);
DDX_Text(pDX, IDC_EDIT10, m_start10);
DDX_Text(pDX, IDC_EDIT11, m_continu1);
DDX_Text(pDX, IDC_EDIT12, m_continu2);
DDX_Text(pDX, IDC_EDIT13, m_continu3);
DDX_Text(pDX, IDC_EDIT14, m_continu4);
DDX_Text(pDX, IDC_EDIT15, m_continu5);
DDX_Text(pDX, IDC_EDIT16, m_continu6);
DDX_Text(pDX, IDC_EDIT17, m_continu7);
DDX_Text(pDX, IDC_EDIT18, m_continu8);
DDX_Text(pDX, IDC_EDIT19, m_continu9);
DDX_Text(pDX, IDC_EDIT20, m_continu10);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCustomizeDialog, CDialog)
//{{AFX_MSG_MAP(CCustomizeDialog)
ON_EN_CHANGE(IDC_THREAD_COUNT, OnChangeThreadCount)
ON_WM_LBUTTONDOWN()
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
ON_EN_KILLFOCUS(IDC_THREAD_COUNT, OnKillfocusThreadCount)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCustomizeDialog message handlers
void CCustomizeDialog::disableCtrl(int nCount)
{
switch(nCount)
{
case 10:
(CEdit*)GetDlgItem(IDC_EDIT10)->ShowWindow(SW_SHOW);
(CEdit*)GetDlgItem(IDC_EDIT20)->ShowWindow(SW_SHOW);
(CComboBox*)GetDlgItem(IDC_COMBO10)->ShowWindow(SW_SHOW);
(CStatic*)GetDlgItem(IDC_STATIC10)->ShowWindow(SW_SHOW);
case 9:
(CEdit*)GetDlgItem(IDC_EDIT09)->ShowWindow(SW_SHOW);
(CEdit*)GetDlgItem(IDC_EDIT19)->ShowWindow(SW_SHOW);
(CComboBox*)GetDlgItem(IDC_COMBO9)->ShowWindow(SW_SHOW);
(CStatic*)GetDlgItem(IDC_STATIC9)->ShowWindow(SW_SHOW);
case 8:
(CEdit*)GetDlgItem(IDC_EDIT08)->ShowWindow(SW_SHOW);
(CEdit*)GetDlgItem(IDC_EDIT18)->ShowWindow(SW_SHOW);
(CComboBox*)GetDlgItem(IDC_COMBO8)->ShowWindow(SW_SHOW);
(CStatic*)GetDlgItem(IDC_STATIC8)->ShowWindow(SW_SHOW);
case 7:
(CEdit*)GetDlgItem(IDC_EDIT07)->ShowWindow(SW_SHOW);
(CEdit*)GetDlgItem(IDC_EDIT17)->ShowWindow(SW_SHOW);
(CComboBox*)GetDlgItem(IDC_COMBO7)->ShowWindow(SW_SHOW);
(CStatic*)GetDlgItem(IDC_STATIC7)->ShowWindow(SW_SHOW);
case 6:
(CEdit*)GetDlgItem(IDC_EDIT06)->ShowWindow(SW_SHOW);
(CEdit*)GetDlgItem(IDC_EDIT16)->ShowWindow(SW_SHOW);
(CComboBox*)GetDlgItem(IDC_COMBO6)->ShowWindow(SW_SHOW);
(CStatic*)GetDlgItem(IDC_STATIC6)->ShowWindow(SW_SHOW);
case 5:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -