⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bench1.cpp

📁 WIN32高级程序设计书附源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:

	nthreads=pDlg->GetDlgItemInt(id_ed_threads,NULL,FALSE);
	nblocks =pDlg->GetDlgItemInt(id_ed_blocks, NULL,FALSE);
	nreps   =pDlg->GetDlgItemInt(id_ed_repeat ,NULL,FALSE);
	if(nthreads>MAXTHREADS) {
		MessageBeep(0);
		pWnd->MessageBox("Maximum threads exceeded","Threads");
		pDlg->SetDlgItemInt(id_ed_threads,MAXTHREADS);
		nthreads=MAXTHREADS;
		}

	SetCursor(LoadCursor(NULL,IDC_WAIT));

	//post status and run dhrystones
	pDlg->SetDlgItemText(id_tx_status,"Running Dhrystones");
	if(fDhry)
		KDhrys=DoDhrystone(pDlg,nthreads,nreps);
	else
		KDhrys="";
	pDlg->SetDlgItemText(id_tx_dhrys,KDhrys);
	TRACE("%s MDhrys\n",KDhrys);

	//post status and run whetstones
	pDlg->SetDlgItemText(id_tx_status,"Running Whetstones");
	if(fWhet)
		KWhets=DoWhetstone(pDlg,nthreads,nreps);
	else
		KWhets="";
	pDlg->SetDlgItemText(id_tx_whets,KWhets);
	TRACE("%s MWhets\n",KWhets);

	//post status and run disk benchmark
	pDlg->SetDlgItemText(id_tx_status,"Running Disk Benchmark");
	if(fDisk)
		KBytes=DoDiskBench(pDlg,nblocks,nreps,ddrive);
	else
		KBytes="";
	pDlg->SetDlgItemText(id_tx_kbytes,KBytes);
	TRACE("%s MBytes\n",KBytes);

	//post status and run video benchmark
	pDlg->SetDlgItemText(id_tx_status,"Running Video Benchmark");
	if(fVideo)
		KVideo=DoVideoBench(pDlg,nreps);
	else
		KVideo="";
	pDlg->SetDlgItemText(id_tx_video,KVideo);
	TRACE("%s MChars\n",KVideo);

	//say that the benchmarks are done
	SetCursor(LoadCursor(NULL,IDC_ARROW));
#ifdef WIN32
	Sleep(1000);	//let them see last message
#endif
	pDlg->SetDlgItemText(id_tx_status,"Benchmarks complete");

	//enable reporting functions
	ResultThreads=nthreads;
	ResultReps=nreps;
	ResultBlocks=nblocks;
	strcpy(ResultDrive,ddrive);
	ResultKDhrys=KDhrys;
	ResultKWhets=KWhets;
	ResultKBytes=KBytes;
	ResultKVideo=KVideo;

	CMenu *main_menu=pWnd->GetMenu();
	ASSERT (main_menu);
	CMenu *file_menu=main_menu->GetSubMenu(0);
	ASSERT (file_menu);
	file_menu->EnableMenuItem(IDM_Save,  MF_ENABLED);
	file_menu->EnableMenuItem(IDM_Saveas,MF_ENABLED);
	file_menu->EnableMenuItem(IDM_Print, MF_ENABLED);
	CMenu *analyze_menu=main_menu->GetSubMenu(2);
	ASSERT (analyze_menu);
	analyze_menu->EnableMenuItem(IDM_Details,MF_ENABLED);
// analyze_menu->EnableMenuItem(IDM_Charts,MF_ENABLED);
// analyze_menu->EnableMenuItem(IDM_Comparisons,MF_ENABLED);
// analyze_menu->EnableMenuItem(IDM_Predictions,MF_ENABLED);
	return TRUE;
}

BOOL BLD_RunBenchMarksUDCFunc (CWnd *pWnd)
{
	return RunBenchMarks(pWnd,TRUE,TRUE,TRUE,TRUE);
}

// user defined code
BOOL BLD_ExitUDCFunc (CWnd *pWnd)
{
	 PostQuitMessage(0);
	 return TRUE;
}

void SaveResults(FILE *fh)
{
	fprintf(fh,"%d,%d,%d,%s,",
		ResultThreads,
		ResultReps,
		ResultBlocks,
		ResultDrive);
	fprintf(fh,"%s,",
		ResultKDhrys);
	fprintf(fh,"%s,",
		ResultKWhets);
	fprintf(fh,"%s,",
		ResultKBytes);
	fprintf(fh,"%s,",
		ResultKVideo);
	fprintf(fh,"%d,",
		bpp);
	for(int i=0;i<6;i++)
		fprintf(fh,"%ld.%ld,",DiskTimes[i]/100,DiskTimes[i]%100);
	for(i=0;i<6;i++)
		fprintf(fh,"%ld.%ld,",VideoTimes[i]/100,VideoTimes[i]%100);
	fprintf(fh,"\"%s\",",
		MachineDescription);
	unsigned checksum = ResultThreads+ResultReps+ResultBlocks+
		int(atof(ResultKDhrys)*10+atof(ResultKWhets)*10+atof(ResultKVideo)*bpp);
	for(i=0;i<6;i++)
		checksum += unsigned(DiskTimes[i]+VideoTimes[i]);
	fprintf(fh,"%g,%X\n",
		version,checksum);
	}
// user defined code
BOOL BLD_PrintUDCFunc (CWnd *pWnd)
{
	FILE *fh;

	fh=fopen("PRN","wt");
	ASSERT(fh);
	SaveResults(fh);
	fprintf(fh,"\f");
	fclose(fh);
	return TRUE;
}

#ifndef MAX_PATH
#define MAX_PATH 255
#endif

#ifdef WIN32
char CurrentFile[MAX_PATH]="NTHELL.DAT";
#else
char CurrentFile[MAX_PATH]="WINHELL.DAT";
#endif

// user defined code
BOOL BLD_SaveUDCFunc (CWnd *pWnd)
{
	FILE *fh;

	TRACE("BLD_SaveUDCFunc: about to open %s\n",CurrentFile);
	fh=fopen(CurrentFile,"at");
	ASSERT(fh);
	BLD_Menu41DlgFunc(pWnd);	//get machine description
	SaveResults(fh);
	fclose(fh);
	return TRUE;
}

// user defined code
BOOL BLD_SaveasUDCFunc (CWnd *pWnd)
{
	TRACE("BLD_SaveasUDCFunc: about to start file open dialog\n");
	CFileDialog cfd(FALSE,"dat",CurrentFile,OFN_HIDEREADONLY,
	"Data Files (*.dat)|*.dat|All Files (*.*)|*.*||");
	if(cfd.DoModal()==IDCANCEL)
		return(FALSE);
	TRACE("BLD_SaveasUDCFunc: returned from file open dialog\n");
	CString name=cfd.GetPathName();
	if(strlen(name))
		strcpy(CurrentFile,name);
	BLD_SaveUDCFunc (pWnd);
	return TRUE;
}

// *********************************************************************
// CLASS DECLARATION FOR CLIENT DIALOG BOX: Cwm_MainWinControlsDlg
// *********************************************************************

// The user client dialog class Cwm_MainWinControlsDlg.	This dialog class inherits from
// the WindowsMAKER base client dialog class.  This class provides all the
// user functionality for the client area dialog box.  You can override
// WindowsMAKER base functionality here, if desired.

class Cwm_MainWinControlsDlg : public Cwm_MainWinControlsBaseDlg
{
public:
	 Cwm_MainWinControlsDlg () : Cwm_MainWinControlsBaseDlg () {} ;
	 virtual ~Cwm_MainWinControlsDlg () {} ;

// Overridables (special message map entries)
	 virtual BOOL OnInitDialog();
	 virtual void OnOK();
	 virtual void OnCancel();

	 WMPROTO_MainWinControlsDlg()

protected:

	 DECLARE_MESSAGE_MAP()
} ;

// *********************************************************************
// FUNCTIONS AND MESSAGE MAP FOR CLIENT DIALOG BOX: Cwm_MainWinControlsDlg
// ************************************************************

// Startup procedure for client dialog box
CWnd* BLD_MainWinControlsClFunc (CWnd* pWnd)
{
	 Cwm_MainWinControlsDlg*	 pTheClientDlg;
	 pTheClientDlg = new Cwm_MainWinControlsDlg;
	 if (BLDCreateClientControls ("BENCHDLG",(CWinMakerClientDlg*)pTheClientDlg))
		  return pTheClientDlg;
	 else
	 {
		  BLDDisplayMessage (::GetActiveWindow (), BLD_CannotCreate,
				"BENCHDLG", MB_OK | MB_ICONHAND);
		  return NULL;
	 }
}

// Below, you should define any custom processing you require
// for the client dialog box BENCHDLG, which is in class Cwm_MainWinControlsDlg.

BEGIN_MESSAGE_MAP(Cwm_MainWinControlsDlg, Cwm_MainWinControlsBaseDlg)


END_MESSAGE_MAP()

