home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / FILESYS.PAK / DEMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  16.8 KB  |  618 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995 Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:    Demo.c
  9. //
  10. //  PURPOSE:   Displays the "DEMOTABCTRL" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    DemoDlgProc      - Processes messages for "DemoTabCtrl" dialog box.
  14. //    MsgDemoInit      - To initialize the about box with version info 
  15. //                       from resources.
  16. //    MsgDemoCommand   - Process WM_COMMAND message sent to the about box.
  17. //    CmdDemoDone      - Free the about box and related data.
  18. //    CmdDemoTabCtrl   - Command messages for the tab control. 
  19. //                       Specifically the TCN_SELCHANGE message.
  20. //    CreateTabControl - Creates the tab control window. 
  21. //    InitTabControl   - Initializes the tab control with tabs
  22. //
  23. //  COMMENTS:
  24. //
  25. //
  26.  
  27. #include <windows.h>            // required for all Windows applications
  28. #include <windowsx.h>
  29. #include <commctrl.h>
  30. #include "globals.h"            // prototypes specific to this application
  31. #include "demo.h"
  32.  
  33.  
  34. // Global variables
  35.  
  36.  
  37. // Local function prototypes
  38. LRESULT MsgDemoCommand      (HWND, UINT, WPARAM, LPARAM);
  39. LRESULT MsgDemoInit         (HWND, UINT, WPARAM, LPARAM);
  40. LRESULT CmdDemoDone         (HWND, WORD, WORD, HWND);
  41. LRESULT CmdDemoLogDrives    (HWND, WORD, WORD, HWND);
  42. void    ResetDemoDialog        (HWND);
  43.  
  44.  
  45. // Demo dialog message table definition.
  46. MSD rgmsdDemo[] =
  47. {
  48.     {WM_COMMAND,     MsgDemoCommand},
  49.     {WM_INITDIALOG,  MsgDemoInit   }
  50. };
  51.  
  52. MSDI msdiDemo =
  53. {
  54.     sizeof(rgmsdDemo) / sizeof(MSD),
  55.     rgmsdDemo,
  56.     edwpNone
  57. };
  58.  
  59. // Demo dialog command table definition.
  60. CMD rgcmdDemo[] =
  61. {
  62.     {IDOK,           CmdDemoDone},
  63.     {IDCANCEL,       CmdDemoDone},
  64.     {IDM_LOGDRIVES,  CmdDemoLogDrives}
  65. };
  66.  
  67. CMDI cmdiDemo =
  68. {
  69.     sizeof(rgcmdDemo) / sizeof(CMD),
  70.     rgcmdDemo,
  71.     edwpNone
  72. };
  73.  
  74.  
  75. //
  76. //  FUNCTION: DemoDlgProc(HWND, UINT, WPARAM, LPARAM)
  77. //
  78. //  PURPOSE:  Processes messages for "Demo" dialog box.
  79. //
  80. //  PARAMETERS:
  81. //    hdlg     - window handle of the dialog box
  82. //    wMessage - type of message
  83. //    wparam   - message-specific information
  84. //    lparam   - message-specific information
  85. //
  86. //  RETURN VALUE:
  87. //    TRUE  - message handled
  88. //    FALSE - message not handled
  89. //
  90. //  COMMENTS:
  91. //
  92. //     Display the File System information inside the dialog box. 
  93. //
  94. //     Wait for user to click on "Ok" button, then close the dialog box.
  95. //
  96.  
  97. LRESULT CALLBACK DemoDlgProc(HWND   hdlg,
  98.                              UINT   uMessage,
  99.                              WPARAM wparam,
  100.                              LPARAM lparam)
  101. {
  102.  
  103.     return DispMessage(&msdiDemo, hdlg, uMessage, wparam, lparam);
  104.  
  105. }
  106.  
  107.  
  108. //
  109. //  FUNCTION: MsgDemoCommand(HWND, UINT, WPARAM, LPARAM)
  110. //
  111. //  PURPOSE: Process WM_COMMAND message sent to the Demo box.
  112. //
  113. //  PARAMETERS:
  114. //    hwnd - The window handing the message.
  115. //    uMessage - The message number. (unused).
  116. //    wparam - Message specific data (unused).
  117. //    lparam - Message specific data (unused).
  118. //
  119. //  RETURN VALUE:
  120. //    Always returns 0 - message handled.
  121. //
  122. //  COMMENTS:
  123. //    Uses this DipsCommand function defined in wndproc.c combined
  124. //    with the cmdiDemo structure defined in this file to handle
  125. //    the command messages for the Demo dialog box.
  126. //
  127.  
  128. #pragma argsused
  129. LRESULT MsgDemoCommand (HWND   hwnd,
  130.                         UINT   uMessage, 
  131.                         WPARAM wparam, 
  132.                         LPARAM lparam)
  133. {
  134.  
  135.     return DispCommand(&cmdiDemo, hwnd, wparam, lparam);
  136.  
  137. }
  138.  
  139.  
  140. //
  141. //  FUNCTION: MsgDemoInit(HWND, UINT, WPARAM, LPARAM)
  142. //
  143. //  PURPOSE: To initialize the Demo box with version info from resources.
  144. //
  145. //  PARAMETERS:
  146. //    hwnd - The window handing the message.
  147. //    uMessage - The message number. (unused).
  148. //    wparam - Message specific data (unused).
  149. //    lparam - Message specific data (unused).
  150. //
  151. //  RETURN VALUE:
  152. //    Always returns 0 - message handled.
  153. //
  154. //  COMMENTS:
  155. //   
  156. //   
  157. //
  158.  
  159. #pragma argsused
  160. LRESULT MsgDemoInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  161. {
  162.     // Center the dialog over the application window
  163.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  164.  
  165.     // Obtain all logical drives on the system.
  166.     GetDrivesOnSystem(hdlg, GetDlgItem(hdlg, IDM_LOGDRIVES));
  167.  
  168.     // Get Volume information. 
  169. //    GetVolumeInfo(hdlg);
  170.  
  171.     return TRUE;
  172. }
  173.  
  174.  
  175. //
  176. //  FUNCTION: CmdDemoDone(HWND, WORD, HWND)
  177. //
  178. //  PURPOSE: Free the Demo box and related data.
  179. //
  180. //  PARAMETERS:
  181. //    hwnd - The window handling the command.
  182. //    wCommand - The command to be handled (unused).
  183. //    hwndCtrl - NULL (unused).
  184. //
  185. //  RETURN VALUE:
  186. //    Always returns TRUE.
  187. //
  188. //  COMMENTS:
  189. //    Calls EndDialog to finish the dialog session. Also calls Shell_Terminate
  190. //    to uninitialze the shell library. This API is not yet documented. 
  191. //    Also, destroys all the demo dialogs by calling DestroyWindow().
  192. //
  193.  
  194. #pragma argsused
  195. LRESULT CmdDemoDone(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  196. {
  197.     EndDialog(hdlg, TRUE);
  198.     return TRUE;
  199. }
  200.  
  201.  
  202.  
  203.  
  204. //
  205. //  FUNCTION: CmdDemoLogDrives(HWND, WORD, HWND)
  206. //
  207. //  PURPOSE: Process the drive change information
  208. //
  209. //  PARAMETERS:
  210. //    hwnd - The window handling the command.
  211. //    wCommand - The command to be handled (unused).
  212. //    hwndCtrl - NULL (unused).
  213. //
  214. //  RETURN VALUE:
  215. //    Always returns TRUE.
  216. //
  217. //  COMMENTS:
  218. //
  219.  
  220. #pragma argsused
  221. LRESULT CmdDemoLogDrives(HWND hdlg,
  222.                          WORD wCommand,
  223.                          WORD wNotify,
  224.                          HWND hwndCtrl)
  225. {
  226.     char  szBuffer[100];
  227.     
  228.     if(wNotify == CBN_SELCHANGE)
  229.     {
  230.         ComboBox_GetText(hwndCtrl, szBuffer, sizeof(szBuffer));
  231.         GetLogDriveInfo(hdlg, szBuffer);    
  232.         GetDiskInfo(hdlg, szBuffer);    
  233.         GetVolumeInfo(hdlg, szBuffer);
  234.     }
  235.     return 0;
  236. }
  237.  
  238. //
  239. //  FUNCTION: GetDrivesOnSystem(HWND, hWndCtl)
  240. //
  241. //  PURPOSE: Find all the drives on the system
  242. //
  243. //  PARAMETERS:
  244. //    hwnd - The window handle of the dialog.
  245. //    
  246. //    
  247. //
  248. //  RETURN VALUE:
  249. //      Always returns TRUE.
  250. //
  251. //  COMMENTS:
  252. //      This function fills the drives combobox with all the
  253. //      drives (physical and logical) connected to the system.
  254. //
  255. //
  256.  
  257. LRESULT GetDrivesOnSystem(HWND hdlg, HWND hWndCtl)
  258. {
  259.     char   szLogBuffer[100];
  260.     HANDLE hHeap;
  261.     LPSTR  lpstr, lpSave;
  262.     static DWORD  bytesForDriveStrings;
  263.     static int    nNumDrives, nDriveNum;
  264.     
  265.     // calling GetLogicalDrives() with the second parameter
  266.     // set to NULL, it will return the number of bytes required
  267.     // to allocate for the buffer that will actually hold the 
  268.     // strings. 
  269.  
  270. /*******************************************************************
  271. THIS API IS EITHER BROKEN IN WINDOWS 95 OR NOT IMPLEMENENTED 
  272. IT RETURNS 0 AS THE RETURN VALUE AND ALSO, IT DOES NOT RETURN
  273. THE NAMES OF THE LOGICAL AND PHYSICAL DRIVES...
  274. ********************************************************************/
  275.  
  276.     bytesForDriveStrings = GetLogicalDriveStrings(0, 
  277.                            (LPSTR)NULL) * sizeof(char);
  278.     if(!bytesForDriveStrings)
  279.     {
  280.         MessageBox(NULL, 
  281.                    "GetLogicalDrives Function Failed",
  282.                    "ERROR",
  283.                    MB_OK);
  284.         return 0;
  285.     }
  286.     else
  287.     {
  288.     // GetLogicalDriveStrings() returned a positive value, so 
  289.     // allocate a buffer to hold the actual strings. 
  290.         hHeap = GetProcessHeap();
  291.         lpstr = (LPSTR) HeapAlloc(hHeap, 
  292.                                   HEAP_ZERO_MEMORY,
  293.                                   bytesForDriveStrings);
  294.         lpSave = lpstr;        // save the pointer so we can free it later
  295.     }
  296.  
  297.     // Get the strings into our buffer..this time..
  298.     GetLogicalDriveStrings((DWORD)HeapSize(hHeap, 0, lpstr),
  299.                             lpstr);
  300.  
  301.     while(*lpstr != 0)
  302.     {
  303.         (void) ComboBox_AddString(hWndCtl, lpstr);
  304.         nNumDrives++;                                    
  305.         lpstr = lpstr + lstrlen(lpstr) + 1;
  306.     }
  307.  
  308.     // We are done with Heap Allocation, so free it.
  309.  
  310.     HeapFree(hHeap, 0, lpSave);
  311.  
  312.     // Get the first fixed drive and get drive information about
  313.     // it, so that we don't try to read volume information from a 
  314.     // drive that does not have a disk. 
  315.     for(nDriveNum = 0; nDriveNum < nNumDrives; nDriveNum++)
  316.     {
  317.         (void) ComboBox_GetLBText(hWndCtl, nDriveNum, szLogBuffer);
  318.         if(GetDriveType(szLogBuffer) == DRIVE_FIXED)
  319.             break;
  320.     }
  321.  
  322.     if(nDriveNum == nNumDrives)
  323.     {
  324.         // there are no fixed drives...just use the first drive.
  325.         nDriveNum = 0;
  326.         (void) ComboBox_GetLBText(hWndCtl, nDriveNum, szLogBuffer);
  327.     }
  328.  
  329.     // Select the First fixed drive, or select the first 
  330.     // available drive.
  331.     (void) ComboBox_SetCurSel(hWndCtl, nDriveNum);
  332.  
  333.     // Fill the demo dialog, with the firt batch of information...
  334.     GetLogDriveInfo(hdlg, szLogBuffer);    
  335.     GetDiskInfo(hdlg, szLogBuffer);    
  336.     GetVolumeInfo(hdlg, szLogBuffer);
  337.  
  338.     return 0;
  339.  
  340. }
  341.  
  342.  
  343. //
  344. //  FUNCTION: GetLogDriveInfo(HWND, LPSTR)
  345. //
  346. //  PURPOSE: Fills the statics with drive information
  347. //
  348. //  PARAMETERS:
  349. //    hwnd - The window handle of the dialog.
  350. //    LPSTR - The String name of the drive in question
  351. //    
  352. //
  353. //  RETURN VALUE:
  354. //      Always returns TRUE.
  355. //
  356. //  COMMENTS:
  357. //      This function fills the static controls with the 
  358. //      various information about the drive. 
  359. //
  360. //
  361.  
  362. LRESULT GetLogDriveInfo(HWND hdlg, LPSTR lpstr)
  363. {           
  364.     int    driveType;
  365.     char   szBuffer[100];
  366.  
  367.  
  368.     //obtain the drive type information..
  369.     driveType = GetDriveType(lpstr) ;
  370.  
  371.     switch(driveType)
  372.     {
  373.  
  374.             case 0:
  375.                 lstrcpy((LPSTR)szBuffer, "DRIVE TYPE") ;
  376.                 lstrcat((LPSTR)szBuffer, "\t") ;
  377.                 lstrcat((LPSTR)szBuffer, "UNDETERMINABLE") ;
  378.                 SetDlgItemText(hdlg, IDM_DRIVETYPE, szBuffer);
  379.             break ;
  380.  
  381.             case 1:
  382.                 lstrcpy((LPSTR)szBuffer, "DRIVE TYPE") ;
  383.                 lstrcat((LPSTR)szBuffer, "\t") ;
  384.                 lstrcat((LPSTR)szBuffer, "PATH INVALID") ;
  385.                 SetDlgItemText(hdlg, IDM_DRIVETYPE, szBuffer);
  386.             break ;
  387.  
  388.             case DRIVE_FIXED:
  389.                 lstrcpy((LPSTR)szBuffer, "DRIVE TYPE") ;
  390.                 lstrcat((LPSTR)szBuffer, "\t") ;
  391.                 lstrcat((LPSTR)szBuffer, "FIXED DRIVE") ;
  392.                 SetDlgItemText(hdlg, IDM_DRIVETYPE, szBuffer);
  393.             break ;
  394.  
  395.             case DRIVE_REMOVABLE:
  396.                 lstrcpy((LPSTR)szBuffer, "DRIVE TYPE") ;
  397.                 lstrcat((LPSTR)szBuffer, "\t") ;
  398.                 lstrcat((LPSTR)szBuffer, "REMOVABLE") ;
  399.                 SetDlgItemText(hdlg, IDM_DRIVETYPE, szBuffer);
  400.             break ;
  401.  
  402.  
  403.             default:
  404.             break;
  405.  
  406.     } //end of switch..
  407.  
  408.  
  409.     return 0;
  410.  
  411.  
  412. }
  413.  
  414.  
  415. //
  416. //  FUNCTION: GetVolumeInfo(HWND, LPSTR)
  417. //
  418. //  PURPOSE: Fills the statics with drive information
  419. //
  420. //  PARAMETERS:
  421. //    hwnd - The window handle of the dialog.
  422. //    LPSTR - The String name of the drive in question
  423. //    
  424. //
  425. //  RETURN VALUE:
  426. //      Always returns TRUE.
  427. //
  428. //  COMMENTS:
  429. //      This function fills the static controls with the 
  430. //      various information about the drive. 
  431. //
  432. //
  433.  
  434. LRESULT  GetVolumeInfo(HWND  hdlg, LPSTR lpstr) 
  435. {
  436.     // char    szRootPathName[50]; 
  437.     char    szFileSystemName[50],  szVolumeName[50];
  438.     char    szBuffer[50]; 
  439.  
  440.  
  441.     
  442.     // DWORD   cbVolumeName, cbFileSystemName;
  443.     DWORD   VolumeSerNum, MaxCompLen, FileSysFlags ;
  444.     BOOL    retVal ;
  445.  
  446.       
  447.     retVal = GetVolumeInformation(lpstr,
  448.                                   (LPSTR)szVolumeName, 
  449.                                   50, 
  450.                                   &VolumeSerNum, 
  451.                                   &MaxCompLen,
  452.                                   &FileSysFlags, 
  453.                                   (LPSTR)szFileSystemName, 
  454.                                   50);
  455.           
  456.     if(!retVal) 
  457.     {
  458.         MessageBox(NULL,
  459.                    "GetVolumeInformation Failed:\r\nPlease Check your Drive Letter:", 
  460.                    "ERROR",   
  461.                     MB_OK | MB_ICONSTOP);
  462.  
  463.         ResetDemoDialog(hdlg);
  464.         return 0;
  465.     }
  466.  
  467.  
  468.     // Fill all the static controls with the available information....
  469.     // First fill in the volume name
  470.     lstrcpy((LPSTR)szBuffer, "Volume Name:") ;
  471.     lstrcat((LPSTR)szBuffer, "\t") ;
  472.     lstrcat((LPSTR)szBuffer, (LPSTR)szVolumeName) ;
  473.     SetDlgItemText(hdlg, IDM_VOLNAME, szBuffer);
  474.  
  475.     // fill in the serial number
  476.     wsprintf((LPSTR)szBuffer, "Serial Number:\t%d",  VolumeSerNum) ;
  477.     SetDlgItemText(hdlg, IDM_SERIALNUM, szBuffer);
  478.     
  479.     // fill in the component length information
  480.     wsprintf((LPSTR)szBuffer, "Component Len:\t%d", MaxCompLen) ;
  481.     SetDlgItemText(hdlg, IDM_COMPLENGTH, szBuffer);
  482.  
  483.     // fill in the File system name
  484.     wsprintf((LPSTR)szBuffer, "File System:\t%s", (LPSTR)szFileSystemName);
  485.     SetDlgItemText(hdlg, IDM_FILESYSTEM, szBuffer);
  486.                       
  487.     // fill in the flie system Flags
  488.     if(FileSysFlags & FS_CASE_IS_PRESERVED)
  489.     {
  490.         wsprintf((LPSTR)szBuffer, 
  491.                  "System Flag:\t%s",
  492.                  (LPSTR)"CASE PRESERVED");
  493.         SetDlgItemText(hdlg, IDM_SYSFLAGS, szBuffer);
  494.     }
  495.             
  496.     if(FileSysFlags & FS_CASE_SENSITIVE)
  497.     {
  498.         wsprintf((LPSTR)szBuffer, 
  499.                  "System Flag:\t%s", 
  500.                  (LPSTR)"CASE SENSITIVE");
  501.         SetDlgItemText(hdlg, IDM_SYSFLAGS, szBuffer);
  502.     }
  503.     
  504.     if(FileSysFlags & FS_UNICODE_STORED_ON_DISK)
  505.     {
  506.         wsprintf((LPSTR)szBuffer, 
  507.                  "System Flag:\t%s", 
  508.                  (LPSTR)"UNICODE STORED");
  509.         SetDlgItemText(hdlg, IDM_SYSFLAGS, szBuffer);
  510.  
  511.     }
  512.          
  513.     return 0;                    
  514. }
  515.  
  516.  
  517. //
  518. //  FUNCTION: GetDiskInfo(HWND, LPSTR)
  519. //
  520. //  PURPOSE: Fills the statics with disk information
  521. //
  522. //  PARAMETERS:
  523. //    hwnd - The window handle of the dialog.
  524. //    LPSTR - The String name of the disk in question
  525. //    
  526. //
  527. //  RETURN VALUE:
  528. //      Always returns TRUE.
  529. //
  530. //  COMMENTS:
  531. //      This function fills the static controls with the 
  532. //      various information about the disk. 
  533. //
  534. //
  535.  
  536.  
  537. LRESULT GetDiskInfo(HWND hdlg, LPSTR lpstr)
  538. {
  539.     char    szBuffer[100] ;
  540.     DWORD     dwSectorsPerCluster, dwTotalClusters ;
  541.     DWORD   dwBytesPerSector,     dwFreeClusters ;
  542.         
  543.    if(GetDiskFreeSpace(lpstr,
  544.                        &dwSectorsPerCluster, 
  545.                        &dwBytesPerSector, 
  546.                        &dwFreeClusters,
  547.                        &dwTotalClusters))
  548.     {
  549.         wsprintf((LPSTR)szBuffer, 
  550.                  "Sectors/Cluster:\t%d", 
  551.                  dwSectorsPerCluster) ;
  552.         SetDlgItemText(hdlg, IDM_SECTORSINCLUSTER, szBuffer);
  553.  
  554.         wsprintf((LPSTR)szBuffer, 
  555.                  "Bytes/Sector:\t%d", 
  556.                  dwBytesPerSector) ;
  557.         SetDlgItemText(hdlg, IDM_BYTESINSECTOR, szBuffer);
  558.  
  559.         wsprintf((LPSTR)szBuffer, 
  560.                  "Free Clusters:\t%d", 
  561.                  dwFreeClusters) ;
  562.         SetDlgItemText(hdlg, IDM_FREECLUSTERS, szBuffer);
  563.  
  564.  
  565.         wsprintf((LPSTR)szBuffer, "Clusters:\t\t%d", dwTotalClusters) ;
  566.         SetDlgItemText(hdlg, IDM_CLUSTERS, szBuffer);
  567.  
  568.     }
  569.  
  570.     return 0;
  571. }
  572.  
  573.  
  574. void ResetDemoDialog(HWND hdlg)
  575. {
  576.  
  577.     char szBuffer[50];
  578.  
  579.         
  580.     lstrcpy((LPSTR)szBuffer, "Volume Name:");
  581.     SetDlgItemText(hdlg, IDM_VOLNAME, szBuffer);
  582.  
  583.     // fill in the serial number
  584.     lstrcpy((LPSTR)szBuffer, "Serial Number:");
  585.     SetDlgItemText(hdlg, IDM_SERIALNUM, szBuffer);
  586.     
  587.     // fill in the component length information
  588.     lstrcpy((LPSTR)szBuffer, "Component Len:") ;
  589.     SetDlgItemText(hdlg, IDM_COMPLENGTH, szBuffer);
  590.  
  591.     // fill in the File system name
  592.     lstrcpy((LPSTR)szBuffer, "File System:\t");
  593.     SetDlgItemText(hdlg, IDM_FILESYSTEM, szBuffer);
  594.  
  595.     // fill in the File system name                      
  596.     lstrcpy((LPSTR)szBuffer, "System Flag:");
  597.     SetDlgItemText(hdlg, IDM_SYSFLAGS, szBuffer);
  598.  
  599.     // fill in the File system name                      
  600.     lstrcpy((LPSTR)szBuffer, "Sectors/Cluster:");
  601.     SetDlgItemText(hdlg, IDM_SECTORSINCLUSTER, szBuffer);
  602.  
  603.     // fill in the File system name                      
  604.     lstrcpy((LPSTR)szBuffer, "Byte/Setor:");
  605.     SetDlgItemText(hdlg, IDM_BYTESINSECTOR, szBuffer);
  606.     
  607.     // fill in the File system name                      
  608.     lstrcpy((LPSTR)szBuffer, "Free Clusters:");
  609.     SetDlgItemText(hdlg, IDM_FREECLUSTERS, szBuffer);
  610.  
  611.     // fill in the File system name                      
  612.     lstrcpy((LPSTR)szBuffer, "Clusters:");
  613.     SetDlgItemText(hdlg, IDM_CLUSTERS, szBuffer);
  614.  
  615.     
  616.                 
  617. }
  618.