📄 sdiskdlg.cpp
字号:
// SDiskDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SDisk.h"
#include "SDiskDlg.h"
#include "SDUsbMassStorage.h"
#include "GUIDs.h"
DWORD DISK0SECTORS = 0x00;// + 0x20;//为DISK0分配固定的扇区大小-BY DEREK,07.21
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CSDiskDlg dialog
CSDiskDlg::CSDiskDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSDiskDlg::IDD, pParent)
{
m_DeviceConnected = false;
m_strUSBDevs = "";
m_EnterPassDevs = "";
m_PassWord = "";
m_EnterPassed = false;
//{{AFX_DATA_INIT(CSDiskDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSDiskDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSDiskDlg)
DDX_Control(pDX, IDC_COMBO1, m_CBoxDevice);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSDiskDlg, CDialog)
//{{AFX_MSG_MAP(CSDiskDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CBN_EDITCHANGE(IDC_COMBO1, OnEditchangeCombo1)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSDiskDlg message handlers
BOOL CSDiskDlg::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_sheet.AddPage(&m_page2);
m_sheet.AddPage(&m_page1);
//用Create来创建一个属性页
m_sheet.Create(this, WS_CHILD | WS_VISIBLE, WS_EX_CONTROLPARENT);
RECT rect;
m_sheet.GetWindowRect(&rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
//调整属性页的大小和位置
m_sheet.SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
if (GetDeviceName(m_strUSBDevs.GetBuffer(256)))
OnEditchangeCombo1();
else
MessageBox("Device disconnection!","Warning",MB_OK);
RegisterDevice(this->m_hWnd,(LPGUID)&USBCLASS_GUID);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSDiskDlg::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 CSDiskDlg::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 CSDiskDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSDiskDlg::OnEditchangeCombo1()
{
// TODO: Add your control notification handler code here
BOOL bResult=false;
//CString m_strUSBDevsOut,m_strUSBDevsIn;
UCHAR bMassBuf[MAX_INQUIRY_BUFFER_LENGTH + 32];
DWORD nLen;
PUCHAR pBuf;
DWORD dTotalBytes = 0;
DWORD TotalSectors = 0;
FLOAT dTotalSize = 0;
pBuf=(PUCHAR)bMassBuf;
bResult = MassStorageIO(m_strUSBDevs.GetBuffer(256),
UFI_READCAPACITY_TOTAL,//读取磁盘可用总扇区数
NULL,
pBuf,
SCSITRANSLEN8,
&nLen,
NULL,
MASSTIMEOUT
);
if (bResult)
{
INQUIRY_BUFFER_LENGTH = pBuf[4] * 0x1000000 + pBuf[5] * 0x10000 + pBuf[6] * 0x100 + pBuf[7];
//减去2个Block
TotalSectors = pBuf[0] * 0x1000000 + pBuf[1] * 0x10000 + pBuf[2] * 0x100 + pBuf[3]+1;// - RESERVESECTORS;//derek 11.21
dTotalBytes = TotalSectors * (pBuf[4] * 0x1000000 + pBuf[5] * 0x10000 + pBuf[6] * 0x100 + pBuf[7]);
dTotalSize = ((FLOAT)dTotalBytes )/ 0x400 / 0x400;////换算成MB
m_page1.TotalSize = dTotalSize;
m_page1.TotalSectors = TotalSectors;
bResult = MassStorageIO(m_strUSBDevs.GetBuffer(256),////读取DISK1的容量
UFI_READCAPACITY,
NULL,
pBuf,
SCSITRANSLEN8,
&nLen,
NULL,
MASSTIMEOUT
);
}
if (bResult)
{
m_page1.m_Sectors1 = pBuf[0] * 0x1000000 + pBuf[1] * 0x10000 + pBuf[2] * 0x100 + pBuf[3]+ 1;
bResult = MassStorageIO(m_strUSBDevs.GetBuffer(256),////读取DISK1的容量
SD_GETKEY,
NULL,
pBuf,
SCSITRANSLEN8,
&nLen,
NULL,
MASSTIMEOUT
);//读取disk0容量
DISK0SECTORS = pBuf[0] * 0x1000000 + pBuf[1] * 0x10000 + pBuf[2] * 0x100 + pBuf[3]+ 1;
m_DeviceConnected = true;
}
else
m_DeviceConnected = false;
return;
}
void CSDiskDlg::OnSelchangeCombo1()
{
// TODO: Add your control notification handler code here
OnEditchangeCombo1();
}
// add for close warning dialog
BOOL CSDiskDlg::OnDeviceChange(UINT nEventType,DWORD_PTR dwData)
{
HWND hWnd1;
switch(nEventType)
{
// 當光碟片放進來時,就會啟動
case DBT_DEVICEARRIVAL:
//MessageBox("Media 已經放進來了,並且準備好了","Device");
break;
// 當光碟片被拿走
case DBT_DEVICEREMOVECOMPLETE:
hWnd1 = ::FindWindow(NULL,"不安全的设备删除");
if (NULL != hWnd1)
{
::PostMessage(hWnd1,WM_CLOSE,0,0);
//hWnd2 = ::FindWindowEx(hWnd1,NULL,NULL,"确定");
}
break;
default:
//MessageBox("其他情況","Device");
break;
}
return TRUE;
}
void CSDiskDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CSDiskDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
// TODO: Add your message handler code here
m_page2.m_PWEdit.SetFocus();
}
void CSDiskDlg::OnOK()
{
// TODO: Add extra validation here
m_page2.OnOK();
// CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -