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

📄 cdburndlg.cpp

📁 使用Windows IMAPI编写的光盘刻录程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	}	
}

void CCDBurnDlg::OnBnClickedDelete()
{
	WIN32_FIND_DATA FindFile;
	HANDLE hFind = NULL;
	CString sTotalSize;
	int ItemIndex;
	UINT Counter = 0;
	ItemIndex = AddedItemsList.GetNextItem(-1,LVNI_SELECTED);
	while(ItemIndex != -1)
	{		
		CString Name;
		CString Type;
		Name = AddedItemsList.GetItemText(ItemIndex,0);
		Type = AddedItemsList.GetItemText(ItemIndex,1);
		if(IndexPath.IsEmpty())
		{
			if(strcmp(Type,"File") == 0)
			{
				hFind = FindFirstFile(FileList[Counter],&FindFile);
				while(strcmp(Name,FindFile.cFileName) != 0)
				{
					Counter ++;
					FindFirstFile(FileList[Counter],&FindFile);
				}
				FilesSize = FilesSize - (FindFile.nFileSizeHigh*MAXDWORD + FindFile.nFileSizeLow);
				TotalSize = (FilesSize+0.01)/1024/1024;
				sTotalSize.Format("%4.2f%s",TotalSize," MB");
				SetDlgItemText(IDC_TOTALSIZE,sTotalSize);				
				while(!FileList[Counter+1].IsEmpty())
				{
					FileList[Counter] = FileList[Counter+1];
					Counter++;
				}
				FileList[Counter] = "";
			}
			if(strcmp(Type,"Folder") == 0)
			{
				FindFirstFile(FolderList[Counter],&FindFile);
				while(strcmp(Name,FindFile.cFileName) != 0)
				{
					Counter ++;
					FindFirstFile(FolderList[Counter],&FindFile);
				}
				FilesSize = FilesSize - FolderSize(FolderList[Counter],IndexPath);
				TotalSize = (FilesSize+0.01)/1024/1024;
				sTotalSize.Format("%4.2f%s",TotalSize," MB");
				SetDlgItemText(IDC_TOTALSIZE,sTotalSize);
				
				while(!FolderList[Counter+1].IsEmpty())
				{
					FolderList[Counter] = FolderList[Counter+1];
					Counter++;
				}
				FolderList[Counter] = "";
			}
		}
		else
		{
			int count = 0;
			int count1 = 0;
			while(!ListPath[count].IsEmpty())
			{
				count++;
			}
			count = count - 1;
			while(!DeleteList[Counter].IsEmpty())
			{
				Counter++;
			}
			DeleteList[Counter] = IndexPath;
			hFind = FindFirstFile(AddedList[count1+1],&FindFile);
			while(!AddedList[count1].IsEmpty()&&(strcmp(AddedList[count1],IndexPath)!=0||strcmp(FindFile.cFileName,Name)!=0))
			{
				count1 = count1 + 2;		
				hFind = FindFirstFile(AddedList[count1+1],&FindFile);
			}
			if(AddedList[count1].IsEmpty())
			{
				DeleteList[Counter+1] = ListPath[count] + "\\" + Name;
				if(strcmp(Type,"File") == 0)
				{
					hFind = FindFirstFile(DeleteList[Counter+1],&FindFile);
					FilesSize = FilesSize - (FindFile.nFileSizeHigh*MAXDWORD + FindFile.nFileSizeLow);
					TotalSize = (FilesSize+0.01)/1024/1024;
					sTotalSize.Format("%4.2f%s",TotalSize," MB");
					SetDlgItemText(IDC_TOTALSIZE,sTotalSize);
				}
				if(strcmp(Type,"Folder") == 0)
				{
					FilesSize = FilesSize - FolderSize(DeleteList[Counter+1],IndexPath);
					TotalSize = (FilesSize+0.01)/1024/1024;
					sTotalSize.Format("%4.2f%s",TotalSize," MB");
					SetDlgItemText(IDC_TOTALSIZE,sTotalSize);	
				}
			}
			else
			{
				DeleteList[Counter+1] = AddedList[count1+1];
				if(strcmp(Type,"File") == 0)
				{
					hFind = FindFirstFile(DeleteList[Counter+1],&FindFile);
					FilesSize = FilesSize - (FindFile.nFileSizeHigh*MAXDWORD + FindFile.nFileSizeLow);
					TotalSize = (FilesSize+0.01)/1024/1024;
					sTotalSize.Format("%4.2f%s",TotalSize," MB");
					SetDlgItemText(IDC_TOTALSIZE,sTotalSize);
				}
				if(strcmp(Type,"Folder") == 0)
				{
					FilesSize = FilesSize - FolderSize(DeleteList[Counter+1],IndexPath);
					TotalSize = (FilesSize+0.01)/1024/1024;
					sTotalSize.Format("%4.2f%s",TotalSize," MB");
					SetDlgItemText(IDC_TOTALSIZE,sTotalSize);	
				}				
				DeleteList[Counter].Empty();
				DeleteList[Counter+1].Empty();
				AddedList[count1].Empty();
				AddedList[count1+1].Empty();
				while(!AddedList[count1+2].IsEmpty())
				{
					AddedList[count1] = AddedList[count+2];
					AddedList[count1+1] = AddedList[count+3];
					count1 = count1 + 2;
				}
				AddedList[count1].Empty();
				AddedList[count1+1].Empty();
			}		
		}
		AddedItemsList.DeleteItem(ItemIndex);
		ItemIndex = AddedItemsList.GetNextItem(-1,LVNI_SELECTED);
		Counter = 0;
	}
}

void CCDBurnDlg::OnBnClickedBurn()
{
	HRESULT hr;	
	if(MyCD.AvailRecorder)
	{
		if(!MyCD.AvailDisc)
		{
			MessageBox("Please Insert Available Disc !","Burn Failed");
		}
		else
		{
			if(FileList[0].IsEmpty()&&FolderList[0].IsEmpty())
			{
				MessageBox("Please Select Files or Folders to be Burned !","Add File or Folder");
			}
			else
			{
				ULONGLONG temp = MyCD.DiscSpace;
				temp = temp*1024*1024;
				if(temp<FilesSize)
				{
					MessageBox("Insufficient Disc Space !","Burn Failded");
				}
				else
				{
					KillTimer(1);
					hr = MyCD.CDBurn(FileList,FolderList,DeleteList,AddedList,&BurnProgress);
					SetTimer(1,2000,NULL);
				}
			}
		}
	}
	else
	{
		MessageBox("No Available Recorder !","Burn Failed");
	}
	BurnProgress.SetPos(0);
}

ULONGLONG CCDBurnDlg::FolderSize(CString Folder,CString IndexPath)
{
	WIN32_FIND_DATA fd;
	HANDLE hFind = NULL;
	ULONGLONG Size = 0;
	UINT count = 0;
	BOOL bLoop;

	hFind = FindFirstFile(Folder,&fd);
	if(IndexPath.IsEmpty())
	{
		IndexPath = fd.cFileName;
	}
	else
	{
		IndexPath = IndexPath + "\\" + fd.cFileName;
	}
    hFind = FindFirstFile(Folder + "\\*.*",&fd);
	if(hFind != INVALID_HANDLE_VALUE)
	{ 
		bLoop = TRUE;
		while(bLoop) 
		{
			BOOL bDelFlag = TRUE;
			CString TempString = Folder + "\\" +fd.cFileName;
			count = 0;
			while(!DeleteList[count].IsEmpty()&&(strcmp(DeleteList[count],IndexPath)!=0||strcmp(DeleteList[count+1],TempString)!=0))
			{
				count = count + 2;
			}
			if(!DeleteList[count].IsEmpty())
			{
				bDelFlag = FALSE;
			}	
			if((fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)&&strcmp(fd.cFileName,".") != 0&&strcmp(fd.cFileName,"..") != 0&&bDelFlag)
			{				
				Size = Size + FolderSize(Folder + "\\" +fd.cFileName,IndexPath);			
			}			
			if((!(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))&&strcmp(fd.cFileName,".") != 0&&strcmp(fd.cFileName,"..") != 0&&bDelFlag)
			{
				Size = Size + fd.nFileSizeHigh*MAXDWORD + fd.nFileSizeLow;
			}		
			bLoop = FindNextFile(hFind,&fd);
		}
		FindClose(hFind);		
	}
	count = 0;

	while(!AddedList[count].IsEmpty())
	{
		if(strcmp(AddedList[count],IndexPath)==0)
		{
			hFind = FindFirstFile(AddedList[count+1],&fd);
			if(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
			{
				Size = Size + FolderSize(AddedList[count+1],IndexPath);			
			}
			else
			{
				Size = Size + fd.nFileSizeHigh*MAXDWORD + fd.nFileSizeLow;
			}
		}
		count = count + 2;
	}
	return Size;
}

ULONGLONG CCDBurnDlg::FirstFolderSize(CString Folder)
{
	WIN32_FIND_DATA fd;
	HANDLE hFind = NULL;
	BOOL bLoop;
	CString StartPath = Folder;
	ULONGLONG TotalFolderSize = 0;	

	hFind = FindFirstFile(StartPath + "\\*.*",&fd);
	if(hFind != INVALID_HANDLE_VALUE)
	{
		bLoop = TRUE;
		while(bLoop)
		{
			if((fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)&&strcmp(fd.cFileName,".") != 0&&strcmp(fd.cFileName,"..") != 0)
			{
				TotalFolderSize = TotalFolderSize + FirstFolderSize(StartPath  + "\\" + fd.cFileName);	
			}
			if(strcmp(fd.cFileName,".") != 0&&strcmp(fd.cFileName,"..") != 0)
			{
				TotalFolderSize = TotalFolderSize +fd.nFileSizeHigh*MAXDWORD + fd.nFileSizeLow;
			}
			bLoop = FindNextFile(hFind,&fd);
		}		
		FindClose(hFind);
	}
	return TotalFolderSize;
}



void CCDBurnDlg::OnTimer(UINT nIDEvent)
{
	HRESULT hr;
	byte pbsessions;
	byte pblasttrack; 
	ULONG ulstartaddress;
	ULONG ulnextwritable; 
	ULONG ulfreeblocks; 
	if(MyCD.AvailRecorder)
	{
		hr = MyCD.pRecorder->OpenExclusive();
		hr = MyCD.pRecorder->QueryMediaInfo(&pbsessions,&pblasttrack,&ulstartaddress,&ulnextwritable,&ulfreeblocks);
		if(hr != S_OK)
		{
			MyCD.AvailDisc = FALSE;
			MyCD.DiscSpace = 0;
			SetDlgItemText(IDC_DISCSPACE,"No Available Disc in the Recorder !");
		}
		else
		{
			CString sDiscSpace;
			MyCD.AvailDisc = TRUE;
			MyCD.DiscSpace = ulfreeblocks/512;
			sDiscSpace.Format("%d%s",MyCD.DiscSpace," MB");
			SetDlgItemText(IDC_DISCSPACE,sDiscSpace);
		}
		hr = MyCD.pRecorder->Close();
	}
}

void CCDBurnDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码

	OnOK();
}

