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

📄 writepurl.cpp

📁 在开发操作系统时
💻 CPP
字号:
// WritePurl.cpp : implementation file
//

#include "stdafx.h"
#include "VirtualFloppyMgr.h"
#include "WritePurl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWritePurl dialog


CWritePurl::CWritePurl(CWnd* pParent /*=NULL*/)
	: CDialog(CWritePurl::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWritePurl)
	m_outPerlFile = _T("");
	//}}AFX_DATA_INIT
}


void CWritePurl::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWritePurl)
	DDX_Text(pDX, IDC_EDIT_SL_OUT_PURL, m_outPerlFile);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CWritePurl, CDialog)
	//{{AFX_MSG_MAP(CWritePurl)
	ON_BN_CLICKED(IDC_WRITEPURE, OnWritepure)
	ON_BN_CLICKED(IDC_BUTTON_SL_OUT_PURL, OnButtonSlOutPurl)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWritePurl message handlers

void CWritePurl::OnWritepure() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	HANDLE hfImage = ::CreateFile((LPCSTR)this->m_outPerlFile,
		GENERIC_WRITE,
		0,
		NULL,
		CREATE_ALWAYS,//TRUNCATE_EXISTING|CREATE_NEW|CREATE_ALWAYS,//OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL,
		NULL);
	::SetFilePointer(hfImage, 0, 0, FILE_BEGIN);

	const int tbufLen = 512;//1024;
	BYTE tbuff[tbufLen];
	DWORD dwBytesWritten = 0;
	int tcnt = 26;
	char tch = 'a';
	while(tcnt)
	{
		memset(tbuff,tch++,tbufLen);
		tcnt-- ;
		if (!::WriteFile(hfImage,
			tbuff,
			tbufLen,
			&dwBytesWritten,
			NULL) )
		{
			int err;
			char error[10];
			err=GetLastError ();
			itoa (err, error, 10);
			MessageBox (error, "Writing sectors ...Failed  ");
			
			::CloseHandle(hfImage);
			return ;
		}
	}
	
	::CloseHandle(hfImage);

	::MessageBox(this->m_hWnd, "成功!", "Floppy writer", MB_OK);	

}

void CWritePurl::OnButtonSlOutPurl() 
{
	// TODO: Add your control notification handler code here
	OPENFILENAME ofn;			// common dialog box structure
	char szFile[MAX_PATH] = "out.img";	// buffer for file name
//	char szFileFilterBIN[255]= "Binary files(*.bin)\0*.bin\0All(*.*)\0*.*\0";
//	char szFileFilterIMG[255]= "Image files(*.img)\0*.img\0All(*.*)\0*.*\0";
	char szFileFilterIMG[255]= "All(*.*)\0*.*\0";
	HWND hwnd = this->m_hWnd;		// owner window
	
	// Initialize OPENFILENAME
	ZeroMemory(&ofn, sizeof(OPENFILENAME));
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = hwnd;
	ofn.lpstrFile = szFile;
	ofn.nMaxFile = sizeof(szFile);
	ofn.lpstrFilter = szFileFilterIMG;
	ofn.nFilterIndex = 1;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = 0;
	ofn.lpstrInitialDir = NULL;
	ofn.lpstrTitle = "打开文件";
	ofn.Flags = OFN_PATHMUSTEXIST ;//| OFN_FILEMUSTEXIST;
	
	// Display the Open dialog box. 
	
	if (GetOpenFileName(&ofn)==FALSE){
		return;
	}
	this->m_outPerlFile = (LPSTR)szFile;
	UpdateData(FALSE);
	
}

⌨️ 快捷键说明

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