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

📄 leftview.cpp

📁 visual c++ 实例编程
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	hPrev = 0;
	// TODO: Add your control notification handler code here
	m_wndStatusBarCtrl->SetText("", 0, 0);
	*pResult = 0;
	if(pNMTreeView->itemNew.state & TVIS_EXPANDEDONCE)	
		return;
	DRIVEPACKET *DrivePacket = (DRIVEPACKET *) pNMTreeView->itemNew.lParam;
	memcpy(&gDrivePacket, DrivePacket, sizeof(DRIVEPACKET));
	memcpy(&ParentDrivePacket, DrivePacket, sizeof(DRIVEPACKET));

	switch(DrivePacket->Type)
	{
	case NET:
		for(i=0; i<NumFloppiesNet; i++){
			wsprintf(TmpStr, "Floppy Disk %lu", i+1);
			TvI.mask = TVIF_CHILDREN | TVIF_TEXT | TVIF_PARAM;
			TvI.pszText = TmpStr;
			TvI.cChildren = 1;
			TvI.lParam = (long)DrivePacket;
			DrivePacket->Net = TRUE;
			DrivePacket->Drive = (WORD) i;
			DrivePacket->Cylinder = 0;
			DrivePacket->Head = 0;
			DrivePacket->Sector = 1;
			DrivePacket->NumSectors = 1;
			DrivePacket->Type = BOOT_RECORD;
			DrivePacket->RelativeSector = 0;
			DrivePacket->NTRelativeSector = 0;
			DrivePacket->Flag = 0;

			TvIns.item = TvI;
			TvIns.hParent = hPrevHD;
			TvIns.hInsertAfter = TVI_LAST;
			DiskTree->InsertItem((LPTVINSERTSTRUCT) &TvIns);
			DrivePacket++;
		}
		for(i=0; i<NumHardsNet; i++){
			wsprintf(TmpStr, "Hard Disk %lu", i+1);
			TvI.mask = TVIF_CHILDREN | TVIF_TEXT | TVIF_PARAM;
			TvI.pszText = TmpStr;
			TvI.cChildren = 1;
			TvI.lParam = (long)DrivePacket;
			DrivePacket->Net = TRUE;
			DrivePacket->Drive = 0x80+i;
			DrivePacket->Cylinder = 0;
			DrivePacket->Head = 0;
			DrivePacket->Sector = 1;
			DrivePacket->NumSectors = 1;
			DrivePacket->Type = PART_TABLE;
			DrivePacket->RelativeSector = 0;
			DrivePacket->NTRelativeSector = 0;
			if(gOSWin95)
				DrivePacket->Flag = Int13ExtNet;
			else
				DrivePacket->Flag = 0;

			TvIns.item = TvI;
			TvIns.hParent = hPrevHD;
			TvIns.hInsertAfter = TVI_LAST;
			DiskTree->InsertItem((LPTVINSERTSTRUCT) &TvIns);
			DrivePacket++;
		}
		m_wndStatusBarCtrl->SetText("", 0, 0);
		break;
	case PART_TABLE:{
		PrevRelSector = MainPrevRelSector = 0;
		hMemBufferDir = LocalAlloc(LMEM_MOVEABLE|LMEM_DISCARDABLE|LMEM_ZEROINIT, DrivePacket->NumSectors * 512);
		if(hMemBufferDir == NULL){
			AfxMessageBox("Fatal Error!  Not able to allocate a Buffer!");
			return;
		}
		BufferDir = (LPBYTE) LocalLock(hMemBufferDir);
		BufferNet = BufferDir;
		NetEvent = BUFFER_FILL;
		memcpy(&gDrivePacket, DrivePacket, sizeof(gDrivePacket));
		BytesToFill = DrivePacket->NumSectors * 512;
		if(DrivePacket->Net){
			NetCall.Function = LOAD_SECTOR;
			NetCall.Cylinder = DrivePacket->Cylinder;
			NetCall.Drive = DrivePacket->Drive;
			NetCall.Head = DrivePacket->Head;
			NetCall.Sector = DrivePacket->Sector;
			NetCall.NumSectors = DrivePacket->NumSectors;
			NetCall.NTRelativeSector = DrivePacket->RelativeSector;
			NetCall.RelativeSector = 0;
			NetCall.Flag = DrivePacket->Flag;
			send(SocketNum, (char *) &NetCall, sizeof(SECTOR_FUNC), 0);
			CallNet();
		}
		else if(gOSWin95){
			if(!(DllThunk32)(DrivePacket->Drive, DrivePacket->Cylinder, DrivePacket->Head, 
					DrivePacket->Sector, DrivePacket->NumSectors, (LPBYTE)BufferDir, DrivePacket->NTRelativeSector, DrivePacket->Flag)){
				AfxMessageBox("Partition table not accessible!");
				return;
			}
		}
		else{
			__int64 Tmp64 = ((__int64) DrivePacket->NTRelativeSector) * 512;
			long TmpVal = Tmp64 & 0xFFFFFFFF;
			long TmpValHi = (Tmp64 >> 32);
			SetFilePointer(hDisk[DrivePacket->Drive], TmpVal, &TmpValHi, FILE_BEGIN);
			TmpVal = 0;
			ReadFile(hDisk[DrivePacket->Drive], BufferDir, DrivePacket->NumSectors * 512, (DWORD *) &TmpVal, NULL);
			if(TmpVal != (DrivePacket->NumSectors * 512)){
				AfxMessageBox("Partition table not accessible!");
				return;
			}
		}
		PartitionTable = (PARTITION *) (BufferDir+0x1BE);
		UnknownPart = FALSE;
		for(i=0; i<4; i++){
			switch(PartitionTable->SysInd)
			{
			case 0:
				continue;
				break;
			case PART_DOS2_FAT:
				strcpy(TmpStr, "12-Bit FAT Disk");
				break;
			case PART_DOS3_FAT:
				strcpy(TmpStr, "16-Bit FAT Disk");
				break;
			case PART_EXTENDED:
				strcpy(TmpStr, "Extended DOS Partition");
				break;
			case PART_DOS4_FAT:
				strcpy(TmpStr, "16-Bit FAT Disk");
				break;
			case PART_DOS32:
				strcpy(TmpStr, "32-Bit FAT Disk");			//Normal FAT32
				break;
			case PART_DOS32X:
				strcpy(TmpStr, "32-Bit FAT Disk");			//FAT32 with int 13 extension
				break;
			case PART_DOSX13:
				strcpy(TmpStr, "16-Bit FAT Disk");			//Extended int 13
				break;
			case PART_DOSX13X:
				strcpy(TmpStr, "Extended 32-bit Partition");			//Extended DOS partition in int 13 extension
				break;
			default:
				UnknownPart = TRUE;
				strcpy(TmpStr, "Unknown");
				break;
			}
			Packets->Cylinder = PartitionTable->Cylinder;
			Packets->Drive = DrivePacket->Drive;
			Packets->Flag = DrivePacket->Flag;
			Packets->Head = PartitionTable->Head;
			Packets->Sector = PartitionTable->Sector;
			Packets->NumSectors = 1;
			Packets->Type = ((PartitionTable->SysInd == PART_EXTENDED) || (PartitionTable->SysInd == PART_DOSX13X)) ? EXTENDED_PART:BOOT_RECORD;
			if(UnknownPart)
				Packets->Type = UNKNOWN;
			Packets->FatType = ((PartitionTable->SysInd == PART_DOS32) || (PartitionTable->SysInd == PART_DOS32X)) ? FAT32:0;
			if((PartitionTable->SysInd == PART_EXTENDED) || (PartitionTable->SysInd == PART_DOSX13X)){
				MainPrevRelSector = PartitionTable->RelativeSector;
				Packets->NTRelativeSector = MainPrevRelSector;
			}
			else{
				Packets->NTRelativeSector = MainPrevRelSector + PartitionTable->RelativeSector;
			}
			Packets->Net = DrivePacket->Net;

			TvI.mask = TVIF_CHILDREN | TVIF_TEXT | TVIF_PARAM;
			TvI.pszText = TmpStr;
			if(UnknownPart){
				Packets->RelativeSector = 1;
				TvI.cChildren = 0;
			}
			else{
				Packets->RelativeSector = 0;
				TvI.cChildren = 1;
			}
			TvI.lParam = (long)Packets++;

			TvIns.item = TvI;
			TvIns.hParent = (HTREEITEM) pNMTreeView->itemNew.hItem;
			TvIns.hInsertAfter = hPrev;
			hPrev = DiskTree->InsertItem((LPTVINSERTSTRUCT) &TvIns);
			PartitionTable++;
		}
		LocalUnlock(hMemBufferDir);
		LocalFree(hMemBufferDir);
		break;
		}
	case EXTENDED_PART:{
		hMemBufferDir = LocalAlloc(LMEM_MOVEABLE|LMEM_DISCARDABLE|LMEM_ZEROINIT, DrivePacket->NumSectors * 512);
		if(hMemBufferDir == NULL){
			AfxMessageBox("Fatal Error!  Not able to allocate a Buffer!");
			return;
		}
		BufferDir = (LPBYTE) LocalLock(hMemBufferDir);
		BufferNet = BufferDir;
		NetEvent = BUFFER_FILL;
		memcpy(&gDrivePacket, DrivePacket, sizeof(gDrivePacket));
		BytesToFill = DrivePacket->NumSectors * 512;
		if(DrivePacket->Net){
			NetCall.Function = LOAD_SECTOR;
			NetCall.Cylinder = DrivePacket->Cylinder;
			NetCall.Drive = DrivePacket->Drive;
			NetCall.Head = DrivePacket->Head;
			NetCall.Sector = DrivePacket->Sector;
			NetCall.NumSectors = DrivePacket->NumSectors;
			NetCall.NTRelativeSector = DrivePacket->NTRelativeSector;
			NetCall.RelativeSector = 0;
			NetCall.Flag = DrivePacket->Flag;
			send(SocketNum, (char *) &NetCall, sizeof(SECTOR_FUNC), 0);
			CallNet();
		}
		else if(gOSWin95){
			if(!(DllThunk32)(DrivePacket->Drive, DrivePacket->Cylinder, DrivePacket->Head, 
					DrivePacket->Sector, DrivePacket->NumSectors, (LPBYTE)BufferDir, DrivePacket->NTRelativeSector, DrivePacket->Flag)){
				AfxMessageBox("Extended partition not accessible!");
				return;
			}
		}
		else{
			__int64 Tmp64 = ((__int64) DrivePacket->NTRelativeSector) * 512;
			long TmpVal = Tmp64 & 0xFFFFFFFF;
			long TmpValHi = (Tmp64 >> 32);
			SetFilePointer(hDisk[DrivePacket->Drive], TmpVal, &TmpValHi, FILE_BEGIN);
			TmpVal = 0;
			ReadFile(hDisk[DrivePacket->Drive], BufferDir, DrivePacket->NumSectors * 512, (DWORD *) &TmpVal, NULL);
			if(TmpVal != (DrivePacket->NumSectors * 512)){
				AfxMessageBox("Extended partition not accessible!");
				return;
			}
		}
		PartitionTable = (PARTITION *) (BufferDir+0x1BE);
		for(i=0; i<4; i++){
			switch(PartitionTable->SysInd)
			{
			case 0:
				continue;
				break;
			case PART_DOS2_FAT:
				strcpy(TmpStr, "12-Bit FAT Disk");
				break;
			case PART_DOS3_FAT:
				strcpy(TmpStr, "16-Bit FAT Disk");
				break;
			case PART_EXTENDED:
				strcpy(TmpStr, "Extended DOS Partition");
				break;
			case PART_DOS4_FAT:
				strcpy(TmpStr, "16-Bit FAT Disk");
				break;
			case PART_DOS32:
				strcpy(TmpStr, "32-Bit FAT Disk");			//Normal FAT32
				break;
			case PART_DOS32X:
				strcpy(TmpStr, "32-Bit FAT Disk");			//FAT32 with int 13 extension
				break;
			case PART_DOSX13:
				strcpy(TmpStr, "16-Bit FAT Disk");			//Extended int 13
				break;
			case PART_DOSX13X:
				strcpy(TmpStr, "Extended 32-bit Partition");			//Extended DOS partition in int 13 extension
				break;
			default:
				strcpy(TmpStr, "Unknown");
				break;
			}
			Packets->Cylinder = PartitionTable->Cylinder;
			Packets->Drive = DrivePacket->Drive;
			Packets->Flag = DrivePacket->Flag;
			Packets->Head = PartitionTable->Head;
			Packets->NumSectors = 1;
			Packets->Sector = PartitionTable->Sector;
			Packets->RelativeSector = 0;
			Packets->Type = ((PartitionTable->SysInd == PART_EXTENDED) || (PartitionTable->SysInd == PART_DOSX13X)) ? EXTENDED_PART:BOOT_RECORD;
			Packets->FatType = ((PartitionTable->SysInd == PART_DOS32) || (PartitionTable->SysInd == PART_DOS32X)) ? FAT32:0;
			if((PartitionTable->SysInd == PART_EXTENDED) || (PartitionTable->SysInd == PART_DOSX13X)){
				PrevRelSector = PartitionTable->RelativeSector;
				Packets->NTRelativeSector = PrevRelSector + MainPrevRelSector;
			}
			else{
				Packets->NTRelativeSector = MainPrevRelSector + PrevRelSector + PartitionTable->RelativeSector;
			}

			Packets->Net = DrivePacket->Net;
			TvI.mask = TVIF_CHILDREN | TVIF_TEXT | TVIF_PARAM;
			TvI.pszText = TmpStr;
			if(UnknownPart){
				Packets->RelativeSector = 1;
				Packets->TotalSectors = 0xFFFFFFFF;
				TvI.cChildren = 0;
			}
			else{
				Packets->RelativeSector = 0;
				TvI.cChildren = 1;
			}
			TvI.lParam = (long)Packets++;

			TvIns.item = TvI;
			TvIns.hParent = (HTREEITEM) pNMTreeView->itemNew.hItem;
			TvIns.hInsertAfter = hPrev;
			hPrev = DiskTree->InsertItem((LPTVINSERTSTRUCT) &TvIns);
			PartitionTable++;
		}
		LocalUnlock(hMemBufferDir);
		LocalFree(hMemBufferDir);
		break;
		}
	case BOOT_RECORD:{
		hMemBufferDir = LocalAlloc(LMEM_MOVEABLE|LMEM_DISCARDABLE|LMEM_ZEROINIT, DrivePacket->NumSectors * 512);
		if(hMemBufferDir == NULL){
			AfxMessageBox("Fatal Error!  Not able to allocate a Buffer!");
			return;
		}
		BufferDir = (LPBYTE) LocalLock(hMemBufferDir);
		BufferNet = BufferDir;
		NetEvent = BUFFER_FILL;
		memcpy(&gDrivePacket, DrivePacket, sizeof(gDrivePacket));
		BytesToFill = DrivePacket->NumSectors * 512;
		if(DrivePacket->Net){
			NetCall.Function = LOAD_SECTOR;
			NetCall.Cylinder = DrivePacket->Cylinder;
			NetCall.Drive = DrivePacket->Drive;
			NetCall.Head = DrivePacket->Head;
			NetCall.Sector = DrivePacket->Sector;

⌨️ 快捷键说明

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