Annotation of mstools/samples/sdktools/porttool/ptdlgs.c, revision 1.1

1.1     ! 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: 
        !            12: #include "porttool.h"
        !            13: #include "port.h"
        !            14: 
        !            15: #define DLGOFFSET               70
        !            16: RESULT rIssue;
        !            17: 
        !            18: HANDLE   hBkFileHeap;
        !            19: 
        !            20: 
        !            21: /* function prototypes for helper functions */
        !            22: void WINAPI GrowDialog (HWND, BOOL);
        !            23: BOOL WINAPI GetHelpFileName (char *);
        !            24: BOOL WINAPI BuildFileList (char *, LPBKFILELIST *);
        !            25: BOOL WINAPI AddFile (char *, char *, BKFILELIST *);
        !            26: BOOL WINAPI RemoveFile (char *, LPBKFILELIST *);
        !            27: BOOL WINAPI FreeFileList (BKFILELIST *);
        !            28: 
        !            29: /* port options dialog */
        !            30: BOOL WINAPI OptionsDlgProc (
        !            31:     HWND    hDlg,
        !            32:     UINT    uMsg,
        !            33:     UINT    uParam,
        !            34:     LONG    lParam)
        !            35: {
        !            36:        BOOL       bRet = TRUE;
        !            37: static DWORD      *dwPTFlags;
        !            38: static HFONT      hStrikeoutFont;
        !            39: static HFONT      hSystemFont;
        !            40:        LOGFONT    lf;
        !            41: 
        !            42:     switch (uMsg)
        !            43:        {
        !            44:        case WM_INITDIALOG:
        !            45:            /* create strikeout font for ignored tokens */
        !            46:            hSystemFont = GetStockObject (SYSTEM_FONT);
        !            47:            GetObject (hSystemFont, sizeof (LOGFONT), &lf);
        !            48:            lf.lfStrikeOut = TRUE;
        !            49:            hStrikeoutFont = CreateFontIndirect (&lf);
        !            50: 
        !            51:            /* initialize token control with stock system font */
        !            52:            SendMessage (GetDlgItem (hDlg, IDC_CURTOKEN),
        !            53:                         WM_SETFONT,
        !            54:                         (UINT)hSystemFont,
        !            55:                         FALSE);
        !            56: 
        !            57:            /* save dwPTFlags from lParam */
        !            58:            dwPTFlags = (DWORD *)lParam;
        !            59: 
        !            60:            /* initialize current token if any */
        !            61:            if (*(WORD *)rIssue.lpszToken != MAXTOKENLEN)
        !            62:                SetDlgItemText (hDlg, IDC_CURTOKEN, rIssue.lpszToken);
        !            63:            else
        !            64:                EnableWindow (GetDlgItem (hDlg, IDC_IGNORETOKEN), FALSE);
        !            65: 
        !            66:            /* initialize search flag check boxes */
        !            67:            CheckDlgButton (hDlg, IDC_NOAPIS, (*dwPTFlags & PT_NOAPIS));
        !            68:            CheckDlgButton (hDlg, IDC_NOMESSAGES, (*dwPTFlags & PT_NOMESSAGES));
        !            69:            CheckDlgButton (hDlg, IDC_NOSTRUCTURES, (*dwPTFlags & PT_NOSTRUCTURES));
        !            70:            CheckDlgButton (hDlg, IDC_NOMACROS, (*dwPTFlags & PT_NOMACROS));
        !            71:            CheckDlgButton (hDlg, IDC_NOCONSTANTS, (*dwPTFlags & PT_NOCONSTANTS));
        !            72:            CheckDlgButton (hDlg, IDC_NOTYPES, (*dwPTFlags & PT_NOTYPES));
        !            73:            CheckDlgButton (hDlg, IDC_NOCUSTOM, (*dwPTFlags & PT_NOCUSTOM));
        !            74:            CheckDlgButton (hDlg, IDC_IGNORECASE, (*dwPTFlags & PT_IGNORECASE));
        !            75: 
        !            76:            /* set focus to first check box, return FALSE */
        !            77:            SetFocus (GetDlgItem (hDlg, IDC_NOAPIS));
        !            78:            bRet = FALSE;
        !            79:            break;
        !            80: 
        !            81:        case WM_COMMAND:
        !            82:            switch (LOWORD (uParam))
        !            83:                {
        !            84:                case IDOK:
        !            85:                    /* get check box states and return as FLAGS in UM_PORT message */
        !            86:                    *dwPTFlags = (*dwPTFlags & ~PT_IGNORECASE) ^
        !            87:                        (IsDlgButtonChecked (hDlg, IDC_IGNORECASE) ? PT_IGNORECASE : 0);
        !            88:                    *dwPTFlags = (*dwPTFlags & ~PT_NOAPIS) ^
        !            89:                        (IsDlgButtonChecked (hDlg, IDC_NOAPIS) ? PT_NOAPIS : 0);
        !            90:                    *dwPTFlags = (*dwPTFlags & ~PT_NOMESSAGES) ^
        !            91:                        (IsDlgButtonChecked (hDlg, IDC_NOMESSAGES) ? PT_NOMESSAGES : 0);
        !            92:                    *dwPTFlags = (*dwPTFlags & ~PT_NOSTRUCTURES) ^
        !            93:                        (IsDlgButtonChecked (hDlg, IDC_NOSTRUCTURES) ? PT_NOSTRUCTURES : 0);
        !            94:                    *dwPTFlags = (*dwPTFlags & ~PT_NOMACROS) ^
        !            95:                        (IsDlgButtonChecked (hDlg, IDC_NOMACROS) ? PT_NOMACROS : 0);
        !            96:                    *dwPTFlags = (*dwPTFlags & ~PT_NOCONSTANTS) ^
        !            97:                        (IsDlgButtonChecked (hDlg, IDC_NOCONSTANTS) ? PT_NOCONSTANTS : 0);
        !            98:                    *dwPTFlags = (*dwPTFlags & ~PT_NOTYPES) ^
        !            99:                        (IsDlgButtonChecked (hDlg, IDC_NOTYPES) ? PT_NOTYPES : 0);
        !           100:                    *dwPTFlags = (*dwPTFlags & ~PT_NOCUSTOM) ^
        !           101:                        (IsDlgButtonChecked (hDlg, IDC_NOCUSTOM) ? PT_NOCUSTOM : 0);
        !           102: 
        !           103:           case IDCANCEL:
        !           104:                    SendMessage (GetDlgItem (hDlg, IDC_CURTOKEN), WM_SETFONT, 0, FALSE);
        !           105:                    DeleteObject (hStrikeoutFont);
        !           106:                    EndDialog (hDlg, LOWORD (uParam) == IDOK);
        !           107:                    break;
        !           108: 
        !           109:                case IDC_IGNORETOKEN:
        !           110:                    /* toggle ignore bit */
        !           111:                    *dwPTFlags ^= PT_IGNORETOKEN;
        !           112: 
        !           113:                    /* have control draw in strikeout if ignored */
        !           114:                    if (*dwPTFlags & PT_IGNORETOKEN)
        !           115:                        SendMessage (GetDlgItem (hDlg, IDC_CURTOKEN),
        !           116:                                     WM_SETFONT,
        !           117:                                     (UINT)hStrikeoutFont,
        !           118:                                     TRUE);
        !           119:                    /* else draw in system font */
        !           120:                    else
        !           121:                        SendMessage (GetDlgItem (hDlg, IDC_CURTOKEN),
        !           122:                                     WM_SETFONT,
        !           123:                                     (UINT)hSystemFont,
        !           124:                                     TRUE);
        !           125:                    break;
        !           126:                }
        !           127:            break;
        !           128: 
        !           129:        default:
        !           130:            bRet = FALSE;
        !           131:            break;
        !           132:        }
        !           133: 
        !           134:     /* return (message was processed); */
        !           135:     return bRet;
        !           136: }
        !           137: 
        !           138: 
        !           139: 
        !           140: /* port options dialog */
        !           141: BOOL WINAPI PortDlgProc (
        !           142:     HWND    hDlg,
        !           143:     UINT    uMsg,
        !           144:     UINT    uParam,
        !           145:     LONG    lParam)
        !           146: {
        !           147:        BOOL    bRet = TRUE;
        !           148: static DWORD   dwPTFlags;
        !           149: static BOOL    bSearching = TRUE;
        !           150: static BOOL    bHelpActive = FALSE, bIsHelpFile = FALSE;
        !           151: static HBRUSH  hBkBrush;
        !           152: static HWND    hWndEdit;
        !           153: static HANDLE  hEditData;
        !           154: static int     nIssues = 0;
        !           155: static int     iLineNo, iStartPos;
        !           156: static HLOCAL  hToken, hHelp, hIssue, hSuggest;
        !           157: static HLOCAL  hEditLine;
        !           158: 
        !           159: 
        !           160:     switch (uMsg)
        !           161:        {
        !           162:         case WM_INITDIALOG:
        !           163:            {
        !           164:            char    lpszTitle[MAX_PATH];
        !           165:            char    lpszFilename[MAX_PATH];
        !           166:            RECT    rc;
        !           167: 
        !           168: 
        !           169:            /* reposition self on bottom of screen */
        !           170:            GetWindowRect (hDlg, &rc);
        !           171:            SetWindowPos (hDlg,
        !           172:                          NULL,
        !           173:                          rc.left,
        !           174:                          GetSystemMetrics (SM_CYSCREEN) -
        !           175:                           (rc.bottom - rc.top + DLGOFFSET),
        !           176:                          rc.right-rc.left,
        !           177:                          rc.bottom-rc.top,
        !           178:                          SWP_NOZORDER | SWP_NOREDRAW | SWP_NOSIZE);
        !           179: 
        !           180:            /* set help available flag */
        !           181:            if (GetHelpFileName (lpszTitle))
        !           182:                {
        !           183:                EnableWindow (GetDlgItem (hDlg, IDC_HELP), TRUE);
        !           184:                bIsHelpFile = TRUE;
        !           185:                }
        !           186: 
        !           187:            /* allocate strings for Issue struct from local heap to reduce stack overhead */
        !           188:            if (!(rIssue.lpszToken = LocalLock (hToken = LocalAlloc (LHND, MAXTOKENLEN))) ||
        !           189:                !(rIssue.lpszHelpStr = LocalLock (hHelp = LocalAlloc (LHND, MAXHELPLEN))) ||
        !           190:                !(rIssue.lpszIssue = LocalLock (hIssue = LocalAlloc (LHND, MAXISSUELEN))) ||
        !           191:                !(rIssue.lpszSuggest = LocalLock (hSuggest = LocalAlloc (LHND, MAXSUGGESTLEN))))
        !           192:                {
        !           193:                ErrorNotify (hDlg, IDS_MEMORYFAILED);
        !           194:                PostMessage (hDlg, WM_COMMAND, IDC_DONE, 0);
        !           195:                break;
        !           196:                }
        !           197: 
        !           198:            /* initialize line and token offset position stuff */
        !           199:            iLineNo = 0;
        !           200:            iStartPos = 0;
        !           201:            rIssue.nPosToken = 0;
        !           202: 
        !           203:            /* initialize background brush for use in WM_CTLCOLOR message */
        !           204:            hBkBrush = (HBRUSH)GetClassLong (hDlg, GCL_HBRBACKGROUND);
        !           205: 
        !           206:            /* set initial search flags to default */
        !           207:            dwPTFlags = 0;
        !           208: 
        !           209:            /* initialize filename in caption */
        !           210:            LoadString (GetModuleHandle (NULL), IDS_PORTFILE, lpszTitle, strlen (lpszTitle));
        !           211:            GetFileFromPath (lpszFilePath, lpszFilename);
        !           212:            strcat (lpszTitle, lpszFilename);
        !           213:            SetWindowText (hDlg, lpszTitle);
        !           214: 
        !           215:            /* IDC_SUGGESTION to SW_HIDE */
        !           216:            ShowWindow (GetDlgItem (hDlg, IDC_SUGGESTION), SW_HIDE);
        !           217:            ShowWindow (GetDlgItem (hDlg, IDC_SUGGESTLABEL), SW_HIDE);
        !           218: 
        !           219:            /* get edit window and data handle */
        !           220:            hWndEdit = (HWND)GetWindowLong (GetParent (hDlg), WL_HWNDEDIT);
        !           221:            hEditData = (HANDLE)SendMessage (hWndEdit, EM_GETHANDLE, 0, 0);
        !           222: 
        !           223:            /* allocate here, reallocate later when needed */
        !           224:            hEditLine = LocalAlloc (LHND, 1);
        !           225: 
        !           226:            /* post message to start ball rolling */
        !           227:            PostMessage (hDlg, WM_COMMAND, (UINT)IDC_CONTINUE, 0);
        !           228: 
        !           229:            /* don't worry about focus here since were going to drive the search anyway */
        !           230:            bRet = TRUE;
        !           231:            }
        !           232:            break;
        !           233: 
        !           234:        case WM_CLOSE:
        !           235:                {
        !           236:                char    lpszFile[MAX_PATH];
        !           237: 
        !           238:                if (bHelpActive &&
        !           239:                GetHelpFileName (lpszFile))
        !           240:                WinHelp (hDlg, lpszFile, HELP_QUIT, 0);
        !           241: 
        !           242:                /* clean up and go away */
        !           243:                LocalUnlock (hToken); LocalFree (hToken);
        !           244:                LocalUnlock (hHelp); LocalFree (hHelp);
        !           245:                LocalUnlock (hIssue); LocalFree (hIssue);
        !           246:                LocalUnlock (hSuggest); LocalFree (hSuggest);
        !           247:                LocalFree (hEditLine);
        !           248:                DestroyWindow (hDlg);
        !           249:                }
        !           250:        break;
        !           251: 
        !           252:        case WM_COMMAND:
        !           253:            switch (LOWORD (uParam))
        !           254:                {
        !           255:                case IDC_CONTINUE:
        !           256:                    {
        !           257:                    int     iLastLine, nCharOffset, nLineLen;
        !           258:                    MSG     msg;
        !           259:                    char    lpszBuff[MAXTOKENLEN];
        !           260:                    char    *lpszLine;
        !           261:                    char    *lpLine;
        !           262:                    char    *lpEditData;
        !           263: 
        !           264:                    /* disable continue button */
        !           265:                    EnableWindow (GetDlgItem (hDlg, IDC_CONTINUE), FALSE);
        !           266:                    EnableWindow (GetDlgItem (hDlg, IDC_OPTIONS), FALSE);
        !           267:                    EnableWindow (GetDlgItem (hDlg, IDCANCEL), TRUE);
        !           268: 
        !           269:                    /* set IDC_SEARCHFOUND to green searching */
        !           270:                    LoadString (GetModuleHandle (NULL), IDS_SEARCHING,
        !           271:                                lpszBuff,
        !           272:                                sizeof (lpszBuff));
        !           273:                    SetWindowText (GetDlgItem (hDlg, IDC_SEARCHFOUND), lpszBuff);
        !           274:                    bSearching = TRUE;
        !           275: 
        !           276:                    /* set last line */
        !           277:                    iLastLine = (int)SendMessage (hWndEdit, EM_GETLINECOUNT, 0, 0);
        !           278: 
        !           279:                    /* find next port issue */
        !           280:                    while (TRUE)
        !           281:                        {
        !           282:                        if (iLineNo >= iLastLine)
        !           283:                            {
        !           284:                            /* no more issues found, so clean up and go away */
        !           285:                            ErrorNotify (hDlg, IDS_NOMOREPORTISSUES);
        !           286: 
        !           287:                            /* nullify any selection in line edit control */
        !           288:                            SendMessage (GetDlgItem (hDlg, IDC_LINE), EM_SETSEL, 0, 0);
        !           289:                            break;
        !           290:                            }
        !           291: 
        !           292:                        /* increment line no */
        !           293:                        SetWindowText (GetDlgItem (hDlg, IDC_LINENO),
        !           294:                                       itoa (iLineNo, lpszBuff, 10));
        !           295: 
        !           296:                        /* get length and number of edit line */
        !           297:                        nCharOffset = SendMessage (hWndEdit, EM_LINEINDEX, iLineNo, 0);
        !           298:                        if ((nLineLen = SendMessage (hWndEdit, EM_LINELENGTH, nCharOffset, 0)) <= 2)
        !           299:                            goto NEXT_LINE;
        !           300: 
        !           301:                        /* allocate enough memory for edit line */
        !           302:                        if (!(hEditLine = LocalReAlloc (hEditLine,
        !           303:                                                        nLineLen+1,
        !           304:                                                        LHND)))
        !           305:                            {
        !           306:                            /* no more issues found, so clean up and go away */
        !           307:                            ErrorNotify (hDlg, IDS_MEMORYFAILED);
        !           308:                            PostMessage (hDlg, WM_COMMAND, IDC_DONE, 0);
        !           309:                            break;
        !           310:                            }
        !           311: 
        !           312:                        /* get line from edit control, and null terminate */
        !           313:                        lpEditData = LocalLock (hEditData);
        !           314:                        lpLine = lpszLine = LocalLock (hEditLine);
        !           315:                        strncpy (lpszLine, lpEditData+nCharOffset, nLineLen);
        !           316:                        lpszLine[nLineLen] = 0;
        !           317: 
        !           318:                        /* increment the token position for multiple errors in a line */
        !           319:                        lpLine += iStartPos;
        !           320:                        LocalUnlock (hEditData);
        !           321: 
        !           322:                        /* initialize line and hilight token */
        !           323:                        SetWindowText (GetDlgItem (hDlg, IDC_LINE), lpszLine);
        !           324: 
        !           325:                        /* reinitialize rIssue strings lengths */
        !           326:                        *(WORD *)rIssue.lpszToken = MAXTOKENLEN;
        !           327:                        *(WORD *)rIssue.lpszHelpStr = MAXHELPLEN;
        !           328:                        *(WORD *)rIssue.lpszIssue = MAXISSUELEN;
        !           329:                        *(WORD *)rIssue.lpszSuggest = MAXSUGGESTLEN;
        !           330: 
        !           331:                        /* search next line */
        !           332:                        if (CheckString (lpLine, dwPTFlags, &rIssue))
        !           333:                            {
        !           334:                            /* set SEARCHFOUND string to found */
        !           335:                            LoadString (GetModuleHandle (NULL),
        !           336:                                        IDS_FOUND,
        !           337:                                        lpszBuff,
        !           338:                                        sizeof (lpszBuff));
        !           339:                            strcat (lpszBuff, rIssue.lpszToken);
        !           340:                            SetWindowText (GetDlgItem (hDlg, IDC_SEARCHFOUND), lpszBuff);
        !           341: 
        !           342:                            /* reenable options button */
        !           343:                            EnableWindow (GetDlgItem (hDlg, IDC_OPTIONS), TRUE);
        !           344: 
        !           345:                            /* set searching flag off */
        !           346:                            bSearching = FALSE;
        !           347: 
        !           348:                            /* increment issue cnt */
        !           349:                            SetWindowText (GetDlgItem (hDlg, IDC_ISSUECNT),
        !           350:                                           itoa (++nIssues, lpszBuff, 10));
        !           351: 
        !           352:                            /* initialize Issue */
        !           353:                            SetWindowText (GetDlgItem (hDlg, IDC_ISSUE), rIssue.lpszIssue);
        !           354: 
        !           355:                            /* if help, enble button */
        !           356:                            EnableWindow (GetDlgItem (hDlg, IDC_HELP),
        !           357:                                          ((*(rIssue.lpszSuggest) != 0) && bIsHelpFile));
        !           358: 
        !           359:                            /* if suggest, show suggestion */
        !           360:                            if (*(rIssue.lpszSuggest))
        !           361:                                {
        !           362:                                SetWindowText (GetDlgItem (hDlg, IDC_SUGGESTION),
        !           363:                                               rIssue.lpszSuggest);
        !           364:                                if (!IsWindowVisible (GetDlgItem (hDlg, IDC_SUGGESTION)))
        !           365:                                    GrowDialog (hDlg, TRUE);
        !           366:                                }
        !           367: 
        !           368:                            else if (IsWindowVisible (GetDlgItem (hDlg, IDC_SUGGESTION)))
        !           369:                                GrowDialog (hDlg, FALSE);
        !           370: 
        !           371:                            /* scroll parent edit control and select offending text */
        !           372:                            SendMessage (hWndEdit, EM_LINESCROLL, 0, iLineNo -
        !           373:                            SendMessage (hWndEdit, EM_GETFIRSTVISIBLELINE, 0, 0));
        !           374:                            SendMessage (hWndEdit,
        !           375:                                         EM_SETSEL,
        !           376:                                         iStartPos + nCharOffset + rIssue.nPosToken,
        !           377:                                         iStartPos + nCharOffset + rIssue.nPosToken +
        !           378:                                             strlen (rIssue.lpszToken));
        !           379: 
        !           380:                            /* select text in line edit control */
        !           381:                            SendMessage (GetDlgItem (hDlg, IDC_LINE),
        !           382:                                         EM_SETSEL,
        !           383:                                         iStartPos + rIssue.nPosToken,
        !           384:                                         iStartPos + rIssue.nPosToken +
        !           385:                                             strlen (rIssue.lpszToken));
        !           386: 
        !           387:                            /* reset nPosToken to check rest of line */
        !           388:                            iStartPos += (rIssue.nPosToken + strlen (rIssue.lpszToken));
        !           389:                            LocalUnlock (hEditLine);
        !           390:                            break;
        !           391:                            }
        !           392: 
        !           393:                        /* call peek message to let user cancel if they choose */
        !           394:                        if (PeekMessage (&msg,
        !           395:                                         GetDlgItem (hDlg, IDCANCEL),
        !           396:                                         WM_LBUTTONDOWN,
        !           397:                                         WM_LBUTTONDOWN,
        !           398:                                         PM_REMOVE))
        !           399:                            {
        !           400:                            /* reset appropriate buttons */
        !           401:                            EnableWindow (GetDlgItem (hDlg, IDCANCEL), FALSE);
        !           402:                            EnableWindow (GetDlgItem (hDlg, IDC_HELP), FALSE);
        !           403:                            EnableWindow (GetDlgItem (hDlg, IDC_OPTIONS), TRUE);
        !           404: 
        !           405:                            /* break to let message get delivered */
        !           406:                            break;
        !           407:                            }
        !           408: 
        !           409:                        /* also let the user exit from searching */
        !           410:                        if (PeekMessage (&msg,
        !           411:                                         GetDlgItem (hDlg, IDC_DONE),
        !           412:                                         WM_LBUTTONDOWN,
        !           413:                                         WM_LBUTTONDOWN,
        !           414:                                         PM_REMOVE))
        !           415:                            {
        !           416:                            PostMessage (hDlg, WM_COMMAND, IDC_DONE, 0);
        !           417:                            break;
        !           418:                            }
        !           419: 
        !           420:                        /* unlock local edit line */
        !           421:                        LocalUnlock (hEditLine);
        !           422: 
        !           423:                        /* reset token position */
        !           424:                        rIssue.nPosToken = 0;
        !           425:                        iStartPos = 0;
        !           426: NEXT_LINE:
        !           427:                        /* increment line and continue */
        !           428:                        iLineNo++;
        !           429:                        }
        !           430: 
        !           431:                    /* enable continue button unless at end of file */
        !           432:                    if (iLineNo < iLastLine)
        !           433:                        {
        !           434:                        EnableWindow (GetDlgItem (hDlg, IDC_CONTINUE), TRUE);
        !           435:                        SetFocus (GetDlgItem (hDlg, IDC_CONTINUE));
        !           436:                        }
        !           437:                    else
        !           438:                        {
        !           439:                        EnableWindow (GetDlgItem (hDlg, IDC_CONTINUE), FALSE);
        !           440:                        EnableWindow (GetDlgItem (hDlg, IDCANCEL), FALSE);
        !           441:                        SetFocus (GetDlgItem (hDlg, IDC_DONE));
        !           442:                        }
        !           443:                    }
        !           444:                    break;
        !           445: 
        !           446:                case WM_CLOSE:
        !           447:                case IDC_DONE:
        !           448:                    {
        !           449:                    char    lpszFile[MAX_PATH];
        !           450: 
        !           451:                    if (bHelpActive &&
        !           452:                        GetHelpFileName (lpszFile))
        !           453:                        WinHelp (hDlg, lpszFile, HELP_QUIT, 0);
        !           454: 
        !           455:                    /* clean up and go away */
        !           456:                    LocalUnlock (hToken); LocalFree (hToken);
        !           457:                    LocalUnlock (hHelp); LocalFree (hHelp);
        !           458:                    LocalUnlock (hIssue); LocalFree (hIssue);
        !           459:                    LocalUnlock (hSuggest); LocalFree (hSuggest);
        !           460:                    LocalFree (hEditLine);
        !           461:                    DestroyWindow (hDlg);
        !           462:                    }
        !           463:                    break;
        !           464: 
        !           465:                case IDC_OPTIONS:
        !           466:                    {
        !           467:                    DWORD    dwOptions = dwPTFlags;
        !           468: 
        !           469:                    /* call dialog to start port process */
        !           470:                    if (DialogBoxParam (GetModuleHandle (NULL),
        !           471:                                        IDD_OPTIONSDLG,
        !           472:                                        hDlg,
        !           473:                                        OptionsDlgProc,
        !           474:                                        (LPARAM)&dwOptions))
        !           475:                        {
        !           476:                        dwPTFlags = dwOptions;
        !           477: 
        !           478:                        /* if PT_IGNORETOKEN, call CheckString */
        !           479:                        if (dwOptions & PT_IGNORETOKEN)
        !           480:                            {
        !           481:                            CheckString (rIssue.lpszToken, dwPTFlags, NULL);
        !           482:                            dwPTFlags ^= PT_IGNORETOKEN;
        !           483:                            }
        !           484:                        }
        !           485: 
        !           486:                    }
        !           487:                    break;
        !           488: 
        !           489:                case IDC_HELP:
        !           490:                    {
        !           491:                    char    lpszFile[MAX_PATH];
        !           492: 
        !           493:                    if (bIsHelpFile && GetHelpFileName (lpszFile))
        !           494:                        {
        !           495:                        WinHelp (hDlg, lpszFile, HELP_KEY, (DWORD)rIssue.lpszHelpStr);
        !           496:                        bHelpActive = TRUE;
        !           497:                        }
        !           498:                    }
        !           499:                    break;
        !           500: 
        !           501:                case IDC_RESTART:
        !           502:                    iLineNo = 0;
        !           503:                    rIssue.nPosToken = 0;
        !           504:                    iStartPos = 0;
        !           505:                    PostMessage (hDlg, WM_COMMAND, IDC_CONTINUE, 0);
        !           506:                    break;
        !           507:                }
        !           508:            break;
        !           509: 
        !           510:        default:
        !           511:            bRet = FALSE;
        !           512:            break;
        !           513:        }
        !           514: 
        !           515:     /* return (message was processed); */
        !           516:     return bRet;
        !           517: }
        !           518: 
        !           519: 
        !           520: 
        !           521: 
        !           522: /* background porting status dialog */
        !           523: BOOL WINAPI BkPortDlgProc (
        !           524:     HWND    hDlg,
        !           525:     UINT    uMsg,
        !           526:     UINT    uParam,
        !           527:     LONG    lParam)
        !           528: {
        !           529:          BOOL          bRet = TRUE;
        !           530:          char          szFileName[MAX_PATH];
        !           531:          char          szFilePath[MAX_PATH];
        !           532: static   BKFILELIST    *lpbkFiles;
        !           533: static   int           iCurThread;
        !           534: static   BOOL          bStarted = FALSE;
        !           535:          BKFILELIST    *lpNode;
        !           536: 
        !           537:     switch (uMsg)
        !           538:        {
        !           539:        case WM_INITDIALOG:
        !           540:            {
        !           541:            HWND          hIssues = GetDlgItem (hDlg, IDC_ISSUES);
        !           542:            HWND          hLines = GetDlgItem (hDlg, IDC_LINES);
        !           543:            HWND          hComplete = GetDlgItem (hDlg, IDC_COMPLETE);
        !           544: 
        !           545:            /* set background icon to porttool background icon and start minimized */
        !           546:            SetClassLong (hDlg,
        !           547:                          GCL_HICON,
        !           548:                          (LONG)LoadIcon (GetModuleHandle (NULL), IDBkPort));
        !           549: 
        !           550:            lpbkFiles = NULL;
        !           551:            iCurThread = -1;
        !           552: 
        !           553:            /* build list of files to port from lParam */
        !           554:            if (lParam)
        !           555:                {
        !           556:                if (!BuildFileList ((char *)lParam, &lpbkFiles))
        !           557:                    {
        !           558:                    lpbkFiles = NULL;
        !           559:                    break;
        !           560:                    }
        !           561:                }
        !           562: 
        !           563:            else
        !           564:                {
        !           565:                /* get file from user first */
        !           566:                *szFileName = 0;
        !           567:                *szFilePath = 0;
        !           568: 
        !           569:                GetFileName (hDlg, szFileName, szFilePath);
        !           570:                if (!BuildFileList (szFilePath, &lpbkFiles))
        !           571:                    {
        !           572:                    lpbkFiles = NULL;
        !           573:                    break;
        !           574:                    }
        !           575:                }
        !           576: 
        !           577:            lpNode = lpbkFiles;
        !           578:            /* initialize each file in list */
        !           579:            while (lpNode)
        !           580:                {
        !           581:                /* add filename to listbox */
        !           582:                SendMessage (GetDlgItem (hDlg, IDC_FILELIST),
        !           583:                             LB_ADDSTRING,
        !           584:                             0,
        !           585:                             (LPARAM)lpNode->bkFile.szFile);
        !           586: 
        !           587:                /* initialize some stuff */
        !           588:                lpNode->bkFile.hDlg = hDlg;
        !           589:                lpNode->bkFile.dwPTFlags = PT_DEFAULT;
        !           590: 
        !           591:                /* start background thread on each file */
        !           592:                StartBkPortThread (&lpNode->bkFile);
        !           593: 
        !           594:                /* traverse list */
        !           595:                lpNode = lpNode->Next;
        !           596:                }
        !           597: 
        !           598:            /* select first thread in listbox */
        !           599:            SendMessage (GetDlgItem (hDlg, IDC_FILELIST), LB_SETCURSEL, 0, 0);
        !           600:            SetDlgItemText (hDlg, IDC_FILEPATH, lpbkFiles->bkFile.szFilePath);
        !           601: 
        !           602:            /* if started with /b switch */
        !           603:            if (!GetParent (hDlg))
        !           604:                ShowWindow (hDlg, SW_SHOWMINIMIZED);
        !           605:            else
        !           606:                SetEvent (lpbkFiles->hEvents[BKPORT_STATUS]);
        !           607: 
        !           608:            iCurThread = 0;
        !           609:            bStarted = TRUE;
        !           610:            }
        !           611:            break;
        !           612: 
        !           613:        case WM_SHOWWINDOW:
        !           614:            if (bStarted)
        !           615:                {
        !           616:                int    i = 0;
        !           617: 
        !           618:                lpNode = lpbkFiles;
        !           619:                while (i < iCurThread)
        !           620:                    lpNode = lpNode->Next;
        !           621: 
        !           622:                if (!uParam)
        !           623:                    ResetEvent (lpNode->hEvents[BKPORT_STATUS]);
        !           624:                else
        !           625:                    SetEvent (lpNode->hEvents[BKPORT_STATUS]);
        !           626:                }
        !           627:            break;
        !           628: 
        !           629:        case WM_SIZE:
        !           630:            if (bStarted)
        !           631:                {
        !           632:                int    i = 0;
        !           633: 
        !           634:                lpNode = lpbkFiles;
        !           635:                while (i < iCurThread)
        !           636:                    lpNode = lpNode->Next;
        !           637: 
        !           638:                if (uParam == SIZEICONIC)
        !           639:                    ResetEvent (lpNode->hEvents[BKPORT_STATUS]);
        !           640:                else
        !           641:                    SetEvent (lpNode->hEvents[BKPORT_STATUS]);
        !           642:                }
        !           643:            break;
        !           644: 
        !           645:        case UM_STATUSUPDATE:
        !           646:            {
        !           647:            char    Buff[10];
        !           648: 
        !           649:            /* update status info controls */
        !           650:            SetDlgItemText (hDlg, IDC_ISSUES, itoa (LOWORD (uParam), Buff, 10));
        !           651:            SetDlgItemText (hDlg, IDC_COMPLETE, itoa (HIWORD (uParam), Buff, 10));
        !           652:            SetDlgItemText (hDlg, IDC_LINES, itoa (lParam, Buff, 10));
        !           653:            }
        !           654:            break;
        !           655: 
        !           656:        case UM_THREADCOMPLETE:
        !           657:            {
        !           658:            int    iThread = 0;
        !           659: 
        !           660:            /* find handle in list */
        !           661:            lpNode = lpbkFiles;
        !           662:            while (lpNode)
        !           663:                {
        !           664:                if ((HANDLE)uParam == lpNode->bkFile.hThread)
        !           665:                    break;
        !           666:                lpNode = lpNode->Next;
        !           667:                iThread++;
        !           668:                }
        !           669: 
        !           670:            if (lpNode)
        !           671:                {
        !           672:                /* remove file list item */
        !           673:                RemoveFile (lpNode->bkFile.szFilePath, &lpbkFiles);
        !           674: 
        !           675:                /* remove item from list box */
        !           676:                SendMessage (GetDlgItem (hDlg, IDC_FILELIST),
        !           677:                             LB_DELETESTRING,
        !           678:                             iThread,
        !           679:                             0);
        !           680: 
        !           681:                /* if current thread ended and more threads exist */
        !           682:                if (iThread == iCurThread &&
        !           683:                    lpbkFiles             &&
        !           684:                    SendMessage (GetDlgItem (hDlg, IDC_FILELIST), LB_GETCOUNT, 0, 0))
        !           685:                    {
        !           686:                    SendMessage (GetDlgItem (hDlg, IDC_FILELIST), LB_SETCURSEL, 0, 0);
        !           687:                    SetEvent (lpbkFiles->hEvents[BKPORT_STATUS]);
        !           688:                    iCurThread = 0;
        !           689:                    }
        !           690: 
        !           691:                else if (iThread == iCurThread)
        !           692:                    {
        !           693:                    iCurThread = -1;
        !           694:                    PostMessage (hDlg, WM_COMMAND, IDC_BKDONE, 0);
        !           695:                    }
        !           696: 
        !           697:                /* clean up controls */
        !           698:                SetDlgItemText (hDlg, IDC_FILEPATH, "");
        !           699:                PostMessage (hDlg, UM_STATUSUPDATE, 0, 0);
        !           700:                }
        !           701: 
        !           702:            else
        !           703:                {
        !           704:                MessageBox (hDlg,
        !           705:                            "Error, invalid thread handle process terminating.",
        !           706:                            "Error",
        !           707:                            MB_ICONSTOP | MB_OK);
        !           708:                ExitProcess (FALSE);
        !           709:                }
        !           710: 
        !           711:            }
        !           712:            break;
        !           713: 
        !           714:        case WM_COMMAND:
        !           715:            switch (LOWORD (uParam))
        !           716:                {
        !           717:                case IDC_FILELIST:
        !           718:                    /* if new file selected change update signal to active thread */
        !           719:                    if (HIWORD (uParam) == LBN_SELCHANGE)
        !           720:                        {
        !           721:                        int    i = 0;
        !           722:                        int    iNewThread = SendMessage (GetDlgItem (hDlg, IDC_FILELIST),
        !           723:                                                         LB_GETCURSEL,
        !           724:                                                         0,
        !           725:                                                         0);
        !           726: 
        !           727:                        /* reset current thread */
        !           728:                        lpNode = lpbkFiles;
        !           729:                        while (lpNode)
        !           730:                            {
        !           731:                            if (i == iCurThread)
        !           732:                                ResetEvent (lpNode->hEvents[BKPORT_STATUS]);
        !           733: 
        !           734:                            if (i == iNewThread)
        !           735:                                {
        !           736:                                SetEvent (lpNode->hEvents[BKPORT_STATUS]);
        !           737:                                SetDlgItemText (hDlg,
        !           738:                                                IDC_FILEPATH,
        !           739:                                                lpNode->bkFile.szFilePath);
        !           740:                                }
        !           741: 
        !           742:                            lpNode = lpNode->Next;
        !           743:                            i++;
        !           744:                            }
        !           745: 
        !           746:                        iCurThread = iNewThread;
        !           747:                        }
        !           748:                    break;
        !           749: 
        !           750:                case IDC_ABORTFILE:
        !           751:                    {
        !           752:                    int        i = 0;
        !           753:                    HCURSOR    hOldCursor;
        !           754: 
        !           755:                    /* reset current thread */
        !           756:                    lpNode = lpbkFiles;
        !           757:                    while (lpNode)
        !           758:                        {
        !           759:                        if (i == iCurThread)
        !           760:                            {
        !           761:                            /* put hourglass cursor up */
        !           762:                            hOldCursor = (HCURSOR)SetClassLong (hDlg, GCL_HCURSOR, 0);
        !           763:                            SetCursor (LoadCursor (NULL, IDC_WAIT));
        !           764: 
        !           765:                            /* abort porting file where it is */
        !           766:                            SetEvent (lpNode->hEvents[BKPORT_ABORT]);
        !           767: 
        !           768:                            /* remove file from list when thread is dead */
        !           769:                            WaitForSingleObject (lpNode->bkFile.hThread, INFINITE);
        !           770:                            RemoveFile (lpNode->bkFile.szFilePath, &lpbkFiles);
        !           771: 
        !           772:                            /* replace original cursor */
        !           773:                            SetClassLong (hDlg, GCL_HCURSOR, (LONG)hOldCursor);
        !           774:                            SetCursor (hOldCursor);
        !           775: 
        !           776:                            /* update listbox */
        !           777:                            SendMessage (GetDlgItem (hDlg, IDC_FILELIST),
        !           778:                                         LB_DELETESTRING,
        !           779:                                         iCurThread,
        !           780:                                         0);
        !           781: 
        !           782:                            /* select new event if any in listbox */
        !           783:                            if (SendMessage (GetDlgItem (hDlg, IDC_FILELIST),
        !           784:                                             LB_GETCOUNT,
        !           785:                                             0,
        !           786:                                             0))
        !           787:                                {
        !           788:                                SendMessage (GetDlgItem (hDlg, IDC_FILELIST),
        !           789:                                             LB_SETCURSEL,
        !           790:                                             0,
        !           791:                                             0);
        !           792:                                SetEvent (lpbkFiles->hEvents[BKPORT_STATUS]);
        !           793:                                iCurThread = 0;
        !           794:                                }
        !           795: 
        !           796:                            else
        !           797:                                {
        !           798:                                iCurThread = -1;
        !           799:                                PostMessage (hDlg, WM_COMMAND, IDC_DONE, 0);
        !           800:                                }
        !           801: 
        !           802:                            /* clean up controls */
        !           803:                            SetDlgItemText (hDlg, IDC_FILEPATH, "");
        !           804:                            PostMessage (hDlg, UM_STATUSUPDATE, 0, 0);
        !           805:                            break;
        !           806:                            }
        !           807: 
        !           808:                        lpNode = lpNode->Next;
        !           809:                        i++;
        !           810:                        }
        !           811:                    }
        !           812:                    break;
        !           813: 
        !           814:                case IDC_ADDFILE:
        !           815:                    {
        !           816:                    /* get file from user first */
        !           817:                    *szFileName = 0;
        !           818:                    *szFilePath = 0;
        !           819: 
        !           820:                    /* add a file to the list */
        !           821:                    if (GetFileName (hDlg, szFileName, szFilePath))
        !           822:                        {
        !           823:                        /* if new list */
        !           824:                        if (!lpbkFiles)
        !           825:                            BuildFileList (szFilePath, &lpbkFiles);
        !           826: 
        !           827:                        else if (!AddFile (szFilePath, szFileName, lpbkFiles))
        !           828:                            break;
        !           829: 
        !           830:                        /* find node in list */
        !           831:                        lpNode = lpbkFiles;
        !           832:                        while (lpNode)
        !           833:                            {
        !           834:                            if (!strcmp (lpNode->bkFile.szFilePath, szFilePath))
        !           835:                                break;
        !           836:                            lpNode = lpNode->Next;
        !           837:                            }
        !           838: 
        !           839:                        if (lpNode)
        !           840:                            {
        !           841:                            /* add filename to listbox */
        !           842:                            SendMessage (GetDlgItem (hDlg, IDC_FILELIST),
        !           843:                                         LB_ADDSTRING,
        !           844:                                         0,
        !           845:                                         (LPARAM)lpNode->bkFile.szFile);
        !           846: 
        !           847:                            /* initialize some stuff */
        !           848:                            lpNode->bkFile.hDlg = hDlg;
        !           849:                            lpNode->bkFile.dwPTFlags = PT_DEFAULT;
        !           850: 
        !           851:                            /* start background thread on this file */
        !           852:                            StartBkPortThread (&lpNode->bkFile);
        !           853: 
        !           854:                            /* if first thread */
        !           855:                            if (iCurThread == -1 ||
        !           856:                                SendMessage (GetDlgItem (hDlg, IDC_FILELIST),
        !           857:                                             LB_GETCOUNT, 0, 0) == 1)
        !           858:                                {
        !           859:                                iCurThread = 0;
        !           860:                                SendMessage (GetDlgItem (hDlg, IDC_FILELIST),
        !           861:                                             LB_SETCURSEL,
        !           862:                                             0,
        !           863:                                             0);
        !           864:                                SendMessage (hDlg,
        !           865:                                             WM_COMMAND,
        !           866:                                             MAKELONG (IDC_FILELIST, LBN_SELCHANGE),
        !           867:                                             0);
        !           868:                                }
        !           869:                            }
        !           870:                        }
        !           871:                    }
        !           872:                    break;
        !           873: 
        !           874:                case IDC_CHANGEOPTIONS:
        !           875:                    {
        !           876:                    DWORD    dwFlags = 0;
        !           877: 
        !           878:                    if ( lpbkFiles == NULL )
        !           879:                        break;
        !           880: 
        !           881:                    dwFlags = (dwFlags & ~PT_IGNORECASE) ^
        !           882:                        (IsDlgButtonChecked (hDlg, IDC_BKIGNORECASE) ? PT_IGNORECASE : 0);
        !           883:                    dwFlags = (dwFlags & ~PT_NOAPIS) ^
        !           884:                        (IsDlgButtonChecked (hDlg, IDC_BKNOAPIS) ? PT_NOAPIS : 0);
        !           885:                    dwFlags = (dwFlags & ~PT_NOMESSAGES) ^
        !           886:                        (IsDlgButtonChecked (hDlg, IDC_BKNOMESSAGES) ? PT_NOMESSAGES : 0);
        !           887:                    dwFlags = (dwFlags & ~PT_NOSTRUCTURES) ^
        !           888:                        (IsDlgButtonChecked (hDlg, IDC_BKNOSTRUCTURES) ? PT_NOSTRUCTURES : 0);
        !           889:                    dwFlags = (dwFlags & ~PT_NOMACROS) ^
        !           890:                        (IsDlgButtonChecked (hDlg, IDC_BKNOMACROS) ? PT_NOMACROS : 0);
        !           891:                    dwFlags = (dwFlags & ~PT_NOCONSTANTS) ^
        !           892:                        (IsDlgButtonChecked (hDlg, IDC_BKNOCONSTANTS) ? PT_NOCONSTANTS : 0);
        !           893:                    dwFlags = (dwFlags & ~PT_NOTYPES) ^
        !           894:                        (IsDlgButtonChecked (hDlg, IDC_BKNOTYPES) ? PT_NOTYPES : 0);
        !           895:                    dwFlags = (dwFlags & ~PT_NOCUSTOM) ^
        !           896:                        (IsDlgButtonChecked (hDlg, IDC_BKNOCUSTOM) ? PT_NOCUSTOM : 0);
        !           897: 
        !           898:                    /* change the options for the file being ported */
        !           899:                    lpbkFiles->bkFile.dwPTFlags = dwFlags;
        !           900:                    }
        !           901:                    break;
        !           902: 
        !           903:                case IDCANCEL:
        !           904:                    {
        !           905:                    HCURSOR    hOldCursor;
        !           906:                    HANDLE     hThreads[MAXBKTHREADS];
        !           907:                    int        i = 0;
        !           908: 
        !           909:                    /* put up confirm message */
        !           910:                    if (MessageBox (hDlg,
        !           911:                                    "Cancel background process?",
        !           912:                                    "PortTool - Abort",
        !           913:                                    MB_ICONQUESTION | MB_OKCANCEL) == IDOK)
        !           914:                        {
        !           915:                        /* put hourglass cursor up */
        !           916:                        hOldCursor = (HCURSOR)SetClassLong (hDlg, GCL_HCURSOR, 0);
        !           917:                        SetCursor (LoadCursor (NULL, IDC_WAIT));
        !           918: 
        !           919:                        /* if any files in list */
        !           920:                        if (lpbkFiles)
        !           921:                            {
        !           922:                            /* abort all background threads and build thread handle array */
        !           923:                            lpNode = lpbkFiles;
        !           924:                            while (lpNode)
        !           925:                                {
        !           926:                                SetEvent (lpNode->hEvents[BKPORT_ABORT]);
        !           927:                                hThreads[i++] = lpNode->bkFile.hThread;
        !           928:                                lpNode = lpNode->Next;
        !           929:                                }
        !           930: 
        !           931:                            /* wait on completion of background threads */
        !           932:                            WaitForMultipleObjects (i, hThreads, TRUE, INFINITE);
        !           933: 
        !           934:                            /* free background port resources */
        !           935:                            FreeFileList (lpbkFiles);
        !           936:                            }
        !           937: 
        !           938:                        SetClassLong (hDlg, GCL_HCURSOR, (LONG)hOldCursor);
        !           939:                        SetCursor (hOldCursor);
        !           940:                        DestroyWindow (hDlg);
        !           941:                        }
        !           942:                    }
        !           943:                    break;
        !           944: 
        !           945:                case IDC_BKDONE:
        !           946:                    /* if file list post message to cancel */
        !           947:                    if (lpbkFiles)
        !           948:                        PostMessage (hDlg, WM_COMMAND, IDCANCEL, 0);
        !           949:                    else
        !           950:                        DestroyWindow (hDlg);
        !           951:                    break;
        !           952: 
        !           953:                default:
        !           954:                    bRet = FALSE;
        !           955:                    break;
        !           956:                }
        !           957:            break;
        !           958: 
        !           959:        case WM_DESTROY:
        !           960:            /* if no parent, post quit message */
        !           961:            if (GetParent (hDlg) == NULL)
        !           962:                PostQuitMessage (1);
        !           963:            break;
        !           964: 
        !           965:        default:
        !           966:            bRet = FALSE;
        !           967:            break;
        !           968:        }
        !           969: 
        !           970:     return bRet;
        !           971: }
        !           972: 
        !           973: 
        !           974: 
        !           975: /* funtion retrieves the help filename from the ini file */
        !           976: BOOL WINAPI GetHelpFileName (
        !           977:     char    *lpszFile)
        !           978: {
        !           979:     char       szAppName[30];
        !           980:     char       szWinHelp[30];
        !           981:     char       szDefault[] = "Default";
        !           982:     char       szIniFile[MAX_PATH];
        !           983:     OFSTRUCT   of;
        !           984: 
        !           985:     /* get ini file and path */
        !           986:     GetIniFile (szIniFile);
        !           987: 
        !           988:     /* get help filename from ini file */
        !           989:     LoadString (GetModuleHandle (NULL), IDS_APPNAME, szAppName, 30);
        !           990:     LoadString (GetModuleHandle (NULL), IDS_WINHELP, szWinHelp, 30);
        !           991:     GetPrivateProfileString (szAppName,
        !           992:                             szWinHelp,
        !           993:                             szDefault,
        !           994:                             lpszFile,
        !           995:                             MAX_PATH,
        !           996:                             szIniFile);
        !           997: 
        !           998:     /* test to see if help file exists */
        !           999:     return (OpenFile (lpszFile, &of, OF_EXIST) != -1);
        !          1000: }
        !          1001: 
        !          1002: 
        !          1003: 
        !          1004: 
        !          1005: /* rearrange dialog and controls */
        !          1006: void WINAPI GrowDialog (
        !          1007:     HWND    hDlg,
        !          1008:     BOOL    bBigger)
        !          1009: {
        !          1010:     RECT    rc;
        !          1011:     int     nChange = (bBigger ? DLGOFFSET : -DLGOFFSET);
        !          1012: 
        !          1013:     /* grow main dialog */
        !          1014:     GetWindowRect (hDlg, &rc);
        !          1015:     SetWindowPos (hDlg,
        !          1016:                  NULL,
        !          1017:                  rc.left,
        !          1018:                  rc.top,
        !          1019:                  rc.right-rc.left,
        !          1020:                  rc.bottom-rc.top + nChange,
        !          1021:                  SWP_NOMOVE | SWP_NOZORDER);
        !          1022: 
        !          1023:     /* move stop button down */
        !          1024:     GetWindowRect (GetDlgItem (hDlg, IDCANCEL), &rc);
        !          1025:     ScreenToClient (hDlg, (LPPOINT)&rc);
        !          1026:     ScreenToClient (hDlg, (LPPOINT)&rc.right);
        !          1027:     SetWindowPos (GetDlgItem (hDlg, IDCANCEL),
        !          1028:                  NULL,
        !          1029:                  rc.left,
        !          1030:                  rc.top + nChange,
        !          1031:                  rc.right-rc.left,
        !          1032:                  rc.bottom-rc.top,
        !          1033:                  SWP_NOSIZE | SWP_NOZORDER);
        !          1034: 
        !          1035:     /* move CONTINUE button down */
        !          1036:     GetWindowRect (GetDlgItem (hDlg, IDC_CONTINUE), &rc);
        !          1037:     ScreenToClient (hDlg, (LPPOINT)&rc);
        !          1038:     ScreenToClient (hDlg, (LPPOINT)&rc.right);
        !          1039:     SetWindowPos (GetDlgItem (hDlg, IDC_CONTINUE),
        !          1040:                  NULL,
        !          1041:                  rc.left,
        !          1042:                  rc.top + nChange,
        !          1043:                  rc.right-rc.left,
        !          1044:                  rc.bottom-rc.top,
        !          1045:                  SWP_NOSIZE | SWP_NOZORDER);
        !          1046: 
        !          1047:     /* move restart button down */
        !          1048:     GetWindowRect (GetDlgItem (hDlg, IDC_RESTART), &rc);
        !          1049:     ScreenToClient (hDlg, (LPPOINT)&rc);
        !          1050:     ScreenToClient (hDlg, (LPPOINT)&rc.right);
        !          1051:     SetWindowPos (GetDlgItem (hDlg, IDC_RESTART),
        !          1052:                  NULL,
        !          1053:                  rc.left,
        !          1054:                  rc.top + nChange,
        !          1055:                  rc.right-rc.left,
        !          1056:                  rc.bottom-rc.top,
        !          1057:                  SWP_NOSIZE | SWP_NOZORDER);
        !          1058: 
        !          1059:     /* move options button down */
        !          1060:     GetWindowRect (GetDlgItem (hDlg, IDC_OPTIONS), &rc);
        !          1061:     ScreenToClient (hDlg, (LPPOINT)&rc);
        !          1062:     ScreenToClient (hDlg, (LPPOINT)&rc.right);
        !          1063:     SetWindowPos (GetDlgItem (hDlg, IDC_OPTIONS),
        !          1064:                  NULL,
        !          1065:                  rc.left,
        !          1066:                  rc.top + nChange,
        !          1067:                  rc.right-rc.left,
        !          1068:                  rc.bottom-rc.top,
        !          1069:                  SWP_NOSIZE | SWP_NOZORDER);
        !          1070: 
        !          1071:     /* move help button down */
        !          1072:     GetWindowRect (GetDlgItem (hDlg, IDC_HELP), &rc);
        !          1073:     ScreenToClient (hDlg, (LPPOINT)&rc);
        !          1074:     ScreenToClient (hDlg, (LPPOINT)&rc.right);
        !          1075:     SetWindowPos (GetDlgItem (hDlg, IDC_HELP),
        !          1076:                  NULL,
        !          1077:                  rc.left,
        !          1078:                  rc.top + nChange,
        !          1079:                  rc.right-rc.left,
        !          1080:                  rc.bottom-rc.top,
        !          1081:                  SWP_NOSIZE | SWP_NOZORDER);
        !          1082: 
        !          1083:     /* move done button down */
        !          1084:     GetWindowRect (GetDlgItem (hDlg, IDC_DONE), &rc);
        !          1085:     ScreenToClient (hDlg, (LPPOINT)&rc);
        !          1086:     ScreenToClient (hDlg, (LPPOINT)&rc.right);
        !          1087:     SetWindowPos (GetDlgItem (hDlg, IDC_DONE),
        !          1088:                  NULL,
        !          1089:                  rc.left,
        !          1090:                  rc.top + nChange,
        !          1091:                  rc.right-rc.left,
        !          1092:                  rc.bottom-rc.top,
        !          1093:                  SWP_NOSIZE | SWP_NOZORDER);
        !          1094: 
        !          1095:     /* show suggestion edit control and label when appropriate */
        !          1096:     ShowWindow (GetDlgItem (hDlg, IDC_SUGGESTION), (bBigger ? SW_SHOW : SW_HIDE));
        !          1097:     ShowWindow (GetDlgItem (hDlg, IDC_SUGGESTLABEL), (bBigger ? SW_SHOW : SW_HIDE));
        !          1098: }
        !          1099: 
        !          1100: 
        !          1101: 
        !          1102: 
        !          1103: BOOL WINAPI BuildFileList (
        !          1104:     char         *lpFileList,
        !          1105:     LPBKFILELIST  *lpList)
        !          1106: {
        !          1107:     char       *lpFile;
        !          1108:     char       szFilePath[MAX_PATH];
        !          1109:     char       szFile[MAX_PATH];
        !          1110:     HFILE      hFile;
        !          1111:     OFSTRUCT   of;
        !          1112:     BOOL       bList = FALSE;
        !          1113: 
        !          1114:     /* create heap for up to 50 files at a time */
        !          1115:     if (!(hBkFileHeap = HeapCreate (HEAP_NO_SERIALIZE,
        !          1116:                                    sizeof (BKFILELIST),
        !          1117:                                    MAXBKTHREADS * sizeof (BKFILELIST))))
        !          1118:        return FALSE;
        !          1119: 
        !          1120:     /* allocate first node in list */
        !          1121:     *lpList = (BKFILELIST *)HeapAlloc (hBkFileHeap, 0, sizeof (BKFILELIST));
        !          1122:     (*lpList)->hEvents[BKPORT_ABORT] = NULL;
        !          1123: 
        !          1124:     /* parse first file in list */
        !          1125:     lpFile = strtok (lpFileList, " ");
        !          1126: 
        !          1127:     /* loop through all files in list */
        !          1128:     while (lpFile)
        !          1129:        {
        !          1130:        strcpy (szFilePath, lpFile);
        !          1131: 
        !          1132:        /* if no path, add current directory as path */
        !          1133:        if (!GetFileFromPath (szFilePath, szFile))
        !          1134:            {
        !          1135:            strcpy (szFile, szFilePath);
        !          1136:            GetCurrentDirectory (MAX_PATH, szFilePath);
        !          1137:            strcat (szFilePath, "\\");
        !          1138:            strcat (szFilePath, szFile);
        !          1139:            }
        !          1140: 
        !          1141:        /* verify file is available */
        !          1142:        hFile = OpenFile (szFilePath, &of, OF_READWRITE);
        !          1143:        if (hFile != -1)
        !          1144:            {
        !          1145:            /* added at least one file */
        !          1146:            bList = TRUE;
        !          1147: 
        !          1148:            /* close file */
        !          1149:            CloseHandle ((HANDLE)hFile);
        !          1150: 
        !          1151:            /* add file to list */
        !          1152:            AddFile (szFilePath, szFile, *lpList);
        !          1153:            }
        !          1154: 
        !          1155:        /* get next file in list */
        !          1156:        lpFile = strtok (NULL, " ");
        !          1157:        }
        !          1158: 
        !          1159:     /* if no valid files, cleanup */
        !          1160:     if (!bList)
        !          1161:        {
        !          1162:        HeapDestroy (hBkFileHeap);
        !          1163:        return FALSE;
        !          1164:        }
        !          1165: 
        !          1166:     return TRUE;
        !          1167: }
        !          1168: 
        !          1169: 
        !          1170: 
        !          1171: 
        !          1172: BOOL WINAPI AddFile (
        !          1173:     char       *lpFilePath,
        !          1174:     char       *lpFile,
        !          1175:     BKFILELIST *lpbkFiles)
        !          1176: {
        !          1177:     BKFILELIST   *lpNode;
        !          1178: 
        !          1179: 
        !          1180:     /* if first item in list don't need to allocate */
        !          1181:     if (!lpbkFiles->hEvents[BKPORT_ABORT])
        !          1182:        lpNode = lpbkFiles;
        !          1183:     else
        !          1184:        {
        !          1185:        lpNode = (BKFILELIST *)HeapAlloc (hBkFileHeap, 0, sizeof (BKFILELIST));
        !          1186:        if (!lpNode)
        !          1187:            return FALSE;
        !          1188: 
        !          1189:        /* find end of list then add new node */
        !          1190:        while (lpbkFiles->Next)
        !          1191:            lpbkFiles = lpbkFiles->Next;
        !          1192:        lpbkFiles->Next = lpNode;
        !          1193:        }
        !          1194: 
        !          1195:     /* initialize node structure */
        !          1196:     strcpy (lpNode->bkFile.szFile, lpFile);
        !          1197:     strcpy (lpNode->bkFile.szFilePath, lpFilePath);
        !          1198:     CreateEvents (lpNode->hEvents, &lpNode->bkFile);
        !          1199:     lpNode->Next = NULL;
        !          1200: 
        !          1201:     return TRUE;
        !          1202: }
        !          1203: 
        !          1204: 
        !          1205: 
        !          1206: 
        !          1207: BOOL WINAPI RemoveFile (
        !          1208:     char         *lpFilePath,
        !          1209:     LPBKFILELIST  *lpbkFiles)
        !          1210: {
        !          1211:     BKFILELIST   *pHead = *lpbkFiles;
        !          1212:     BKFILELIST   *pTail = *lpbkFiles;
        !          1213: 
        !          1214:     /* loop thru list until file name matches */
        !          1215:     while (pHead)
        !          1216:        {
        !          1217:        if (!strcmp (lpFilePath, pHead->bkFile.szFilePath))
        !          1218:            {
        !          1219:            /* special case remove first node */
        !          1220:            if (pTail == pHead)
        !          1221:                {
        !          1222:                *lpbkFiles = pHead->Next;
        !          1223:                DestroyEvents (pHead->hEvents);
        !          1224:                HeapFree (hBkFileHeap, 0, (char *)(pHead));
        !          1225: 
        !          1226:                /* if no more nodes, destroy heap */
        !          1227:                if (!*lpbkFiles)
        !          1228:                    HeapDestroy (hBkFileHeap);
        !          1229:                }
        !          1230: 
        !          1231:            else
        !          1232:                {
        !          1233:                pTail->Next = pHead->Next;
        !          1234:                DestroyEvents (pHead->hEvents);
        !          1235:                HeapFree (hBkFileHeap, 0, (char *)pHead);
        !          1236:                }
        !          1237: 
        !          1238:            return TRUE;
        !          1239:            }
        !          1240: 
        !          1241:        pTail = pHead;
        !          1242:        pHead = pHead->Next;
        !          1243:        }
        !          1244: 
        !          1245:     return FALSE;
        !          1246: }
        !          1247: 
        !          1248: 
        !          1249: 
        !          1250: 
        !          1251: BOOL WINAPI FreeFileList (
        !          1252:     BKFILELIST *lpbkFiles)
        !          1253: {
        !          1254:     /* loop thru each list item */
        !          1255:     while (lpbkFiles)
        !          1256:        {
        !          1257:        /* destroy event handles */
        !          1258:        DestroyEvents (lpbkFiles->hEvents);
        !          1259: 
        !          1260:        lpbkFiles = lpbkFiles->Next;
        !          1261:        }
        !          1262: 
        !          1263:     /* release entire heap */
        !          1264:     HeapDestroy (hBkFileHeap);
        !          1265: 
        !          1266:     return TRUE;
        !          1267: }

unix.superglobalmegacorp.com

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