void CCDBurnDlg::OnNMDblclkAddeditems(NMHDR *pNMHDR, LRESULT *pResult)
{
	WIN32_FIND_DATA FindFile;
	HANDLE hFind = NULL;
	CString sTotalSize;
	CString sFileSize;
	CString sFileTime;
	FILETIME FileTime;
	BOOL bLoop;
	ULONGLONG FileSize = 0;
	UINT ItemIndex;	
	UINT nItem = 0;
	UINT Counter = 0;
	UINT count = 0;

	ItemIndex = AddedItemsList.GetNextItem(-1,LVNI_SELECTED);
	if(ItemIndex != -1)
	{
		CString Name = AddedItemsList.GetItemText(ItemIndex,0);
		CString Type = AddedItemsList.GetItemText(ItemIndex,1);
		if(strcmp(Type,"Folder") == 0)
		{
			if(IndexPath.IsEmpty())
			{	
				FindFirstFile(FolderList[Counter],&FindFile);
				while(strcmp(Name,FindFile.cFileName) != 0)
				{
					Counter ++;
					FindFirstFile(FolderList[Counter],&FindFile);
				}
				IndexPath = Name;
				ListPath[0] = FolderList[Counter];
			}
			else
			{
				Counter = 0;				
				while(!ListPath[Counter].IsEmpty())

⌨️ 快捷键说明

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