先推广一下QQ群:61618925。欢迎各位爱好编程的朋友加入。
一、程序界面
二、关键部分代码:
1.数据结构定义
#define MBRSIZE 512 #define BOOTRECORDSIZE 440 #define DISKSIGNEDSIZE 4 #define RESERVESIZE 2 #define DPTNUMBER 4 #define DPTSIZE 16 #define ENDSIGNSIZE 2typedef struct tagBOOTRECORD {UCHAR szBootRecord[BOOTRECORDSIZE]; }BOOTRECORD, *PBOOTRECORD;typedef struct tagDPT {UCHAR szBootSign; //引导标志,0x80表示活动分区,0x00表示非活动分区UCHAR szStartHeadNumber; //起始磁头号UCHAR szStartSectorNumber; //起始扇区号,低6位UCHAR szStartCylinderNumber;//起始柱面号,起始扇区号的高2位+起始柱面号UCHAR szPartitionType; //分区类型,0x00表示该分区未使用(即未指定),0x06表示FAT16基本分区,0x0B表示FAT32基本分区,0x05表示拓展分区,0x07表示NTFS分区,0x0F表示(LBA模式)拓展分区(0x83为Linux分区等)。UCHAR szEndHeadNumber; //结束磁头号UCHAR szEndSectorNumber; //结束扇区号,低6位UCHAR szEndCylinderNumber; //结束柱面号,结束扇区号的高2位+结束柱面号ULONG ulSectorsPreceding; //本分区之前使用的扇区数ULONG ulSectorsInPartition; //分区的总扇区数 }DPT, *PDPT;typedef struct tagMBR {BOOTRECORD BootRecord;//引导程序UCHAR ulSigned[DISKSIGNEDSIZE]; //Windows磁盘签名UCHAR szReserve[RESERVESIZE]; //保留位DPT Dpt[DPTNUMBER]; //分区表UCHAR szEndSign[ENDSIGNSIZE]; //结束标志 }MBR, *PMBR;
2.关键程序实现
void CMBRInfoDlg::InitMBRTree(void) {HTREEITEM hParentItem = m_ctrlMBRTree.InsertItem(_T("引导程序"));hParentItem = m_ctrlMBRTree.InsertItem(_T("Windows磁盘签名"));hParentItem = m_ctrlMBRTree.InsertItem(_T("保留位"));hParentItem = m_ctrlMBRTree.InsertItem(_T("分区表"));HTREEITEM hChildItem = m_ctrlMBRTree.InsertItem(_T("第一分区表"), hParentItem);m_ctrlMBRTree.InsertItem(_T("引导标志"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("分区类型"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区前使用的扇区数"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区的总扇区数"), hChildItem);hChildItem = m_ctrlMBRTree.InsertItem(_T("第二分区表"), hParentItem);m_ctrlMBRTree.InsertItem(_T("引导标志"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("分区类型"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区前使用的扇区数"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区的总扇区数"), hChildItem);hChildItem = m_ctrlMBRTree.InsertItem(_T("第三分区表"), hParentItem);m_ctrlMBRTree.InsertItem(_T("引导标志"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("分区类型"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区前使用的扇区数"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区的总扇区数"), hChildItem);hChildItem = m_ctrlMBRTree.InsertItem(_T("第四分区表"), hParentItem);m_ctrlMBRTree.InsertItem(_T("引导标志"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("分区类型"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区前使用的扇区数"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区的总扇区数"), hChildItem);hParentItem = m_ctrlMBRTree.InsertItem(_T("结束标志"));m_ctrlMBRTree.SetBkColor(RGB(150, 100, 100)); }void CMBRInfoDlg::ShowMBR() {DWORD dwRead = 0;DWORD dwError = 0;CString strError = _T("");UCHAR szMBRInfo[MBRSIZE];ZeroMemory(szMBRInfo, MBRSIZE * sizeof(UCHAR));if (!ReadFile(m_hDevice, (LPVOID)szMBRInfo, MBRSIZE * sizeof(UCHAR), &dwRead, NULL)){dwError = GetLastError();strError.Format(_T("ReadFile Error : %d"), dwError);AfxMessageBox(strError);CloseHandle(m_hDevice);m_hDevice = INVALID_HANDLE_VALUE;return;}memcpy(m_Mbr.BootRecord.szBootRecord, szMBRInfo, BOOTRECORDSIZE * sizeof(UCHAR));memcpy(m_Mbr.ulSigned, &szMBRInfo[BOOTRECORDSIZE], DISKSIGNEDSIZE);memcpy(m_Mbr.szReserve, &szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE], RESERVESIZE);for (int i = 0; i < 4; ++i){m_Mbr.Dpt[i].szBootSign = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE];m_Mbr.Dpt[i].szStartHeadNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 1];m_Mbr.Dpt[i].szStartSectorNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 2];m_Mbr.Dpt[i].szStartCylinderNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 3];m_Mbr.Dpt[i].szPartitionType = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 4];m_Mbr.Dpt[i].szEndHeadNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 5];m_Mbr.Dpt[i].szEndSectorNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 6];m_Mbr.Dpt[i].szEndCylinderNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 7];m_Mbr.Dpt[i].ulSectorsPreceding = *((int*)&szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 8]);m_Mbr.Dpt[i].ulSectorsInPartition = *((int*)&szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 12]);}memcpy(m_Mbr.szEndSign, &szMBRInfo[MBRSIZE - ENDSIGNSIZE], ENDSIGNSIZE);UCHAR szTemp[3];CString strTemp = _T("");for (int i = 0; i < MBRSIZE; i++){ZeroMemory(szTemp, 3 * sizeof(UCHAR));wsprintf((LPTSTR)szTemp, _T("%02X"), szMBRInfo[i]);strTemp = szTemp;m_strMBRInfo += strTemp;if ((i + 1) % 16 == 0){m_strMBRInfo += _T("\r\n");}else{m_strMBRInfo += _T(" ");}}m_ctrlMBREdit.SetWindowText(m_strMBRInfo); }void CMBRInfoDlg::OnTvnSelchangedTreeMbr(NMHDR *pNMHDR, LRESULT *pResult) {LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);// TODO: 在此添加控件通知处理程序代码HTREEITEM hItem = m_ctrlMBRTree.GetSelectedItem();CString strItemText = m_ctrlMBRTree.GetItemText(hItem);if (strItemText == _T("引导程序")){m_ctrlMBREdit.SetSel(0, 4 * BOOTRECORDSIZE - 2);m_strTips = _T("引导程序占440字节");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("Windows磁盘签名")){m_ctrlMBREdit.SetSel(4 * BOOTRECORDSIZE, 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE) - 2);m_strTips = _T("Windows磁盘签名占4个字节");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("保留位")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE) - 2);m_strTips = _T("保留位占2个字节");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTNUMBER * DPTSIZE) - 2);m_strTips = _T("分区表总占64个字节,系统最多有4个主分区。双击分区表节点可以展开下一级节点查看各个分区的具体信息。");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("结束标志")){m_ctrlMBREdit.SetSel(4 * (MBRSIZE - ENDSIGNSIZE), 4 * MBRSIZE - 2);m_strTips = _T("结束标志占2个字节。[55 AA]为正常结束标志");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE) - 2);m_strTips = _T("每一个分区表占16个字节,双击第一分区表节点可以展开查看该分区的具体信息");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2) - 2);m_strTips = _T("每一个分区表占16个字节,双击第二分区表节点可以展开查看该分区的具体信息");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3) - 2);m_strTips = _T("每一个分区表占16个字节,双击第三分区表节点可以展开查看该分区的具体信息");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 4) - 2);m_strTips = _T("每一个分区表占16个字节,双击第四分区表节点可以展开查看该分区的具体信息");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("引导标志")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 1) - 2);if (m_Mbr.Dpt[0].szBootSign == 0x80){m_strTips = _T("活动分区");}else if (m_Mbr.Dpt[0].szBootSign == 0x00){m_strTips = _T("非活动分区");}else{m_strTips = _T("未知分区");}m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 1) - 2);if (m_Mbr.Dpt[1].szBootSign == 0x80){m_strTips = _T("活动分区");}else if (m_Mbr.Dpt[1].szBootSign == 0x00){m_strTips = _T("非活动分区");}else{m_strTips = _T("未知分区");}m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 1) - 2);if (m_Mbr.Dpt[2].szBootSign == 0x80){m_strTips = _T("活动分区");}else if (m_Mbr.Dpt[2].szBootSign == 0x00){m_strTips = _T("非活动分区");}else{m_strTips = _T("未知分区");}m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 1) - 2);if (m_Mbr.Dpt[3].szBootSign == 0x80){m_strTips = _T("活动分区");}else if (m_Mbr.Dpt[3].szBootSign == 0x00){m_strTips = _T("非活动分区");}else{m_strTips = _T("未知分区");}m_ctrlTips.SetWindowText(m_strTips);}}if (strItemText == _T("起始磁头号")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 1), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 2) - 2);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 1), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 2) - 2);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 1), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 2) - 2);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 1), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 2) - 2);}m_strTips = _T("起始磁头号");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("起始扇区号")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 2), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 3) - 2);m_strTips.Format(_T("起始扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[0].szStartSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 2), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 3) - 2);m_strTips.Format(_T("起始扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[1].szStartSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 2), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 3) - 2);m_strTips.Format(_T("起始扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[2].szStartSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 2), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 3) - 2);m_strTips.Format(_T("起始扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[3].szStartSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}}if (strItemText == _T("起始柱面号")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 3), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 4) - 2);m_strTips.Format(_T("起始柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[0].szStartSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[0].szStartCylinderNumber);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 3), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 4) - 2);m_strTips.Format(_T("起始柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[1].szStartSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[1].szStartCylinderNumber);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 3), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 4) - 2);m_strTips.Format(_T("起始柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[2].szStartSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[2].szStartCylinderNumber);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 3), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 4) - 2);m_strTips.Format(_T("起始柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[3].szStartSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[3].szStartCylinderNumber);}m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("分区类型")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);int iPartitionType = 0;if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 4), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 5) - 2);iPartitionType = m_Mbr.Dpt[0].szPartitionType;}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 4), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 5) - 2);iPartitionType = m_Mbr.Dpt[1].szPartitionType;}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 4), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 5) - 2);iPartitionType = m_Mbr.Dpt[2].szPartitionType;}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 4), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 5) - 2);iPartitionType = m_Mbr.Dpt[3].szPartitionType;}switch (iPartitionType){case 0x00:m_strTips = _T("该分区未使用");break;case 0x05:m_strTips = _T("拓展分区");break;case 0x06:m_strTips = _T("FAT16基本分区");break;case 0x07:m_strTips = _T("NTFS分区");break;case 0x0B:m_strTips = _T("FAT32基本分区");break;case 0x0F:m_strTips = _T("(LBA模式)拓展分区");break;case 0x83:m_strTips = _T("Linux分区");break;default:m_strTips = _T("未知分区");}m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("结束磁头号")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 5), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 6) - 2);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 5), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 6) - 2);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 5), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 6) - 2);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 5), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 6) - 2);}m_strTips = _T("结束磁头号");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("结束扇区号")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 6), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 7) - 2);m_strTips.Format(_T("结束扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[0].szEndSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 6), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 7) - 2);m_strTips.Format(_T("结束扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[1].szEndSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 6), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 7) - 2);m_strTips.Format(_T("结束扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[2].szEndSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 6), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 7) - 2);m_strTips.Format(_T("结束扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[3].szEndSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}}if (strItemText == _T("结束柱面号")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 7), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 8) - 2);m_strTips.Format(_T("结束柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[0].szEndSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[0].szEndCylinderNumber);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 7), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 8) - 2);m_strTips.Format(_T("结束柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[1].szEndSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[1].szEndCylinderNumber);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 7), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 8) - 2);m_strTips.Format(_T("结束柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[2].szEndSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[2].szEndCylinderNumber);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 7), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 8) - 2);m_strTips.Format(_T("结束柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[3].szEndSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[3].szEndCylinderNumber);}m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("本分区前使用的扇区数")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 8), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 12) - 2);m_strTips.Format(_T("本分区前扇区数:%08X"), m_Mbr.Dpt[0].ulSectorsPreceding);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 8), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 12) - 2);m_strTips.Format(_T("本分区前扇区数:%08X"), m_Mbr.Dpt[1].ulSectorsPreceding);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 8), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 12) - 2);m_strTips.Format(_T("本分区前扇区数:%08X"), m_Mbr.Dpt[2].ulSectorsPreceding);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 8), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 12) - 2);m_strTips.Format(_T("本分区前扇区数:%08X"), m_Mbr.Dpt[3].ulSectorsPreceding);}m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("本分区的总扇区数")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 12), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 16) - 2);m_strTips.Format(_T("本分区扇区数:%08X.本分区的大小为:%lfG"), m_Mbr.Dpt[0].ulSectorsInPartition, m_Mbr.Dpt[0].ulSectorsInPartition * 1.0 * 512 / 1024 / 1024 / 1024);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 12), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 16) - 2);m_strTips.Format(_T("本分区扇区数:%08X.本分区的大小为:%lfG"), m_Mbr.Dpt[1].ulSectorsInPartition, m_Mbr.Dpt[1].ulSectorsInPartition * 1.0 * 512 / 1024 / 1024 / 1024);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 12), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 16) - 2);m_strTips.Format(_T("本分区扇区数:%08X.本分区的大小为:%lfG"), m_Mbr.Dpt[2].ulSectorsInPartition, m_Mbr.Dpt[2].ulSectorsInPartition * 1.0 * 512 / 1024 / 1024 / 1024);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 12), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 16) - 2);m_strTips.Format(_T("本分区扇区数:%08X.本分区的大小为:%lfG"), m_Mbr.Dpt[3].ulSectorsInPartition, m_Mbr.Dpt[3].ulSectorsInPartition * 1.0 * 512 / 1024 / 1024 / 1024);}m_ctrlTips.SetWindowText(m_strTips);}*pResult = 0; }HBRUSH CMBRInfoDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) {//HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO: 在此更改 DC 的任何属性pDC->SetBkMode(TRANSPARENT);if (pWnd == GetDlgItem(IDC_EDIT_MBR)){return CreateSolidBrush(RGB(150, 100, 100));}else{return CreateSolidBrush(RGB(120, 100, 100));}// TODO: 如果默认的不是所需画笔,则返回另一个画笔//return hbr; }BOOL CMBRInfoDlg::OpenDevice(void) {DWORD dwError = 0;CString strError = _T("");m_hDevice = CreateFile(_T("\\\\.\\PhysicalDrive0"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);if (INVALID_HANDLE_VALUE == m_hDevice){dwError = GetLastError();strError.Format(_T("CreateFile Error : %d"), dwError);AfxMessageBox(strError);return FALSE;}return TRUE; }
三、程序下载地址
http://pan.baidu.com/s/1jGKCa94