Annotation of mstools/samples/sdktools/perfmon/init.c, revision 1.1

1.1     ! root        1: //==========================================================================//
        !             2: //                                  Includes                                //
        !             3: //==========================================================================//
        !             4: #include <string.h>     // strupr
        !             5: #include <stdio.h>      // for sprintf.
        !             6: #include <locale.h>     // TESTING TESTING
        !             7: 
        !             8: 
        !             9: #include "perfmon.h"
        !            10: #include "init.h"       // external declarations for this file
        !            11: 
        !            12: #include "alert.h"      // for AlertIitializeApplication
        !            13: #include "command.h"    // for ViewChart
        !            14: #include "grafdata.h"   // for QuerySaveChart
        !            15: #include "graph.h"      // for GraphInitializeApplication
        !            16: #include "legend.h"     // for LegendInitializeApplication
        !            17: #include "log.h"        // for LogInitializeApplication
        !            18: #include "intrline.h"   // for ILineInitializeApplication
        !            19: #include "perfdata.h"   // for PerfDataInitializeInstance
        !            20: #include "perfmops.h"   // for OpenFileHandler, for now
        !            21: #include "status.h"     // for StatusInitializeApplication
        !            22: #include "timeline.h"   // for TLineInitializeApplication
        !            23: #include "playback.h"   // for PlaybackInitializeInstance
        !            24: #include "registry.h"   // for Load/SaveMainWindowPlacement
        !            25: #include "report.h"     // for ReportInitializeApplication
        !            26: #include "toolbar.h"    // for ToolbarInitializeApplication
        !            27: #include "utils.h"
        !            28: #include "fileopen.h"   // for FileOpen
        !            29: #include "pmemory.h"    // for MemoryFree
        !            30: 
        !            31: extern   TCHAR          DefaultLangId[] ;
        !            32: extern   TCHAR          EnglishLangId[] ;
        !            33: 
        !            34: //==========================================================================//
        !            35: //                                  Constants                               //
        !            36: //==========================================================================//
        !            37: 
        !            38: 
        !            39: #define szPerfmonMainClass TEXT("PerfmonMainClass")
        !            40: 
        !            41: HHOOK   lpMsgFilterProc ;
        !            42: DWORD FAR PASCAL MessageFilterProc (int nCode, WPARAM wParam,
        !            43:       LPARAM lParam) ;
        !            44: 
        !            45: 
        !            46: //==========================================================================//
        !            47: //                              Local Functions                             //
        !            48: //==========================================================================//
        !            49: 
        !            50: 
        !            51: void GetScalesFonts (void)
        !            52:    {
        !            53:    LOGFONT        lf ;
        !            54: 
        !            55:    memset (&lf, 0, sizeof (lf)) ;
        !            56: 
        !            57:    lstrcpy (lf.lfFaceName, szScalesFontFace) ;
        !            58:    lf.lfHeight = iScalesFontHeight ;
        !            59:    lf.lfWeight = FW_REGULAR ;
        !            60: 
        !            61:    hFontScales = CreateFontIndirect (&lf) ;
        !            62: 
        !            63:    lf.lfWeight = FW_BOLD ;
        !            64:    hFontScalesBold = CreateFontIndirect (&lf) ;
        !            65:    }
        !            66: 
        !            67: 
        !            68: BOOL InitializeSystemValues (void)
        !            69: /*
        !            70:    Effect:        Read and store in variables the various system values,
        !            71:                   such as the width and height of the screen and icons,
        !            72:                   the width of scroll bars, etc.
        !            73: 
        !            74:    Called By:     PerfmonInitialize only.
        !            75: 
        !            76:    Returns:       Whether this function was successful in getting all
        !            77:                   needed system values.
        !            78: */
        !            79:    {  // InitializeSystemValues
        !            80:    xScreenWidth =  GetSystemMetrics (SM_CXSCREEN) ;
        !            81:    yScreenHeight = GetSystemMetrics (SM_CYSCREEN) ;
        !            82: 
        !            83:    xBorderWidth = GetSystemMetrics (SM_CXBORDER) ;
        !            84:    yBorderHeight = GetSystemMetrics (SM_CYBORDER) ;
        !            85: 
        !            86:    xScrollWidth = GetSystemMetrics (SM_CXVSCROLL) ;
        !            87:    yScrollHeight = GetSystemMetrics (SM_CYHSCROLL) ;
        !            88: 
        !            89:    xScrollThumbWidth = GetSystemMetrics (SM_CXHTHUMB) ;
        !            90:    yScrollThumbHeight = GetSystemMetrics (SM_CYVTHUMB) ;
        !            91: 
        !            92:    xDlgBorderWidth = GetSystemMetrics (SM_CXDLGFRAME) ;
        !            93:    yDlgBorderHeight = GetSystemMetrics (SM_CYDLGFRAME) ;
        !            94: 
        !            95:    MinimumSize = yScrollHeight +
        !            96:                  GetSystemMetrics (SM_CYMENU) +
        !            97:                  GetSystemMetrics (SM_CYCAPTION) ;
        !            98: 
        !            99:    //================================================================//
        !           100:    // create all the brushes and pens for performance improvement    //
        !           101:    //================================================================//
        !           102:    CreatePerfmonSystemObjects () ;
        !           103:    hWhitePen = CreatePen (PS_SOLID, 3, crWhite) ;
        !           104: 
        !           105: 
        !           106: // TESTING TESTING TESTING
        !           107: #if 0
        !           108:    {
        !           109:    DWORD GDIBatchLimit = GdiSetBatchLimit (1) ;
        !           110:    }
        !           111: //mike1(TEXT("SetLocale returns %s"), setlocale(LC_NUMERIC, NULL));
        !           112: mike1(TEXT("SetLocale returns %s"), setlocale(LC_NUMERIC, NULL));
        !           113: #endif
        !           114: 
        !           115: 
        !           116:    return (TRUE) ;
        !           117:    }  // InitializeSystemValues
        !           118: 
        !           119: 
        !           120: BOOL InitializeApplication (void)
        !           121: /*
        !           122:    Effect:        Perform all initializations required for the FIRST
        !           123:                   instance of the Perfmon application. In particular,
        !           124:                   register all of Perfmon's window classes.
        !           125: 
        !           126:    Note:          There is no background brush set for the MainWindow
        !           127:                   class so that the main window is never erased. The
        !           128:                   client area of MainWindow is always covered by one
        !           129:                   of the view windows. If we erase it, it would just
        !           130:                   flicker needlessly.
        !           131: 
        !           132:    Called By:     PerfmonInitialize only.
        !           133: 
        !           134:    Returns:       Whether this function was successful in initializing.
        !           135: */
        !           136:    {  // InitializeApplication
        !           137:    BOOL           bSuccess ;
        !           138:    WNDCLASS       wc ;
        !           139:    TCHAR          LocalHelpFileName [ShortTextLen] ;
        !           140:    LPTSTR         pFileName ;
        !           141: 
        !           142:    hIcon = LoadIcon (hInstance, idIcon) ;
        !           143: 
        !           144:    //=============================//
        !           145:    // Register Main window class  //
        !           146:    //=============================//
        !           147: 
        !           148:    wc.style         = CS_DBLCLKS | CS_BYTEALIGNCLIENT;
        !           149:    wc.lpfnWndProc   = (WNDPROC) MainWndProc;
        !           150:    wc.hInstance     = hInstance;
        !           151:    wc.cbClsExtra    = 0 ;
        !           152:    wc.cbWndExtra    = 0;
        !           153:    wc.hIcon         = hIcon ;
        !           154:    wc.hCursor       = LoadCursor(NULL, IDI_APPLICATION);
        !           155:    wc.hbrBackground = NULL ;                             // see note above
        !           156:    wc.lpszMenuName  = idMenuChart ;
        !           157:    wc.lpszClassName = szPerfmonMainClass ;
        !           158: 
        !           159:    bSuccess = RegisterClass (&wc) ;
        !           160: 
        !           161:    //=============================//
        !           162:    // Register Abstract "Systems" //
        !           163:    //=============================//
        !           164:    hbLightGray = GetStockObject (LTGRAY_BRUSH) ;
        !           165: 
        !           166:    if (bSuccess)
        !           167:       bSuccess = StatusInitializeApplication () ;
        !           168: 
        !           169:    if (bSuccess)
        !           170:       bSuccess = GraphInitializeApplication () ;
        !           171: 
        !           172: #ifdef ADVANCED_PERFMON
        !           173:    if (bSuccess)
        !           174:       bSuccess = LogInitializeApplication () ;
        !           175: 
        !           176:    if (bSuccess)
        !           177:       bSuccess = AlertInitializeApplication () ;
        !           178: 
        !           179:    if (bSuccess)
        !           180:       bSuccess = ReportInitializeApplication () ;
        !           181: 
        !           182:    if (bSuccess)
        !           183:       bSuccess = ILineInitializeApplication () ;
        !           184: 
        !           185:    if (bSuccess)
        !           186:       bSuccess = TLineInitializeApplication () ;
        !           187: #endif
        !           188: 
        !           189:    // setup messagehook to handle F1 as help
        !           190:    lpMsgFilterProc = SetWindowsHookEx (WH_MSGFILTER,
        !           191:           (HOOKPROC) MessageFilterProc,
        !           192:           hInstance,
        !           193:           GetCurrentThreadId()) ;
        !           194: 
        !           195:    // get the help file full path name
        !           196:    LoadString (hInstance, IDS_HELPFILE_NAME,
        !           197:       (LPTSTR)LocalHelpFileName, ShortTextLen-1);
        !           198: 
        !           199: 
        !           200:    if (LocalHelpFileName[0])
        !           201:       {
        !           202:       pszHelpFile = (LPTSTR) MemoryAllocate (FilePathLen * sizeof (TCHAR)) ;
        !           203:       SearchPath (NULL, LocalHelpFileName, NULL,
        !           204:             FilePathLen - 1, pszHelpFile, &pFileName) ;
        !           205:       }
        !           206:    else
        !           207:       {
        !           208:       // no help file
        !           209:       pszHelpFile = (LPTSTR) MemoryAllocate (sizeof (TCHAR)) ;
        !           210:       *pszHelpFile = TEXT('\0') ;
        !           211:       }
        !           212: 
        !           213:    return (bSuccess) ;
        !           214:    }  // InitializeApplication
        !           215: 
        !           216: 
        !           217: 
        !           218: BOOL InitializeInstance (int nCmdShow, LPCSTR lpszCmdLine)
        !           219: /*
        !           220:    Effect:        Perform all initializations required for EACH instance
        !           221:                   of the Perfmon application. In particular, create all
        !           222:                   of Perfmon's initial windows, and perform any other
        !           223:                   initializations except registering classes (done in
        !           224:                   InitializeApplication).
        !           225: 
        !           226:    Called By:     PerfmonInitialize only.
        !           227: 
        !           228:    Note:          This function has multiple return points.
        !           229: 
        !           230:    Returns:       Whether this function was successful in initalizing.
        !           231: */
        !           232:    {  // InitializeInstance
        !           233:    DWORD          ComputerNameLength;
        !           234:    TCHAR          szApplication [WindowCaptionLen] ;
        !           235: 
        !           236: 
        !           237:    //=============================//
        !           238:    // Set Priority high           //
        !           239:    //=============================//
        !           240: 
        !           241:    SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS) ;
        !           242:    SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST) ;
        !           243: 
        !           244:    //=============================//
        !           245:    // Load Resources              //
        !           246:    //=============================//
        !           247: 
        !           248:    GetScalesFonts () ;
        !           249: 
        !           250:    hMenuChart = LoadMenu (hInstance, idMenuChart) ;
        !           251: 
        !           252: #ifdef ADVANCED_PERFMON
        !           253:    hMenuAlert = LoadMenu (hInstance, idMenuAlert) ;
        !           254:    hMenuLog = LoadMenu (hInstance, idMenuLog) ;
        !           255:    hMenuReport = LoadMenu (hInstance, idMenuReport) ;
        !           256: #endif
        !           257: 
        !           258:    hAccelerators = LoadAccelerators (hInstance, idAccelerators) ;
        !           259: 
        !           260: 
        !           261:    //=============================//
        !           262:    // Initialize Systems          //
        !           263:    //=============================//
        !           264: 
        !           265:    iLanguage = GetUserDefaultLangID() ;
        !           266:    iEnglishLanguage = MAKELANGID (LANG_ENGLISH, LANG_NEUTRAL) ;
        !           267: //   iEnglishLanguage = MAKELANGID (iLanguage & 0x0ff, LANG_NEUTRAL) ;
        !           268:    TSPRINTF (DefaultLangId, TEXT("%03x"), iLanguage) ;
        !           269:    TSPRINTF (EnglishLangId, TEXT("%03x"), iEnglishLanguage) ;
        !           270: 
        !           271:    // GetComputerName returns the name without the "\\" prefix. We add
        !           272:    // the prefix before even calling the routine. This is so that all our
        !           273:    // computer names have the prefix and are therefore compatible with
        !           274:    // I_SetSystemFocus (see perfmops.c).
        !           275: 
        !           276:    ComputerNameLength = MAX_COMPUTERNAME_LENGTH + 1;
        !           277:    lstrcpy (LocalComputerName, szComputerPrefix) ;
        !           278:    GetComputerName (LocalComputerName + lstrlen (szComputerPrefix), 
        !           279:                     &ComputerNameLength);
        !           280: 
        !           281:    PlaybackInitializeInstance () ;
        !           282:    PerfDataInitializeInstance () ;
        !           283: 
        !           284:    //=============================//
        !           285:    // Create Window               //
        !           286:    //=============================//
        !           287: 
        !           288:    StringLoad (IDS_APPNAME, szApplication) ;
        !           289:    hWndMain = CreateWindow (szPerfmonMainClass,
        !           290:                             szApplication,
        !           291:                                    WS_OVERLAPPEDWINDOW | WS_BORDER,
        !           292:                                 CW_USEDEFAULT, CW_USEDEFAULT, 
        !           293:                                 CW_USEDEFAULT, CW_USEDEFAULT, 
        !           294:                                      NULL,
        !           295:                             NULL,
        !           296:                             NULL,
        !           297:                             NULL);
        !           298: 
        !           299:    if (!hWndMain)
        !           300:       return (FALSE) ;
        !           301: 
        !           302:    ViewChart (hWndMain) ;
        !           303: 
        !           304:    LoadMainWindowPlacement (hWndMain) ;
        !           305: 
        !           306:    return (TRUE) ;
        !           307:    }  // InitializeInstance
        !           308: 
        !           309: 
        !           310: //==========================================================================//
        !           311: //                             Exported Functions                           //
        !           312: //==========================================================================//
        !           313: 
        !           314: 
        !           315: BOOL PerfmonInitialize (HINSTANCE hCurrentInstance,
        !           316:                         HINSTANCE hPrevInstance,
        !           317:                         LPCSTR lpszCmdLine,
        !           318:                         int nCmdShow)
        !           319: /*
        !           320:    Effect:        Performa all initializations required when Perfmon is
        !           321:                   started. In particular, initialize all "systems", register
        !           322:                   all window classes, create needed windows, read in and
        !           323:                   process font and Perfmon lists.
        !           324: 
        !           325:    Called By:     WinMain only, at the start of the application.
        !           326: 
        !           327:    Assert:        There are no other instances of Perfmon currently
        !           328:                   executing.
        !           329: 
        !           330:    Returns:       Whether initialization was successful. If this function
        !           331:                   returns FALSE, Perfmon should exit immediately.
        !           332: 
        !           333:    Internals:     The bSuccess variable is used to conditionalize each
        !           334:                   successive initialization step.
        !           335: */
        !           336:    {  // PerfmonInitialize
        !           337:    BOOL           bSuccess ;
        !           338:    TCHAR          szFilePath [FilePathLen + 1] ;
        !           339:    LPTSTR         pFileNameStart ;
        !           340:    HANDLE         hFindFile ;
        !           341:    WIN32_FIND_DATA FindFileInfo ;
        !           342:    CHAR           QuoteChar ;
        !           343:    LPSTR          pCmdLine ;
        !           344:    int            NameOffset ;
        !           345: 
        !           346: 
        !           347:    hInstance = hCurrentInstance ;
        !           348:    bSuccess = InitializeSystemValues () ;
        !           349: 
        !           350:    if (bSuccess && !hPrevInstance)
        !           351:       bSuccess = InitializeApplication () ;
        !           352: 
        !           353:    if (bSuccess)
        !           354:       bSuccess = InitializeInstance (nCmdShow, lpszCmdLine) ;
        !           355: 
        !           356:    GetDateTimeFormats() ;
        !           357: 
        !           358:    if (bSuccess)
        !           359:       {
        !           360: 
        !           361:       if (strempty (lpszCmdLine))
        !           362:          StringLoad (IDS_DEFAULTPATH, szFilePath) ;
        !           363:       else
        !           364:          {
        !           365:          // check for single or double quote
        !           366:          QuoteChar = *lpszCmdLine ;
        !           367:          if (QuoteChar == '\'' || QuoteChar == '\"')
        !           368:             {
        !           369:             lpszCmdLine++ ;
        !           370: 
        !           371:             // remove the matching QuoteChar if found
        !           372:             pCmdLine = (LPSTR) lpszCmdLine ;
        !           373:             while (*pCmdLine != '\0')
        !           374:                {
        !           375:                if (*pCmdLine == QuoteChar)
        !           376:                   {
        !           377:                   *pCmdLine = '\0' ;
        !           378:                   break ;
        !           379:                   }
        !           380:                else
        !           381:                   {
        !           382:                   pCmdLine++ ;
        !           383:                   }
        !           384:                }
        !           385:             }
        !           386: 
        !           387:          // convert the LPSTR to LPTSTR
        !           388: 
        !           389:          mbstowcs (szFilePath, lpszCmdLine, strlen(lpszCmdLine) + 1) ;
        !           390: 
        !           391:          pFileNameStart = ExtractFileName (szFilePath) ;
        !           392:          NameOffset = pFileNameStart - szFilePath ;
        !           393: 
        !           394:          // convert short filename to long NTFS filename if necessary
        !           395:          hFindFile = FindFirstFile (szFilePath, &FindFileInfo) ;
        !           396:          if (hFindFile && hFindFile != INVALID_HANDLE_VALUE)
        !           397:             {
        !           398:             // append the file name back to the path name
        !           399:             lstrcpy (&szFilePath[NameOffset], FindFileInfo.cFileName) ;
        !           400:             FindClose (hFindFile) ;
        !           401:             }
        !           402:          }
        !           403:       
        !           404: //      OpenFileHandler (hWndMain, szFilePath) ;
        !           405:       FileOpen (hWndMain, (int)0, (LPTSTR)szFilePath) ;
        !           406:       PrepareMenu (GetMenu (hWndMain));
        !           407:       }
        !           408: 
        !           409:    return (bSuccess) ;
        !           410:    }  // PerfmonInitialize
        !           411: 
        !           412: 
        !           413: 
        !           414: void PerfmonClose (HWND hWndMain)
        !           415:    {
        !           416:    if (!QuerySaveChart (hWndMain, pGraphs))
        !           417:       return ;
        !           418: 
        !           419:    // close the log file for now.
        !           420:    // need to query the user later..!!
        !           421:    if (LogCollecting (hWndLog))
        !           422:       {
        !           423:       PLOG pLog = LogData (hWndLog) ;
        !           424:       
        !           425:       if (pLog)
        !           426:          {
        !           427:          CloseLog (hWndLog, pLog) ;
        !           428:          }
        !           429:       }
        !           430:       
        !           431: 
        !           432:    // free all the filenames
        !           433:    if (pChartFullFileName)
        !           434:       {
        !           435:       MemoryFree (pChartFullFileName) ;
        !           436:       pChartFullFileName = NULL ;
        !           437:       }
        !           438:    if (pAlertFullFileName)
        !           439:       {
        !           440:       MemoryFree (pAlertFullFileName) ;
        !           441:       pAlertFullFileName = NULL ;
        !           442:       }
        !           443:    if (pLogFullFileName)
        !           444:       {
        !           445:       MemoryFree (pLogFullFileName) ;
        !           446:       pLogFullFileName = NULL ;
        !           447:       }
        !           448:    if (pReportFullFileName)
        !           449:       {
        !           450:       MemoryFree (pReportFullFileName) ;
        !           451:       pReportFullFileName = NULL ;
        !           452:       }
        !           453: 
        !           454:    // free all the GDI resources
        !           455:    DeletePen (hWhitePen) ;
        !           456:    DeletePerfmonSystemObjects () ;
        !           457: 
        !           458:    SaveMainWindowPlacement (hWndMain) ;
        !           459:    DestroyWindow (hWndMain) ;
        !           460:    }  // PerfmonClose
        !           461: 
        !           462: 

unix.superglobalmegacorp.com

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