BOOL Cwm_MainWinControlsDlg::OnInitDialog()
{
	//fill list box with known disk drives

	 CListBox *clb = (CListBox *)GetDlgItem(id_cb_drive);
	 clb->Dir( 0xC000 , "*.*");

	//Set default drive to current drive
	 int nSelect=_getdrive()-1;
	 nSelect = min(nSelect,clb->GetCount()-1);
	 clb->SetCurSel(nSelect);

#ifdef WIN32
	//Detect Win32s, suppress attempts to create threads if found
	 DWORD Version = GetVersion();
	 if(0x80000000 & Version) {
		//MessageBox("Win32s Detected","DEBUG"); //test works correctly
		CEdit *ed_threads = (CEdit *)GetDlgItem(id_ed_threads);
		ed_threads->SetReadOnly();
		}
#else
		{
		CEdit *ed_threads = (CEdit *)GetDlgItem(id_ed_threads);
		ed_threads->SetReadOnly();
		}
#endif

	CDC *pcdc=GetDC();
	bpp=pcdc->GetDeviceCaps(BITSPIXEL);
	rastercaps=pcdc->GetDeviceCaps(RASTERCAPS);
	if(rastercaps & RC_PALETTE) {
		sizepalette=pcdc->GetDeviceCaps(SIZEPALETTE);
		numreserved=pcdc->GetDeviceCaps(NUMRESERVED);
	}
	ReleaseDC(pcdc);
	SetDlgItemInt(id_tx_bpp,bpp);

	// Base Class processing of Init Dialog
	 Cwm_MainWinControlsBaseDlg::OnInitDialog();
	 return TRUE;	  // set focus to first control
}


void Cwm_MainWinControlsDlg::OnOK()
{
	 // Base Class processing of Ok
	 Cwm_MainWinControlsBaseDlg::OnOK();
}


void Cwm_MainWinControlsDlg::OnCancel()
{
	 // Base Class processing of Cancel
	 Cwm_MainWinControlsBaseDlg::OnCancel();
}

// *********************************************************************
// CLASS DECLARATION FOR MODAL DIALOG BOX: Cwm_AboutDlg
// *********************************************************************

// The user modal dialog class Cwm_AboutDlg.  This dialog class inherits from
// the WindowsMAKER modal base dialog class.  This class provides all the
// user functionality for this specific dialog box.  You can override
// WindowsMAKER base functionality here, if desired.

class Cwm_AboutDlg : public Cwm_AboutBaseDlg
{
public:
	 Cwm_AboutDlg (LPSTR AName, CWnd* AParent)
	 : Cwm_AboutBaseDlg (AName, AParent) {} ;

	 virtual ~Cwm_AboutDlg () {} ;

// Overridables (special message map entries)
	 virtual BOOL OnInitDialog();
	 virtual void OnOK();
	 virtual void OnCancel();

	 WMPROTO_AboutDlg()

protected:

	 DECLARE_MESSAGE_MAP()
} ;

// *********************************************************************
// FUNCTIONS AND MESSAGE MAP FOR MODAL DIALOG BOX: Cwm_AboutDlg
// ************************************************************

// Startup procedure for modal dialog box
int BLD_AboutDlgFunc (CWnd* pWnd)
{
	 int iRet;
	 Cwm_AboutDlg	  TheDlg ("ABOUT",pWnd);

	 iRet=TheDlg.DoModal ();
	 if( -1 == iRet )
	 {
		  BLDDisplayMessage (::GetActiveWindow (), BLD_CannotCreate,
				"ABOUT", MB_OK | MB_ICONHAND);
	 }
	 return iRet;
}

// Below, you can define any custom processing you require
// for the modal dialog box ABOUT, which is in class Cwm_AboutDlg.

BEGIN_MESSAGE_MAP(Cwm_AboutDlg, Cwm_AboutBaseDlg)


END_MESSAGE_MAP()


BOOL Cwm_AboutDlg::OnInitDialog()
{
	char temp[10];
	sprintf(temp,"%g",version);
	SetDlgItemText(id_tx_version,temp);
	 // Base Class processing of Init Dialog
	 Cwm_AboutBaseDlg::OnInitDialog();
	 return TRUE;	  // set focus to first control
}


void Cwm_AboutDlg::OnOK()
{

	 // Base Class processing of Ok
	 Cwm_AboutBaseDlg::OnOK();
}


void Cwm_AboutDlg::OnCancel()
{

	 // Base Class processing of Cancel
	 Cwm_AboutBaseDlg::OnCancel();
}

// user defined code
BOOL BLD_RunDhrystoneUDCFunc (CWnd *pWnd)
{
	return RunBenchMarks(pWnd,TRUE,FALSE,FALSE,FALSE);

⌨️ 快捷键说明

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