/*++ Copyright (c) 1990 Microsoft Corporation Module Name: Wperf.c Abstract: Win32 application to display performance statictics. Author: Mark Enstrom (marke) Environment: Win32 Revision History: 10-20-91 Initial version --*/ // // set variable to define global variables // #include #include #include #include #include #include "wperf.h" // // global handles // HANDLE hInst; // // Selected Display Mode (read from wp2.ini), default set here. // DISPLAY_ITEM PerfDataList[SAVE_SUBJECTS]; WINPERF_INFO WinperfInfo; // // Window names // PUCHAR PerfNames[] = { "CPU0", "CPU1", "CPU2", "CPU3", "CPU4", "CPU5", "CPU6", "CPU7", "CPU8", "CPU9", "CPU10", "CPU11", "CPU12", "CPU13", "CPU14", "CPU15", "PAGE FLT", "PAGES AVAIL", "CONTEXT SW/S", "1st TB MISS/S", "2nd TB MISS/S", "SYSTEM CALLS/S", "INTERRUPT/S", "PAGE POOL", "NON-PAGE POOL", "PROCESSES", "THREADS", "ALIGN FIXUP", "EXCEPT DSPTCH", "FLOAT EMULAT", "INSTR EMULAT", "CPU" }; int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) /*++ Routine Description: Windows entry point routine Arguments: Return Value: status of operation Revision History: 03-21-91 Initial code --*/ { MSG msg; HBRUSH BackBrush; // // check for other instances of this program // BackBrush = CreateSolidBrush(RGB(192,192,192)); if (!InitApplication(hInstance,BackBrush)) { //DbgPrint("Init Application fails\n"); return (FALSE); } // // Perform initializations that apply to a specific instance // if (!InitInstance(hInstance, nCmdShow)){ return (FALSE); } // // Acquire and dispatch messages until a WM_QUIT message is received. // while (GetMessage(&msg, // message structure NULL, // handle of window receiving the message 0, // lowest message to examine 0)) // highest message to examine { TranslateMessage(&msg); // Translates virtual key codes DispatchMessage(&msg); // Dispatches message to window } DeleteObject(BackBrush); return (int)(msg.wParam); // Returns the value from PostQuitMessage } BOOL InitApplication( HANDLE hInstance, HBRUSH hBackground ) /*++ Routine Description: Initializes window data and registers window class. Arguments: hInstance - current instance hBackground - background fill brush Return Value: status of operation Revision History: 02-17-91 Initial code --*/ { WNDCLASS wc; BOOL ReturnStatus; // // Fill in window class structure with parameters that describe the // main window. // wc.style = CS_DBLCLKS; // Class style(s). wc.lpfnWndProc = MainWndProc; // Function to retrieve messages for // windows of this class. wc.cbClsExtra = 0; // No per-class extra data. wc.cbWndExtra = 0; // No per-window extra data. wc.hInstance = hInstance; // Application that owns the class. wc.hIcon = LoadIcon(hInstance, // MAKEINTRESOURCE(WINPERF_ICON)); // Load Winperf icon wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load default cursor wc.hbrBackground = hBackground;; // Use background passed to routine wc.lpszMenuName = "winperfMenu"; // Name of menu resource in .RC file. wc.lpszClassName = "WinPerfClass"; // Name used in call to CreateWindow. ReturnStatus = RegisterClass(&wc); return(ReturnStatus); } BOOL InitInstance( HANDLE hInstance, int nCmdShow ) /*++ Routine Description: Save instance handle and create main window. This function performs initialization tasks that cannot be shared by multiple instances. Arguments: hInstance - Current instance identifier. nCmdShow - Param for first ShowWindow() call. Return Value: status of operation Revision History: 02-17-91 Initial code --*/ { DWORD WindowStyle; // // Save the instance handle in a static variable, which will be used in // many subsequent calls from this application to Windows. // hInst = hInstance; // // init the window position and size to be in the upper corner of // the screen, 200x100 // // What I want here is a way to get the WINDOW dimensions // WinperfInfo.WindowPositionX = 640 - 200; WinperfInfo.WindowPositionY = 0; WinperfInfo.WindowSizeX = 200; WinperfInfo.WindowSizeY = 100; WinperfInfo.CpuStyle = CPU_STYLE_LINE; // // read profile data from .ini file // InitProfileData(&WinperfInfo); WinperfInfo.hMenu = LoadMenu(hInstance,"winperfMenu"); // // Create a main window for this application instance. // WinperfInfo.hWndMain = CreateWindow( "WinPerfClass", // See RegisterClass() call. "Perf Meter", // Text for window title bar. WS_OVERLAPPEDWINDOW, // window style WinperfInfo.WindowPositionX, // Default horizontal position. WinperfInfo.WindowPositionY, // Default vertical position. WinperfInfo.WindowSizeX, // Default width. WinperfInfo.WindowSizeY, // Default height. NULL, // Overlapped windows have no parent. NULL, // Use the window class menu. hInstance, // This instance owns this window. NULL // Pointer not needed. ); // // Decide on whether or not to display the menu and caption // based on the window class read from the .ini file // if (WinperfInfo.DisplayMode==STYLE_ENABLE_MENU) { WinperfInfo.DisplayMenu = TRUE; } else { WinperfInfo.DisplayMenu = FALSE; WindowStyle = GetWindowLong(WinperfInfo.hWndMain,GWL_STYLE); WindowStyle = (WindowStyle & (~STYLE_ENABLE_MENU)) | STYLE_DISABLE_MENU; SetWindowPos(WinperfInfo.hWndMain, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_DRAWFRAME); SetWindowLong(WinperfInfo.hWndMain,GWL_STYLE,WindowStyle); SetMenu(WinperfInfo.hWndMain,NULL); } // // If window could not be created, return "failure" // if (!WinperfInfo.hWndMain) { return (FALSE); } // // Make the window visible; update its client area; and return "success" // SetFocus(WinperfInfo.hWndMain); ShowWindow(WinperfInfo.hWndMain, SW_SHOWNORMAL); UpdateWindow(WinperfInfo.hWndMain); return (TRUE); } LRESULT APIENTRY MainWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) /*++ Routine Description: Process messages. Arguments: hWnd - window hande message - type of message wParam - additional information lParam - additional information Return Value: status of operation Revision History: 02-17-91 Initial code --*/ { PAINTSTRUCT ps; // // process each message // switch (message) { // // create window // case WM_CREATE: { HDC hDC = GetDC(hWnd); BOOLEAN Fit; UINT Index; // // make brushes and pens // WinperfInfo.hBluePen = CreatePen(PS_SOLID,1,RGB(000,000,128)); WinperfInfo.hRedPen = CreatePen(PS_SOLID,1,RGB(255,000,000)); WinperfInfo.hGreenPen = CreatePen(PS_SOLID,1,RGB(000,255,000)); WinperfInfo.hMagentaPen = CreatePen(PS_SOLID,1,RGB(255,000,254)); WinperfInfo.hYellowPen = CreatePen(PS_SOLID,1,RGB(255,255,000)); WinperfInfo.hDotPen = CreatePen(PS_DOT,1,RGB(000,000,000)); WinperfInfo.hBackground = CreateSolidBrush(RGB(192,192,192)); WinperfInfo.hLightBrush = CreateSolidBrush(RGB(255,255,255)); WinperfInfo.hDarkBrush = CreateSolidBrush(RGB(128,128,128)); WinperfInfo.hRedBrush = CreateSolidBrush(RGB(255,000,000)); WinperfInfo.hGreenBrush = CreateSolidBrush(RGB(000,255,000)); WinperfInfo.hBlueBrush = CreateSolidBrush(RGB(000,000,255)); WinperfInfo.hMagentaBrush= CreateSolidBrush(RGB(255,000,254)); WinperfInfo.hYellowBrush = CreateSolidBrush(RGB(255,255,000)); // // create thee fonts using NT default font families // WinperfInfo.SmallFont = CreateFont(8, 0, 0, 0, 400, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, DEFAULT_PITCH, "Small Fonts"); WinperfInfo.MediumFont = CreateFont(10, 0, 0, 0, 400, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, DEFAULT_PITCH, "Times New Roman"); WinperfInfo.LargeFont = CreateFont(14, 0, 0, 0, 400, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, DEFAULT_PITCH, "Times New Roman"); // // create a system timer event to call performance gathering routines by. // WinperfInfo.TimerId = SetTimer(hWnd, TIMER_ID, 1000 * DELAY_SECONDS, NULL); // // init display variables // InitPerfWindowDisplay(hWnd,hDC,PerfDataList,SAVE_SUBJECTS); // // Fit the perf windows into the main window // Fit = FitPerfWindows(hWnd,hDC,PerfDataList,SAVE_SUBJECTS); if (!Fit) { //DbgPrint("FitPerfWindows Fails !\n"); } for (Index=0;Index WinperfInfo.NumberOfProcessors // // Also Disable radio button // PerfDataList[Index].Display = FALSE; EnableWindow(GetDlgItem(hDlg,IDM_CPU0+Index),FALSE); } } else { // // Set or clear radio button based on display variable // if (PerfDataList[Index].Display == TRUE) { SendDlgItemMessage(hDlg,IDM_CPU0+Index,BM_SETCHECK,1,0); } else { SendDlgItemMessage(hDlg,IDM_CPU0+Index,BM_SETCHECK,0,0); } } } // // Beyond the end of the save subjects lies the cpu Style, set this to either style // if (WinperfInfo.CpuStyle == CPU_STYLE_LINE) { CheckRadioButton(hDlg,IDM_SEL_LINE,IDM_SEL_BAR,IDM_SEL_LINE); } else { CheckRadioButton(hDlg,IDM_SEL_LINE,IDM_SEL_BAR,IDM_SEL_BAR); } return (TRUE); case WM_COMMAND: switch(wParam) { // // end function // case IDOK: for (Index=0;IndexWindowPositionX,"winperf.ini"); PositionY = GetPrivateProfileInt("winperf","PositionY" ,pWinperfInfo->WindowPositionY,"winperf.ini"); SizeX = GetPrivateProfileInt("winperf","SizeX" ,pWinperfInfo->WindowSizeX ,"winperf.ini"); SizeY = GetPrivateProfileInt("winperf","SizeY" ,pWinperfInfo->WindowSizeY ,"winperf.ini"); // // read the first deiplay element with default 1 // Element[0] = GetPrivateProfileInt("winperf","DisplayElement0",1,"winperf.ini"); // // read the rest of the display elements with default 0 // for (Index=1;IndexDisplayMode ,"winperf.ini"); CpuStyle = GetPrivateProfileInt("winperf","CpuStyle",pWinperfInfo->CpuStyle ,"winperf.ini"); pWinperfInfo->WindowPositionX = PositionX; pWinperfInfo->WindowPositionY = PositionY; pWinperfInfo->WindowSizeX = SizeX; pWinperfInfo->WindowSizeY = SizeY; for (Index=0;IndexDisplayElement[Index] = Element[Index]; } pWinperfInfo->DisplayMode = Mode; pWinperfInfo->CpuStyle = CpuStyle; } VOID SaveProfileData( PWINPERF_INFO pWinperfInfo ) /*++ Routine Description: Save profile data Arguments: WindowPositionX - Window initial x position WindowPositionY - Window initial y position WindowSizeX - Window initial width WindowSizey - Window Initial height DisplayMode - Window initial display mode Return Value: None. Revision History: 02-17-91 Initial code --*/ { UCHAR TempStr[50],TempName[50]; UINT Index; wsprintf(TempStr,"%i",pWinperfInfo->WindowPositionX); WritePrivateProfileString("winperf","PositionX",TempStr,"winperf.ini"); wsprintf(TempStr,"%i",pWinperfInfo->WindowPositionY); WritePrivateProfileString("winperf","PositionY",TempStr,"winperf.ini"); wsprintf(TempStr,"%i",pWinperfInfo->WindowSizeX); WritePrivateProfileString("winperf","SizeX",TempStr,"winperf.ini"); wsprintf(TempStr,"%i",pWinperfInfo->WindowSizeY); WritePrivateProfileString("winperf","SizeY",TempStr,"winperf.ini"); for (Index=0;IndexDisplayElement[Index]); wsprintf(TempName,"DisplayElement%li",Index); WritePrivateProfileString("winperf",TempName,TempStr,"winperf.ini"); } wsprintf(TempStr,"%li",pWinperfInfo->DisplayMode); WritePrivateProfileString("winperf","DisplayMode",TempStr,"winperf.ini"); wsprintf(TempStr,"%li",pWinperfInfo->CpuStyle); WritePrivateProfileString("winperf","CpuStyle",TempStr,"winperf.ini"); } BOOLEAN InitPerfWindowDisplay( IN HWND hWnd, IN HDC hDC, IN PDISPLAY_ITEM DisplayItems, IN ULONG NumberOfWindows ) /*++ Routine Description: Init All perf windows to active, init data Arguments: hDC - Screen context DisplayItems - List of display structures NumberOfWindows - Number of sub-windows Return Value: Status Revision History: 02-17-91 Initial code --*/ { int Index1; UINT Index; for (Index=0;Index