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

1.1     ! root        1: /*****************************************************************************
        !             2:  *
        !             3:  *  Perfmon.c - This is the WinMain module. It creates the main window and
        !             4:  *              the threads, and contains the main MainWndProc.
        !             5:  *
        !             6:  *  Microsoft Confidential
        !             7:  *  Copyright (c) 1992-1993 Microsoft Corporation
        !             8:  *
        !             9:  *  Authors -
        !            10:  *
        !            11:  *       Russ Blake
        !            12:  *       Mike Moskowitz
        !            13:  *       Hon-Wah Chan
        !            14:  *       Bob Watson
        !            15:  *
        !            16:  ****************************************************************************/
        !            17: 
        !            18: 
        !            19: //==========================================================================//
        !            20: //                                  Includes                                //
        !            21: //==========================================================================//
        !            22: #undef NOSYSCOMMANDS
        !            23: 
        !            24: // DEFINE_GLOBALS will define all the globals listed in globals.h
        !            25: #define DEFINE_GLOBALS
        !            26: 
        !            27: #include "perfmon.h"
        !            28: 
        !            29: #include "command.h"
        !            30: 
        !            31: #include "graph.h"
        !            32: #include "log.h"
        !            33: #include "alert.h"
        !            34: #include "report.h"     // for CreateReportWindow
        !            35: #include "legend.h"
        !            36: #include "init.h"
        !            37: #include "perfmops.h"
        !            38: #include "toolbar.h"    // for CreateToolbar
        !            39: #include "status.h"     // for CreatePMStatusWindow
        !            40: #include "utils.h"
        !            41: 
        !            42: #include "fileopen.h"   // for FileOpen
        !            43: #ifdef DEBUGDUMP
        !            44: #include "debug.h"
        !            45: #endif
        !            46: 
        !            47: 
        !            48: 
        !            49: #define dwToolbarStyle     (WS_CHILD | WS_VISIBLE | TBS_NOCAPTION)
        !            50: 
        !            51: extern TCHAR szInternational[] ;
        !            52: 
        !            53: //==========================================================================//
        !            54: //                              Message Handlers                            //
        !            55: //==========================================================================//
        !            56: 
        !            57: void static OnSize (HWND hWnd,
        !            58:                     WORD xWidth,
        !            59:                     WORD yHeight)
        !            60: /*
        !            61:    Effect:        Perform any actions needed when the main window is
        !            62:                   resized. In particular, size the four data windows,
        !            63:                   only one of which is visible right now.
        !            64: */
        !            65:    {  // OnSize
        !            66:    SizePerfmonComponents () ;
        !            67:    }
        !            68: 
        !            69: 
        !            70: void static OnCreate (HWND hWnd)
        !            71: /*
        !            72:    Effect:        Perform all actions needed when the main window is
        !            73:                   created. In particular, create the three data windows,
        !            74:                   and show one of them.
        !            75: 
        !            76:    To Do:         Check for proper creation. If not possible, we will
        !            77:                   need to abort creation of the program.
        !            78: 
        !            79:    Called By:     MainWndProc only, in response to a WM_CREATE message.
        !            80: */
        !            81:    {  // OnCreate
        !            82:    hWndGraph = CreateGraphWindow (hWnd) ;
        !            83: 
        !            84: #ifdef ADVANCED_PERFMON
        !            85:    hWndLog = CreateLogWindow (hWnd) ;
        !            86:    hWndAlert = CreateAlertWindow (hWnd) ;
        !            87:    hWndReport = CreateReportWindow (hWnd) ;
        !            88: #endif
        !            89: 
        !            90:    hWndStatus = CreatePMStatusWindow (hWnd) ;
        !            91: 
        !            92:    CreateToolbarWnd (hWnd) ;
        !            93:    MinimumSize += WindowHeight (hWndToolbar) ;
        !            94: 
        !            95:    Options.bMenubar = TRUE ;
        !            96:    Options.bToolbar = TRUE ;
        !            97:    Options.bStatusbar = TRUE;
        !            98:    Options.bAlwaysOnTop = FALSE ;
        !            99: 
        !           100:    // initialize to chart view - HWC
        !           101:    iPerfmonView = IDM_VIEWCHART;
        !           102: 
        !           103: 
        !           104:    ShowWindow (PerfmonViewWindow (), SW_SHOWNORMAL) ;
        !           105:    }  // OnCreate
        !           106: 
        !           107: 
        !           108: 
        !           109: //==========================================================================//
        !           110: //                             Exported Functions                           //
        !           111: //==========================================================================//
        !           112: 
        !           113: void MenuBarHit (DWORD wParam)
        !           114: {
        !           115:    if (wParam == MENUCLOSING)
        !           116:       {
        !           117:       StatusLineReady (hWndStatus) ;
        !           118:       dwCurrentMenuID = 0 ;
        !           119:       }
        !           120:    else if (HIWORD(wParam) & MF_SYSMENU)
        !           121:       {
        !           122:       WORD   SystemMenuItem = 0 ;
        !           123:       switch (LOWORD (wParam))
        !           124:          {
        !           125:          case SC_RESTORE:
        !           126:             SystemMenuItem = IDM_SYSTEMRESTORE ;
        !           127:             break ;
        !           128: 
        !           129:          case SC_SIZE:
        !           130:             SystemMenuItem = IDM_SYSTEMSIZE ;
        !           131:             break ;
        !           132: 
        !           133:          case SC_MOVE:
        !           134:             SystemMenuItem = IDM_SYSTEMMOVE ;
        !           135:             break ;
        !           136: 
        !           137:          case SC_MINIMIZE:
        !           138:             SystemMenuItem = IDM_SYSTEMMINIMIZE ;
        !           139:             break ;
        !           140: 
        !           141:          case SC_MAXIMIZE:
        !           142:             SystemMenuItem = IDM_SYSTEMMAXIMIZE ;
        !           143:             break ;
        !           144: 
        !           145:          case SC_CLOSE:
        !           146:             SystemMenuItem = IDM_SYSTEMCLOSE ;
        !           147:             break ;
        !           148: 
        !           149:          case SC_TASKLIST:
        !           150:             SystemMenuItem = IDM_SYSTEMSWITCHTO ;
        !           151:             break ;
        !           152:          }
        !           153: 
        !           154:       if (SystemMenuItem)
        !           155:          {
        !           156:          StatusLine (hWndStatus, SystemMenuItem) ;
        !           157:          dwCurrentMenuID = MenuIDToHelpID (SystemMenuItem) ;
        !           158:          }
        !           159:       }
        !           160:    else
        !           161:       {
        !           162:       StatusLine (hWndStatus, LOWORD (wParam)) ;
        !           163:       }
        !           164: }
        !           165: 
        !           166: void OnDropFile (DWORD wParam)
        !           167:    {
        !           168:    TCHAR FileName [FilePathLen + 1] ;
        !           169:    LPTSTR         pFileNameStart ;
        !           170:    HANDLE         hFindFile ;
        !           171:    WIN32_FIND_DATA FindFileInfo ;
        !           172:    int            NameOffset ;
        !           173:    int            NumOfFiles = 0 ;
        !           174: 
        !           175:    NumOfFiles = DragQueryFile ((HDROP) wParam, 0xffffffff, NULL, 0) ;
        !           176:    if (NumOfFiles > 0)
        !           177:       {
        !           178:       // we only open the first file for now
        !           179:       DragQueryFile((HDROP) wParam, 0, FileName, FilePathLen) ;
        !           180: 
        !           181:       pFileNameStart = ExtractFileName (FileName) ;
        !           182:       NameOffset = pFileNameStart - FileName ;
        !           183: 
        !           184:       // convert short filename to long NTFS filename if necessary
        !           185:       hFindFile = FindFirstFile (FileName, &FindFileInfo) ;
        !           186:       if (hFindFile && hFindFile != INVALID_HANDLE_VALUE)
        !           187:          {
        !           188:          // append the file name back to the path name
        !           189:          lstrcpy (&FileName[NameOffset], FindFileInfo.cFileName) ;
        !           190:          FindClose (hFindFile) ;
        !           191:          }
        !           192: 
        !           193:       FileOpen (hWndMain, (int)0, (LPTSTR)FileName) ;
        !           194:       PrepareMenu (GetMenu (hWndMain));
        !           195:       }
        !           196: 
        !           197:    DragFinish ((HDROP) wParam) ;
        !           198:    }
        !           199: 
        !           200: LRESULT APIENTRY MainWndProc (HWND hWnd, 
        !           201:                               UINT message, 
        !           202:                               DWORD wParam, 
        !           203:                               LONG lParam)
        !           204:    {
        !           205:    LONG     lRetCode = 0L ;
        !           206:    BOOL     bCallDefWinProc = FALSE ;
        !           207: 
        !           208:    switch (LOWORD (message))
        !           209:       {  // switch
        !           210:       case WM_LBUTTONDBLCLK:
        !           211:          ShowPerfmonMenu (!Options.bMenubar) ;
        !           212:          if (Options.bMenubar)
        !           213:             {
        !           214:             PrepareMenu (GetMenu (hWnd)) ;
        !           215:             }
        !           216:          break ;
        !           217: 
        !           218:           case WM_COMMAND:
        !           219:              if (PerfmonCommand (hWnd,wParam,lParam))
        !           220:                 return(0);
        !           221:          else
        !           222:             bCallDefWinProc = TRUE ;
        !           223:          break;
        !           224: 
        !           225:       case WM_MENUSELECT:
        !           226:          MenuBarHit (wParam) ;
        !           227:          break ;
        !           228: 
        !           229:       case WM_NCHITTEST:
        !           230:         /* if we have no title/menu bar, clicking and dragging the client
        !           231:          * area moves the window. To do this, return HTCAPTION.
        !           232:          * Note dragging not allowed if window maximized, or if caption
        !           233:          * bar is present.
        !           234:          */
        !           235:         wParam = DefWindowProc(hWnd, message, wParam, lParam);
        !           236:         if (!Options.bMenubar && 
        !           237:             (wParam == HTCLIENT) &&
        !           238:             !IsZoomed (hWndMain))
        !           239:            return HTCAPTION ;
        !           240:         else
        !           241:            return wParam ;
        !           242:         break ;
        !           243: 
        !           244:       
        !           245:       case WM_SHOWWINDOW:
        !           246:          PrepareMenu (GetMenu (hWnd)) ;
        !           247:          break ;
        !           248: 
        !           249:       case WM_SIZE:
        !           250:          OnSize (hWnd, LOWORD (lParam), HIWORD (lParam)) ;
        !           251:          break ;
        !           252: 
        !           253:       case WM_GETMINMAXINFO:
        !           254:          {
        !           255:          MINMAXINFO   *pMinMax ;
        !           256: 
        !           257:          pMinMax = (MINMAXINFO *) lParam ;
        !           258:          pMinMax->ptMinTrackSize.x = MinimumSize ;
        !           259:          pMinMax->ptMinTrackSize.y = MinimumSize ;
        !           260:          }
        !           261:          break ;
        !           262: 
        !           263:       case WM_F1DOWN:
        !           264:          if (dwCurrentDlgID)
        !           265:             {
        !           266:             CallWinHelp (dwCurrentDlgID) ;
        !           267:             }
        !           268:          else if (dwCurrentMenuID)
        !           269:             {
        !           270:             CallWinHelp (dwCurrentMenuID) ;
        !           271:             dwCurrentMenuID = 0 ;
        !           272:             }
        !           273:          break ;
        !           274: 
        !           275:       case WM_CREATE:
        !           276:          OnCreate (hWnd) ;
        !           277:          ViewChart (hWnd) ;
        !           278:          PrepareMenu (GetMenu (hWnd)) ;
        !           279:          break ;
        !           280: 
        !           281:       case WM_DESTROY:
        !           282:          WinHelp (hWndMain, pszHelpFile, HELP_QUIT, 0) ;
        !           283:          PostQuitMessage (0);
        !           284:          break ;
        !           285: 
        !           286:       case WM_QUERYENDSESSION:
        !           287:          // please shut it down
        !           288:          return (1) ;
        !           289:          break ;
        !           290: 
        !           291:       case WM_ENDSESSION:
        !           292:          if (wParam == TRUE)
        !           293:             {
        !           294:             // close any log file before closing down
        !           295:             PerfmonClose (hWnd) ;
        !           296:             return (1) ;
        !           297:             }
        !           298:          else
        !           299:             bCallDefWinProc = TRUE ;
        !           300:          break ;
        !           301: 
        !           302:       case WM_CLOSE:
        !           303:          PerfmonClose (hWnd) ;
        !           304:          break ;
        !           305: 
        !           306:       case WM_ACTIVATE:
        !           307:          bPerfmonIconic = (BOOL) HIWORD (wParam) ;
        !           308:          break ;
        !           309: 
        !           310:       case WM_SYSCOLORCHANGE:
        !           311:          DeletePerfmonSystemObjects () ;
        !           312:          CreatePerfmonSystemObjects () ;
        !           313:          WindowInvalidate (PerfmonViewWindow()) ;
        !           314:          break ;
        !           315: 
        !           316:       case WM_WININICHANGE:
        !           317:          if (!lParam || strsamei((LPTSTR)lParam, szInternational))
        !           318:             {
        !           319:             GetDateTimeFormats () ;
        !           320:             }
        !           321:          break ;
        !           322: 
        !           323:       case WM_DROPFILES:
        !           324:          OnDropFile (wParam) ;
        !           325:          return (0) ;
        !           326:          break ;
        !           327: 
        !           328:       default:
        !           329:          bCallDefWinProc = TRUE ;
        !           330:              break;
        !           331: 
        !           332:       }  // switch
        !           333: 
        !           334:    if (bCallDefWinProc)
        !           335:       {
        !           336:       lRetCode = DefWindowProc (hWnd, message, wParam, lParam) ;
        !           337:       }
        !           338:    return (lRetCode);
        !           339:    }  // MainWndProc
        !           340: 
        !           341: 
        !           342: int PASCAL WinMain (HINSTANCE hCurrentInstance,
        !           343:                            HINSTANCE hPrevInstance,
        !           344:                     LPSTR lpszCmdLine, 
        !           345:                     int nCmdShow)
        !           346:    {  // WinMain
        !           347:    MSG      msg;
        !           348: 
        !           349:    if (!PerfmonInitialize (hCurrentInstance, hPrevInstance, 
        !           350:                            lpszCmdLine, nCmdShow))
        !           351:       return (FALSE) ;
        !           352: 
        !           353:    DragAcceptFiles (hWndMain, TRUE) ;
        !           354: 
        !           355:    while (GetMessage (&msg, NULL, 0, 0))
        !           356:       {
        !           357:       if (!TranslateAccelerator(hWndMain, hAccelerators, &msg))
        !           358:          {
        !           359:          TranslateMessage (&msg) ;
        !           360:          DispatchMessage (&msg) ;
        !           361:          }
        !           362:       }  // while
        !           363: 
        !           364:    return(msg.wParam);
        !           365:    }
        !           366: 
        !           367: DWORD FAR PASCAL MessageFilterProc (int nCode,
        !           368:                                     WPARAM wParam,
        !           369:                                     LPARAM lParam)
        !           370:    {
        !           371:    LPMSG lpMsg = (LPMSG)lParam ;
        !           372:    extern HHOOK lpMsgFilterProc ;
        !           373: 
        !           374:    if (nCode < 0)
        !           375:       {
        !           376:       return FALSE ;
        !           377:       }
        !           378: 
        !           379:    if (nCode == MSGF_DIALOGBOX || nCode == MSGF_MENU)
        !           380:       {
        !           381:       if (lpMsg->message == WM_KEYDOWN && lpMsg->wParam == VK_F1)
        !           382:           {
        !           383:           PostMessage (hWndMain, WM_F1DOWN, nCode, 0L) ;
        !           384:           return TRUE ;
        !           385:           }
        !           386:       }
        !           387: 
        !           388:    return (DefHookProc (nCode, wParam,
        !           389:               (DWORD)lpMsg,
        !           390:               &lpMsgFilterProc)) ;
        !           391:    }
        !           392: 
        !           393: 
        !           394: #if 0
        !           395: /***************************************/
        !           396: VOID ErrorExit(LPTSTR pszError,HWND hwnd)
        !           397: /***************************************/
        !           398: {
        !           399:     // NOTE: make sure all lgraph calls set StopQuerying.
        !           400: 
        !           401:     if (hwnd)
        !           402:     {
        !           403:         MessageBox(NULL, pszError, nm_buf, MB_ICONHAND | MB_OK | MB_SYSTEMMODAL);
        !           404:         DestroyWindow(hwnd);
        !           405:     }
        !           406:     return;
        !           407: }
        !           408: #endif
        !           409: 
        !           410: 
        !           411: 
        !           412: void SizePerfmonComponents (void) 
        !           413:    {
        !           414:    RECT           rectClient ;
        !           415:    int            xWidth, yHeight ;
        !           416:    int            yToolbarHeight ;
        !           417:    int            yStatusHeight ;
        !           418:    int            yViewHeight ;
        !           419: 
        !           420:    GetClientRect (hWndMain, &rectClient) ;
        !           421:    xWidth = rectClient.right - rectClient.left ;
        !           422:    yHeight = rectClient.bottom - rectClient.top ;
        !           423: 
        !           424:    if (Options.bToolbar)
        !           425:       {
        !           426:       SendMessage (hWndToolbar, WM_SIZE, 0, 0L) ;
        !           427:       }
        !           428: 
        !           429:    yToolbarHeight = Options.bToolbar ? (WindowHeight (hWndToolbar) - 1) : 0 ;
        !           430:    yStatusHeight = Options.bStatusbar ? StatusHeight (hWndStatus) : 0 ;
        !           431: 
        !           432:    if (Options.bStatusbar)
        !           433:       {
        !           434:       if (yToolbarHeight + yStatusHeight > yHeight)
        !           435:          {
        !           436:          // too small to display both toolbar and status bar
        !           437:          // just display part of the status bar
        !           438:          yStatusHeight = yHeight - yToolbarHeight ;
        !           439:          }
        !           440: 
        !           441:       MoveWindow (hWndStatus, 
        !           442:                   0, yHeight - yStatusHeight, xWidth, yStatusHeight, TRUE) ;
        !           443:       //WindowInvalidate (hWndStatus) ;
        !           444:       }
        !           445:    //WindowInvalidate (hWndMain) ;
        !           446:    WindowShow (hWndStatus, Options.bStatusbar) ;
        !           447:    WindowShow (hWndToolbar, Options.bToolbar) ;
        !           448: 
        !           449:    yViewHeight = yHeight - yStatusHeight - yToolbarHeight ;
        !           450: 
        !           451:    MoveWindow (hWndGraph, 
        !           452:                0, yToolbarHeight, 
        !           453:                xWidth, yViewHeight, 
        !           454:                TRUE) ;
        !           455:    MoveWindow (hWndAlert, 
        !           456:                0, yToolbarHeight, 
        !           457:                xWidth, yViewHeight, 
        !           458:                TRUE) ;
        !           459:    MoveWindow (hWndLog, 
        !           460:                0, yToolbarHeight, 
        !           461:                xWidth, yViewHeight, 
        !           462:                TRUE) ;
        !           463:    MoveWindow (hWndReport, 
        !           464:                0, yToolbarHeight, 
        !           465:                xWidth, yViewHeight, 
        !           466:                TRUE) ;
        !           467: 
        !           468: 
        !           469:    }  // SizePerfmonComponents
        !           470: 
        !           471: 
        !           472: 
        !           473: 
        !           474: 

unix.superglobalmegacorp.com

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