Annotation of q_a/samples/setinfo/setinfo.c, revision 1.1.1.3

1.1.1.3 ! root        1: 
        !             2: /******************************************************************************\
        !             3: *       This is a part of the Microsoft Source Code Samples. 
        !             4: *       Copyright (C) 1993 Microsoft Corporation.
        !             5: *       All rights reserved. 
        !             6: *       This source code is only intended as a supplement to 
        !             7: *       Microsoft Development Tools and/or WinHelp documentation.
        !             8: *       See these sources for detailed information regarding the 
        !             9: *       Microsoft samples programs.
        !            10: \******************************************************************************/
        !            11: 
1.1       root       12: /*************************************************************************\
                     13: *  PROGRAM: setinfo.c
                     14: *
                     15: *  PURPOSE:
                     16: *
                     17: *    To demonstrate queries and setting file information much as the
                     18: *    OS/2 API's DosQFileInfo() and DosSetFileInfo().
                     19: *
                     20: *  GLOBAL VARIABLES:
                     21: *
                     22: *    HANDLE hInst;  - Instance handle.
                     23: *
                     24: *    HWND   hWnd;   - Client window handle.
                     25: *
                     26: *    HWND   hWndDlg;- Window handle to upper dialog box.
                     27: *
                     28: *    HWND   hWndFileDlg;
                     29: *                   - Window handle to lower dialog box.
                     30: *
                     31: *    DWORD  StepTime;
                     32: *                   - Time in ms., used to control the speed of reporting
                     33: *                     return codes in the upper dialog box.
                     34: *
                     35: *  FUNCTIONS:
                     36: *
                     37: *    WinMain()      - Initializes the window, and process the message loop.
                     38: *    MainWndProc()  - To handle the messages to the main window.
                     39: *    StatusDlgProc()- To handle messages to the Status Dialog (upper) box.
                     40: *    FileDlgProc()  - To handle messages to the File Dialog (lower) box.
                     41: *    RepStat()      - To calculate return codes and to send results as
                     42: *                     messages to the StatusDlgProc()
                     43: *
                     44: *  COMMENTS:
                     45: *
                     46: *    Overview:
                     47: *      This sample captures and sets a files date/time, size, and
                     48: *      attributes information (note it does not *set* file size
                     49: *      information).  It also reports API return code status
                     50: *      information.
                     51: *
                     52: *    To Use:
                     53: *      Enter a file name into the appropriate edit field, and click on
                     54: *      the Get Info. button.  File information will be retrieved and
                     55: *      placed in the various edit fields and check buttons.  To set
                     56: *      file information, modify the values in the Time and Date edit
                     57: *      fields, and click the Set Info. button.  To set file attributes,
                     58: *      set the approprate check boxes, and click on the Set Attr. button.
                     59: *      Note this application does not check for rediculous Date and Time
                     60: *      information, and does not understand i.e. values before 1980 or after
                     61: *      2099.  The API are left to deal with such values as best they
                     62: *      can.
                     63: *
                     64: *      As the buttons are clicked the code sends return code status
                     65: *      information to be reported in the upper dialog box.  The user
                     66: *      can leave this reporting to be done at default time ( 0ms. Sleep
                     67: *      between each API), or can enter a time in the appropriate box
                     68: *      and clicking the Set Time button.  This will put a Sleep between
                     69: *      the API call so that the user can more easily read the return
                     70: *      codes.
                     71: *
                     72: *    Time Conversion:
                     73: *      Note that GetFileTime() and SetFileTime() use 64 bit FILETIME
                     74: *      structures.  These structure consist of two DWORD fields: which
                     75: *      represent file time in hundreds of nano-seconds.  This file time
                     76: *      can be converted into DosDate time (or back again) with the
                     77: *      FileTimeToDosDateTime() and DosDateTimeToFileTime() calls.  These
                     78: *      calls use WORD values representing DosDate and DosTime.  The
                     79: *      online Windows .hlp files will tell you how these WORDs break
                     80: *      down into days, months, hours, seconds, etc.  This sample uses
                     81: *      a combination of masking and shifting to extract the values
                     82: *      from the file (see the FileDlgProc() and the symbolic constants
                     83: *      mask defined in the header file).  Other points of interest are
                     84: *      that seconds are stored in 2 second increments (1-29), and that
                     85: *      years are represented from 1980 (meaning i.e. 1992 will be
                     86: *      be represented by 12).
                     87: *
                     88: *
                     89: \*************************************************************************/
                     90: 
                     91: #include <windows.h>
                     92: #include <stdlib.h>
                     93: #include "setinfo.h"
                     94: 
                     95: 
                     96: HANDLE hInst;
                     97: HWND   hWnd, hWndDlg, hWndFileDlg;
                     98: DWORD  StepTime;
                     99: 
                    100: 
                    101: 
                    102: /*************************************************************************\
                    103: *
                    104: *  FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
                    105: *
                    106: *  PURPOSE:  Calls initialization function, processes message loop.
                    107: *
                    108: *  COMMENTS: A fairly standard WinMain, with the exception that it
                    109: *            creates two modeless dialog boxes which fit over the window.
                    110: *            Note the use of IsDialogMessage in the message loop.  This
                    111: *            call not only returns a boolean value, but also processes
                    112: *            the message if it is a dialog box message; otherwise the
                    113: *            message falls through to the body of the loop to be translated
                    114: *            and dispatched.
                    115: *
                    116: \*************************************************************************/
                    117: 
                    118: int APIENTRY WinMain (HANDLE hInstance,
                    119:                       HANDLE hPrevInstance,
                    120:                       LPSTR  lpCmdLine,
                    121:                       int    nCmdShow)
                    122: 
                    123: 
                    124: {
                    125: 
                    126:   MSG  msg;
                    127:   WNDCLASS wc;
                    128:   RECT rect;
                    129: 
                    130:   UNREFERENCED_PARAMETER( lpCmdLine );
                    131:   UNREFERENCED_PARAMETER( hPrevInstance );
                    132: 
                    133:   hInst = hInstance;
                    134: 
1.1.1.3 ! root      135:   wc.style = 0;                          // Replaces CS_SIZEREDRAW.
1.1       root      136:   wc.lpfnWndProc = (WNDPROC)MainWndProc; // The client window procedure.
                    137:   wc.cbClsExtra = 0;                     // No room reserved for extra data.
                    138:   wc.cbWndExtra = 0;
                    139:   wc.hInstance = hInstance;
                    140:   wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
                    141:   wc.hCursor = LoadCursor (NULL, IDC_ARROW);
                    142:   wc.hbrBackground = GetStockObject (WHITE_BRUSH);
                    143:   wc.lpszMenuName = "";
                    144:   wc.lpszClassName = "SetInfoWClass";
                    145: 
                    146:   RegisterClass(&wc);
                    147: 
                    148:   hWnd = CreateWindow ("SetInfoWClass",
                    149:                        "Set File Info. Sample",
                    150:                        WS_OVERLAPPEDWINDOW,
                    151:                        CW_USEDEFAULT,
                    152:                        CW_USEDEFAULT,
                    153:                        CW_USEDEFAULT,
                    154:                        CW_USEDEFAULT,
                    155:                        NULL,
                    156:                        NULL,
                    157:                        hInstance,
                    158:                        NULL);
                    159: 
1.1.1.2   root      160:   hWndDlg     = CreateDialog (hInst, "StatusDlg", hWnd, (DLGPROC)StatusDlgProc);
                    161:   hWndFileDlg = CreateDialog (hInst, "FileDlg",   hWnd, (DLGPROC)FileDlgProc);
1.1       root      162: 
                    163:   GetClientRect (hWnd, &rect);
                    164:   SendMessage (hWnd, WM_SIZE, 0, (rect.right - rect.left));
                    165:   ShowWindow  (hWndDlg,  SW_SHOW);
                    166:   ShowWindow  (hWndFileDlg, SW_SHOW);
                    167:   ShowWindow  (hWnd, nCmdShow);
                    168: 
1.1.1.3 ! root      169:   while (GetMessage (&msg, NULL, 0, 0))
1.1       root      170:     if (!IsDialogMessage (hWndDlg, &msg)
                    171:         && !IsDialogMessage (hWndFileDlg, &msg))
                    172:       {
                    173:        DispatchMessage (&msg);   // Dispatch message to window.
                    174:       }
                    175: 
                    176:   return (msg.wParam);           // Returns value from PostQuitMessage.
                    177: 
                    178: }
                    179: 
                    180: /*************************************************************************\
                    181: *
                    182: *  FUNCTION:  MainWndProc (HWND, UINT, UINT, LONG)
                    183: *
                    184: *  PURPOSE:   To process messages.  To launch client and server threads
                    185: *             as appropriate.
                    186: *
                    187: *  VARIABLES USED:
                    188: *
                    189: *    - hWndDlg:
                    190: *             Global window handle for the upper dialog box.
                    191: *
                    192: *    - hWndFileDlg:
                    193: *             Global window handle for the lower dialog box.
                    194: *
                    195: *  MESSAGES:
                    196: *
                    197: *    WM_DESTROY      - Standard, destroys the window.
                    198: *    WM_SIZE         - Sends messages to the two dialog boxes so that they
                    199: *                      maintain their relative size to the client window.
                    200: *
                    201: *  CALLED BY:
                    202: *
                    203: *    WinMain();
                    204: *
                    205: \*************************************************************************/
                    206: 
                    207: LONG APIENTRY MainWndProc (HWND hwnd,
                    208:                            UINT message,
                    209:                            UINT wParam,
                    210:                            LONG lParam)
                    211: {
                    212:   switch (message)
                    213:       {
                    214: 
                    215:         case WM_SIZE :
1.1.1.3 ! root      216:           SetWindowPos (hWndDlg, NULL, 0,0, LOWORD(lParam), DIALOGHEIGHT, 0);
        !           217:           SetWindowPos (hWndFileDlg, NULL, 0,DIALOGHEIGHT, LOWORD(lParam), HIWORD(lParam), 0);
1.1       root      218:           return (0);
                    219: 
                    220:         case WM_DESTROY :
                    221:             PostQuitMessage (0);
                    222:             return (0);
                    223: 
                    224:        }
                    225:     return DefWindowProc (hwnd, message, wParam, lParam);
                    226: }
                    227: 
                    228: /*************************************************************************\
                    229: *
                    230: *  FUNCTION:  StatusDlgProc (HWND, UINT, UINT, LONG)
                    231: *
                    232: *  PURPOSE:   To process messages for the upper dialog box.
                    233: *
                    234: *  VARIABLES USED:
                    235: *
                    236: *    - StepTime:
                    237: *             A global DWORD holding the value of the sleep time between
                    238: *             API calls.
                    239: *
                    240: *    - bTranslated:
                    241: *             A local BOOL needed for GetDlgItemInt().
                    242: *
                    243: *  MESSAGES:
                    244: *
                    245: *    WM_INITDIALOG:  - Sets a "0" in the time edit field IDE_TIME.  This
                    246: *                      is to indicate to the user that the default time
                    247: *                      set to sleep between reporting the results of
                    248: *                      API calls is set to 0.
                    249: *
                    250: *    WM_REPSTAT:     - A user defined message.  This message uses wParam
                    251: *                      as a pointer to a string holding an API i.e.
                    252: *                      "CreateFile()".  It uses lParam to hold a string
                    253: *                      reporting the value of returned by the API i.e.
                    254: *                      "ERROR_ACCESS_DENIED", or a number if the return
                    255: *                      value isn't identified in RepStat().  The code
                    256: *                      then places these strings in the IDE_API and
                    257: *                      IDE_REPSTAT edit fields.
                    258: *
                    259: *    WM_COMMAND
                    260: *
                    261: *      IDM_STEP:     - Captures the time value in the IDE_TIME edit
                    262: *                      field, and then sets that value into the
                    263: *                      global DWORD StepTime.  This value sets
                    264: *                      a sleep time inbetween reporting the results of
                    265: *                      each API (making it easier for the user to read).
                    266: *
                    267: *  COMMENTS:
                    268: *
                    269: *    This procedure controls the upper dialog box of the application.
                    270: *    The purpose of this box is to report on the API being used by
                    271: *    the lower box, and it's return code.  It also allows you to control
                    272: *    the speed that the application steps through these calls.  This is
                    273: *    basically a error checking/debugging feature, but it also lends an
                    274: *    intuitive look at the API being used.
                    275: *
                    276: \*************************************************************************/
                    277: 
                    278: LONG APIENTRY StatusDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
                    279: {
                    280:   BOOL bTranslated;
                    281: 
                    282:   UNREFERENCED_PARAMETER (wParam);
                    283:   UNREFERENCED_PARAMETER (lParam);
                    284: 
                    285:   switch (message)
                    286:     {
                    287:     case WM_INITDIALOG:
                    288:       StepTime = 0;
                    289:       SetDlgItemInt (hDlg, IDE_TIME, StepTime, FALSE);
                    290:       return (0);
                    291: 
                    292:     case WM_REPSTAT:
                    293:       SetDlgItemText (hDlg, IDE_API,(LPTSTR) wParam);
                    294:       SetDlgItemText (hDlg, IDE_RETSTAT, (LPTSTR)lParam);
                    295:       return (0);
                    296: 
                    297:     case WM_COMMAND:
                    298:       switch (LOWORD(wParam))
                    299:        {
                    300:        case IDB_STEP:
                    301:            StepTime = GetDlgItemInt (hDlg, IDE_TIME, &bTranslated, FALSE);
                    302:        }
                    303:     }
                    304:   return (0);
                    305: }
                    306: 
                    307: /*************************************************************************\
                    308: *
                    309: *  FUNCTION:  FileDlgProc (HWND, UINT, UINT, LONG)
                    310: *
                    311: *  PURPOSE:   To process the messages to the lower dialog box.
                    312: *
                    313: *  VARIABLES USED:
                    314: *
                    315: *    - fileName:
                    316: *             A local CHAR array used to capture the text from the
                    317: *             IDE_FILENAME edit field.
                    318: *
                    319: *    - hFile: Local file handle.
                    320: *
                    321: *    - retCode:
                    322: *             Local DWORD used to trap API return codes.
                    323: *
                    324: *    - ftCreation,
                    325: *    - ftAccessed,
                    326: *    - ftWrittenTo:
                    327: *             Local FILETIME structures.
                    328: *
                    329: *    - wDosDate,
                    330: *    - wDosTime:
                    331: *             Local WORDs, used to hold the values converted from the
                    332: *             FILETIME structures converted by FileTimeToDosDateTime()
                    333: *             and DosDateTimeToFileTime().
                    334: *
                    335: *    - DD[],
                    336: *    - MM[],
                    337: *    - YY[],
                    338: *    - Mn[],
                    339: *    - SS[],
                    340: *    - HH[]:  Local CHAR arrays used to trap the values in various
                    341: *             edit fields representing date and time values.
                    342: *
                    343: *    - dwFileSize:
                    344: *             Local DWORD holding file size.
                    345: *
                    346: *    - lpsFileSize[]:
                    347: *             Local CHAR array used to trap the string from the IDE_SIZE
                    348: *             edit field.
                    349: *
                    350: *    - dwFileAttr:
                    351: *             Local DWORD holding the file attributes.
                    352: *
                    353: *    - hDlg:  Input parameter, handle to the dialog box.
                    354: *
                    355: *  MESSAGES:
                    356: *
                    357: *    WM_COMMAND
                    358: *
                    359: *      IDB_ATTR:
                    360: *             It initializes the variable to hold the file attributes,
                    361: *             dwFileAttr, and then traps the checked states of the
                    362: *             dialog boxes checked buttons.  If a box is found to be
                    363: *             checked, then the appropriate file attribute flag is
                    364: *             OR'd into dwFileAttr.  When all of the attribute values
                    365: *             have been collected, these attributes are set to the file
                    366: *             listed in IDE_FILENAME.
                    367: *
                    368: *      IDB_SET:
                    369: *             This collects the values from the various time and date
                    370: *             edit fields, converts them into system time, and sets
                    371: *             them to the file listed in IDE_FILENAME.  Basically the
                    372: *             technique is to 1) get the values from the edit fields;
                    373: *             2) shift them to their correct location in the WORD; and
                    374: *             3) OR them together into a single WORD.
                    375: *
                    376: *      IDB_OPENFILE:
                    377: *             This gets the date, time, size, and attribute information
                    378: *             from the file listed in IDE_FILENAME.  It converts the
                    379: *             values appropriately and puts them into the various
                    380: *             edit fields and check buttons.  Again, to do time and date
                    381: *             conversions, you must AND the values returned from
                    382: *             GetFileTime() with certain masks to let the appropriate bits
                    383: *             fall through from the WORD (see the mask and shift values
                    384: *             in the setinfo.h file), and shift them to the low order
                    385: *             bit to get the new values.  This is done in the wsprintf()
                    386: *             call's parameter list.
                    387: *
                    388: *  CALLS TO:
                    389: *
                    390: *    RepStat();
                    391: *
                    392: *  COMMENTS:
                    393: *    The basic function of this box is to capture and set file information,
                    394: *    and to send messages to the upper dialog box via RepStat() to report
                    395: *    return code information.  Special characteristics of this function
                    396: *    is how to get and set file information and attributes, and how to
                    397: *    convert Time and Date information.
                    398: *
                    399: \*************************************************************************/
                    400: 
                    401: LONG APIENTRY FileDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
                    402: {
                    403:   CHAR     fileName[100];
                    404:   HANDLE   hFile;
                    405:   DWORD    retCode = 0;
                    406:   FILETIME ftCreation, ftAccessed, ftWrittenTo;
                    407:   WORD     wDosDate, wDosTime;
                    408:   CHAR     DD[3], MM[3], YY[3], HH[3], Mn[3], SS[3];
                    409:   DWORD    dwFileSize;
                    410:   CHAR     lpsFileSize[10];
                    411:   DWORD    dwFileAttr;
                    412: 
                    413:   UNREFERENCED_PARAMETER (wParam);
                    414:   UNREFERENCED_PARAMETER (lParam);
                    415: 
                    416:   switch (message)
                    417:     {
                    418: 
                    419:     case WM_COMMAND :
                    420:       switch (LOWORD(wParam))
                    421:         {
                    422:         case IDB_ATTR:
                    423: 
                    424:           dwFileAttr = 0;
                    425: 
                    426:           if (IsDlgButtonChecked (hDlg, IDC_HIDE))
                    427:              dwFileAttr |= FILE_ATTRIBUTE_HIDDEN;
                    428: 
                    429:           if (IsDlgButtonChecked (hDlg, IDC_NORMAL))
                    430:              dwFileAttr |= FILE_ATTRIBUTE_NORMAL;
                    431: 
                    432:           if (IsDlgButtonChecked (hDlg, IDC_ARC))
                    433:              dwFileAttr |= FILE_ATTRIBUTE_ARCHIVE;
                    434: 
                    435:           if (IsDlgButtonChecked (hDlg, IDC_SYSTEM))
                    436:              dwFileAttr |= FILE_ATTRIBUTE_SYSTEM;
                    437: 
                    438:           if (IsDlgButtonChecked (hDlg, IDC_READ))
                    439:              dwFileAttr |= FILE_ATTRIBUTE_READONLY;
                    440: 
                    441:           GetDlgItemText (hDlg, IDE_FILENAME, fileName, 100);
                    442: 
                    443:           retCode = SetFileAttributes (fileName, dwFileAttr);
                    444:             RepStat ("SetFileAttributes()", retCode);
                    445: 
                    446:           return (0);
                    447: 
                    448:         case IDB_SET:
                    449: 
                    450:           GetDlgItemText (hDlg, IDE_YEAR,  YY, 3);
                    451:           GetDlgItemText (hDlg, IDE_DAY,   DD, 3);
                    452:           GetDlgItemText (hDlg, IDE_MONTH, MM, 3);
                    453:           wDosDate = (WORD)((atoi(YY) - 80)<<YRSHIFT |
                    454:                              atoi(MM)<<MONSHIFT |
                    455:                              atoi(DD)<<DAYSHIFT);
                    456: 
                    457:           GetDlgItemText (hDlg, IDE_HOURS,   HH, 3);
                    458:           GetDlgItemText (hDlg, IDE_SECONDS, SS, 3);
                    459:           GetDlgItemText (hDlg, IDE_MINUTES, Mn, 3);
                    460:           wDosTime = (WORD)((atoi(SS) / 2)<< SECSHIFT |
                    461:                              atoi(Mn)<<MINSHIFT |
                    462:                              atoi(HH)<<HRSHIFT);
                    463: 
                    464:           retCode = DosDateTimeToFileTime (wDosDate, wDosTime, &ftWrittenTo);
                    465:             RepStat("DosDateTimeToFileTime()", retCode);
                    466: 
                    467:           GetDlgItemText (hDlg, IDE_FILENAME, fileName, 100);
                    468:           hFile = CreateFile (fileName,
                    469:                               GENERIC_READ | GENERIC_WRITE,
                    470:                               FILE_SHARE_READ | FILE_SHARE_WRITE,
                    471:                               NULL,
                    472:                               OPEN_EXISTING,
                    473:                               FILE_ATTRIBUTE_NORMAL,
                    474:                               NULL);
                    475:           if (RepStat("CreateFile()", (DWORD)hFile))
                    476:             return (0);
                    477: 
                    478: 
                    479:           retCode = SetFileTime (hFile, NULL, NULL, &ftWrittenTo);
                    480:             RepStat("SetFileTime()", retCode);
                    481: 
                    482:           CloseHandle (hFile);
                    483:           return (0);
                    484: 
                    485: 
                    486:         case IDB_OPENFILE :
                    487:           GetDlgItemText (hDlg, IDE_FILENAME, fileName, 100);
                    488:           hFile = CreateFile (fileName,
                    489:                               GENERIC_READ,
                    490:                               FILE_SHARE_READ | FILE_SHARE_WRITE,
                    491:                               NULL,
                    492:                               OPEN_EXISTING,
                    493:                               FILE_ATTRIBUTE_NORMAL,
                    494:                               NULL);
                    495:           if (RepStat("CreateFile()", (DWORD)hFile))
                    496:             return (0);
                    497: 
                    498:           (BOOL)retCode = GetFileTime (hFile,
                    499:                                        &ftCreation,
                    500:                                        &ftAccessed,
                    501:                                        &ftWrittenTo);
                    502:           RepStat( "GetFileTime()", retCode);
                    503: 
                    504:           (BOOL)retCode = FileTimeToDosDateTime( &ftWrittenTo,
                    505:                                                  &wDosDate,
                    506:                                                  &wDosTime);
                    507:           RepStat("FileTimeToDosDateTime()", retCode);
                    508: 
                    509:           dwFileSize = GetFileSize (hFile, NULL);
                    510:           RepStat("GetFileSize()", dwFileSize);
                    511: 
                    512: 
                    513:           wsprintf(YY, "%02d", ((wDosDate & YRMASK) >> YRSHIFT ) + 80);
                    514:           SetDlgItemText (hDlg, IDE_YEAR, YY);
                    515: 
                    516:           wsprintf(MM, "%02d", ((wDosDate & MONMASK) >> MONSHIFT));
                    517:           SetDlgItemText (hDlg, IDE_MONTH, MM);
                    518: 
                    519:           wsprintf(DD, "%02d", ((wDosDate & DAYMASK) >> DAYSHIFT) );
                    520:           SetDlgItemText (hDlg, IDE_DAY, DD);
                    521: 
                    522:           wsprintf(SS, "%02d", ((wDosTime & SECMASK) >> SECSHIFT ) * 2);
                    523:           SetDlgItemText (hDlg, IDE_SECONDS, SS);
                    524: 
                    525:           wsprintf(Mn, "%02d", ((wDosTime & MINMASK) >> MINSHIFT));
                    526:           SetDlgItemText (hDlg, IDE_MINUTES, Mn);
                    527: 
                    528:           wsprintf(HH, "%02d", (DWORD)(wDosTime & HRMASK) >> HRSHIFT );
                    529:           SetDlgItemText (hDlg, IDE_HOURS, HH);
                    530: 
                    531:           wsprintf(lpsFileSize, "%d", dwFileSize);
                    532:           SetDlgItemText (hDlg, IDE_SIZE, lpsFileSize);
                    533: 
                    534:           dwFileAttr = GetFileAttributes (fileName);
                    535:             RepStat("GetFileAttributes()", dwFileAttr);
                    536: 
                    537:           if (dwFileAttr & FILE_ATTRIBUTE_NORMAL)
                    538:             CheckDlgButton (hDlg, IDC_NORMAL, TRUE);
                    539:           else
                    540:             CheckDlgButton (hDlg, IDC_NORMAL, FALSE);
                    541: 
                    542:           if (dwFileAttr & FILE_ATTRIBUTE_READONLY)
                    543:             CheckDlgButton (hDlg, IDC_READ, TRUE);
                    544:           else
                    545:             CheckDlgButton (hDlg, IDC_READ, FALSE);
                    546: 
                    547:           if (dwFileAttr & FILE_ATTRIBUTE_HIDDEN)
                    548:             CheckDlgButton (hDlg, IDC_HIDE, TRUE);
                    549:           else
                    550:             CheckDlgButton (hDlg, IDC_HIDE, FALSE);
                    551: 
                    552:           if (dwFileAttr & FILE_ATTRIBUTE_SYSTEM)
                    553:             CheckDlgButton (hDlg, IDC_SYSTEM, TRUE);
                    554:           else
                    555:             CheckDlgButton (hDlg, IDC_SYSTEM, FALSE);
                    556: 
                    557:           if (dwFileAttr & FILE_ATTRIBUTE_ARCHIVE)
                    558:             CheckDlgButton (hDlg, IDC_ARC, TRUE);
                    559:           else
                    560:             CheckDlgButton (hDlg, IDC_ARC, FALSE);
                    561: 
                    562:           CloseHandle (hFile);
                    563: 
                    564:           return (0);
                    565:         }
                    566:     }
                    567:   return (0);
                    568: }
                    569: 
                    570: /*************************************************************************\
                    571: *
                    572: *  FUNCTION:  RepStat (CHAR *, DWORD)
                    573: *
                    574: *  PURPOSE:   To report return code information to the upper dialog box.
                    575: *
                    576: *  VARIABLES USED:
                    577: *
                    578: *    - TempBufW[],
                    579: *    - TempBufL[]:
                    580: *             Local CHAR arrays used to set the lParam and wParam of
                    581: *             the WM_REPSTAT message.
                    582: *
                    583: *    - StepTime:
                    584: *             Global DWORD representing the amount of sleep time chosen
                    585: *             by the user.
                    586: *
                    587: *  CALLED BY:
                    588: *
                    589: *    FileDlgProc();
                    590: *
                    591: *  COMMENTS:
                    592: *
                    593: *    This function receives a string representing an API, and a DWORD
                    594: *    representing it's return code value.  It checks the return code to
                    595: *    see if it indicates an error.  If so, GetLastError is called to find
                    596: *    the extended error information; if not, then retCode is set to 0.
                    597: *    The case statement is used to exchange the retCode value for
                    598: *    it's more intuitive string counterpart.  If no counterpart
                    599: *    is listed, the function just sends the number value in string
                    600: *    form.  Note that retCode 0 is just sent as a string number.
                    601: *    Once the function drops from the switch statment, it sends the
                    602: *    user define WM_REPSTAT message to the upper dialog box with the
                    603: *    API and retCode information.  It will then enter a Sleep of a
                    604: *    duration determined by the global StepTime value (set by the
                    605: *    user through and edit field.  The function returns a boolean
                    606: *    value so that the calling procedure can determine if it wants
                    607: *    to continue processing or break.
                    608: *
                    609: \*************************************************************************/
                    610: 
                    611: 
                    612: BOOL RepStat (CHAR *API, DWORD retCode)
                    613: {
                    614:   CHAR TempBufW[40];
                    615:   CHAR TempBufL[40];
                    616: 
                    617:   wsprintf(TempBufW, API);
                    618: 
                    619:   if ((int)retCode <= 0 )
                    620:     retCode = GetLastError();
                    621:   else
                    622:     retCode = 0;
                    623: 
                    624:   if (retCode)
                    625:     MessageBeep(0);
                    626: 
                    627:   switch (retCode)
                    628:     {
                    629:     case ERROR_INVALID_FUNCTION:   // 1L
                    630:       wsprintf(TempBufL, "ERROR_INVALID_FUNCTION");
                    631:       break;
                    632: 
                    633:     case ERROR_FILE_NOT_FOUND:     // 2L
                    634:       wsprintf(TempBufL, "ERROR_FILE_NOT_FOUND");
                    635:       break;
                    636: 
                    637:     case ERROR_ACCESS_DENIED:      // 5L
                    638:       wsprintf(TempBufL, "ERROR_ACCESS_DENIED");
                    639:       break;
                    640: 
                    641:     case ERROR_INVALID_HANDLE:     // 6L
                    642:       wsprintf(TempBufL, "ERROR_INVALID_HANDLE");
                    643:       break;
                    644: 
                    645:     case ERROR_INVALID_PARAMETER:  // 87L
                    646:       wsprintf(TempBufL, "ERROR_INVALID_HANDLE");
                    647:       break;
                    648: 
                    649:     case ERROR_INVALID_NAME:       // 123L
                    650:       wsprintf(TempBufL, "ERROR_INVALID_NAME");
                    651:       break;
                    652: 
                    653:     default:
                    654:       wsprintf(TempBufL, "%d", retCode);
                    655:     }
                    656: 
                    657:   SendMessage (hWndDlg, WM_REPSTAT, (DWORD)TempBufW, (LONG)TempBufL);
                    658:   Sleep( StepTime );
                    659: 
                    660:   return (retCode != 0);
                    661: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.