(Click inside to see a full size image.)
This is the last of a multi part lecture on checking the space on your hard drive, etc. It's now a true Windows program. ('95, '98, 'NT')
Well, after three months we've finally made it! The program for this month is the third installment of the DSIZ window program that I have been promising. The program is based on a dialog box and has icons for selecting the path, starting the program, exiting, and bring up the notepad. In addition it has an edit box which allows manually typing in the computer path.
The most exciting part of this program is the fact that it uses threads. All windows programs use a main thread, but when the program needs to search the directories and calculate the space, it starts a second thread called a worker thread. This is a completely separate path of execution which occurs simultaneously with the main thread. This is just incredible and turns the resulting functionality from a "ho-hum" program into something quite professional!
Object: To inventory all file space used on a hard drive and display a sorted list of the top level sub directories and the total space occupied under each one. This is now a 32 bit application. Enhancements include the use of computed cluster sizes. (compiler: Microsoft VC++ 5.0 )
Based on the concepts developed in July and August, the program uses methods for determining disk space on a Windows 95 or 98 computer using the FAT32 disk structure. It also handles the NTFS file structure on a WindowsNT computer as well as various network systems.
"Random Access" questions start at 7:30 Tuesday night. See you there.
See SOURCE CODE links below.
UINT SearchThread( LPVOID pParam) // Controlling function -- WORKER THREAD { CDsizWDlg *mDlg = (CDsizWDlg *) pParam; mDlg->PostMessage(WM_MYMOUSEUPDATE,TRUE); mDlg->m_progress.SetPos(0); mDlg->m_progress.ShowWindow(SW_SHOW); mDlg->m_progress.SetStep(1); process( 3, mDlg->m_cmds, mDlg); mDlg->m_progress.ShowWindow(SW_HIDE); mDlg->PostMessage(WM_MYMOUSEUPDATE,FALSE); mDlg->m_Act.SetWindowText(" "); return 0; } int process(int argc, char *argv[], CDsizWDlg *myDialog) { char root[_MAX_PATH] = "\\", mytime[20], mydate[20], estimated[20]=""; char info[_MAX_PATH]; if (argc==1) { puts(VERSION); return 1; } Tsize=Gsize=gFileCount=gFolderCount=gCluster=0L; pDlg = myDialog; _strdate(mydate); _strtime(mytime); strcpy(info,pDlg->m_NetworkPath); CDiskInfo Homedrive; // save startup info CPathInfo Target(argv[1]); // parse command line argument // Attempt to change to new drive and check that is was successful. // if (Target.DKnumber <= 26) _chdrive(Target.DKnumber); // 1=A, 2=B, ... if (Target.DKnumber != _getdrive()) { puts("+++ Disk Selection Error +++\007"); return 2; } if (*Target.dir) strcpy(root,Target.dir); // adjust root starting point CDiskInfo *Newdrive = new CDiskInfo(); // store info about new drive gCluster = Newdrive->Cluster; // save value in global varable // cluster information is not accurate over microsoft networks. if (Newdrive->drive_type==DRIVE_REMOTE) { gCluster = 4096; // save value in global varable strcpy(estimated," estimated"); } search(root); // Do a RECURSIVE file search sprintf(out_buff," ------\t------------------------------------"); hprintf(out_buff,1); sprintf(out_buff,"%6ld\tMB_used in %ld files (%ld folders)", megabytes(Gsize), gFileCount, gFolderCount); hprintf(out_buff,1); sprintf(out_buff,"%6ld\tMB_total disk capacity", (Newdrive->KBtotal >> 10)); hprintf(out_buff,1); sprintf(out_buff,"%6ld\tMB_available (megabytes)", (Newdrive->KBavail >> 10) ); hprintf(out_buff,1); sprintf(out_buff," ------\t------------------------------------");hprintf(out_buff,0); sprintf(out_buff," Date\t%s %s", mydate, mytime ); hprintf(out_buff,0); sprintf(out_buff," Clustr\t%ld bytes%s", gCluster, estimated); hprintf(out_buff,0); sprintf(out_buff," Type\t%s", DTypes[Newdrive->drive_type]); hprintf(out_buff,0); sprintf(out_buff," Path\t%s", root ); hprintf(out_buff,0); sprintf(out_buff," Info\t%s", info ); hprintf(out_buff,0); sprintf(out_buff," Drive\t%c:", Newdrive->DKletter ); hprintf(out_buff,0); delete Newdrive; // Restore original settings. return 0; }