/*++ Copyright (c) 1990 Microsoft Corporation Module Name: Vdmperf.c Abstract: Win32 application to display VDM performance statictics. Author: Mark Lucovsky (stolen from Mark Enstrom (marke) winperf) Environment: Win32 Revision History: 11-05-92 Initial version --*/ // // set variable to define global variables // #include #include #include #include #include #include "vdmperf.h" // // global handles // HANDLE hInst; // // Selected Display Mode (read from wp2.ini), default set here. // DISPLAY_ITEM PerfDataList[SAVE_SUBJECTS]; VDMPERF_INFO VdmperfInfo; // // Window names // PUCHAR PerfNames[] = { "PUSHF", "POPF", "IRET", "HLT", "CLI", "STI", "BOP", "SEG_NOT_P", "VDMOPCODEF", "INTNN", "INTO", "INB", "INW", "OUTB", "OUTW", "INSB", "INSW", "OUTSB", "OUTSW" }; int __cdecl main(USHORT argc, CHAR **argv) /*++ Routine Description: Windows entry point routine Arguments: Return Value: status of operation Revision History: 03-21-91 Initial code --*/ { // // // HANDLE hInstance = MGetInstHandle(); HANDLE hPrevInstance = (HANDLE)NULL; LPSTR lpCmdLine = MGetCmdLine(); INT nCmdShow = SW_SHOWDEFAULT; USHORT _argc = argc; CHAR **_argv = argv; 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)){ DbgPrint("Init Instance failed\n"); return (FALSE); } // // Acquire and dispatch messages until a WM_QUIT message is received. // while (GetMessage(&msg, // message structure (HWND)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 = (WNDPROC)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((HANDLE)NULL, IDC_ARROW); // Load default cursor wc.hbrBackground = hBackground;; // Use background passed to routine wc.lpszMenuName = "vdmperfMenu"; // Name of menu resource in .RC file. wc.lpszClassName = "VdmPerfClass"; // 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 // VdmperfInfo.WindowPositionX = 640 - 200; VdmperfInfo.WindowPositionY = 0; VdmperfInfo.WindowSizeX = 200; VdmperfInfo.WindowSizeY = 100; // // read profile data from .ini file // InitProfileData(&VdmperfInfo); VdmperfInfo.hMenu = LoadMenu(hInstance,"vdmperfMenu"); // // Create a main window for this application instance. // VdmperfInfo.hWndMain = CreateWindow( "VdmPerfClass", // See RegisterClass() call. "VDM Perf", // Text for window title bar. WS_OVERLAPPEDWINDOW, // window style VdmperfInfo.WindowPositionX, // Default horizontal position. VdmperfInfo.WindowPositionY, // Default vertical position. VdmperfInfo.WindowSizeX, // Default width. VdmperfInfo.WindowSizeY, // Default height. (HWND)NULL, // Overlapped windows have no parent. (HMENU)NULL, // Use the window class menu. hInstance, // This instance owns this window. (LPVOID)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 (VdmperfInfo.DisplayMode==STYLE_ENABLE_MENU) { VdmperfInfo.DisplayMenu = TRUE; } else { VdmperfInfo.DisplayMenu = FALSE; WindowStyle = GetWindowLong(VdmperfInfo.hWndMain,GWL_STYLE); WindowStyle = (WindowStyle & (~STYLE_ENABLE_MENU)) | STYLE_DISABLE_MENU; SetWindowPos(VdmperfInfo.hWndMain, (HWND)NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_DRAWFRAME); SetWindowLong(VdmperfInfo.hWndMain,GWL_STYLE,WindowStyle); SetMenu(VdmperfInfo.hWndMain,NULL); } // // If window could not be created, return "failure" // if (!VdmperfInfo.hWndMain) { return (FALSE); } // // Make the window visible; update its client area; and return "success" // SetFocus(VdmperfInfo.hWndMain); ShowWindow(VdmperfInfo.hWndMain, SW_SHOWNORMAL); UpdateWindow(VdmperfInfo.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 // VdmperfInfo.hBluePen = CreatePen(PS_SOLID,1,RGB(0,0,128)); VdmperfInfo.hRedPen = CreatePen(PS_SOLID,1,RGB(255,0,0)); VdmperfInfo.hGreenPen = CreatePen(PS_SOLID,1,RGB(0,255,0)); VdmperfInfo.hDotPen = CreatePen(PS_DOT,1,RGB(0,0,0)); VdmperfInfo.hBackground = CreateSolidBrush(RGB(192,192,192)); VdmperfInfo.hLightBrush = CreateSolidBrush(RGB(255,255,255)); VdmperfInfo.hDarkBrush = CreateSolidBrush(RGB(128,128,128)); VdmperfInfo.hRedBrush = CreateSolidBrush(RGB(255,000,000)); VdmperfInfo.hGreenBrush = CreateSolidBrush(RGB(000,255,000)); VdmperfInfo.hBlueBrush = CreateSolidBrush(RGB(000,000,255)); // // create thee fonts using NT default font families // VdmperfInfo.SmallFont = CreateFont(8, 0, 0, 0, 400, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, DEFAULT_PITCH, "Small Fonts"); VdmperfInfo.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"); VdmperfInfo.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. // VdmperfInfo.TimerId = SetTimer(hWnd,(UINT)TIMER_ID,(UINT)1000 * DELAY_SECONDS,(TIMERPROC)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;IndexWindowPositionX,"vdmperf.ini"); PositionY = GetPrivateProfileInt("vdmperf","PositionY" ,pVdmperfInfo->WindowPositionY,"vdmperf.ini"); SizeX = GetPrivateProfileInt("vdmperf","SizeX" ,pVdmperfInfo->WindowSizeX ,"vdmperf.ini"); SizeY = GetPrivateProfileInt("vdmperf","SizeY" ,pVdmperfInfo->WindowSizeY ,"vdmperf.ini"); // // read the first deiplay element with default 1 // Element[0] = GetPrivateProfileInt("vdmperf","DisplayElement0",1,"vdmperf.ini"); // // read the rest of the display elements with default 0 // for (Index=1;IndexDisplayMode ,"vdmperf.ini"); pVdmperfInfo->WindowPositionX = PositionX; pVdmperfInfo->WindowPositionY = PositionY; pVdmperfInfo->WindowSizeX = SizeX; pVdmperfInfo->WindowSizeY = SizeY; for (Index=0;IndexDisplayElement[Index] = Element[Index]; } pVdmperfInfo->DisplayMode = Mode; } VOID SaveProfileData(PVDMPERF_INFO pVdmperfInfo) /*++ 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",pVdmperfInfo->WindowPositionX); WritePrivateProfileString("vdmperf","PositionX",TempStr,"vdmperf.ini"); wsprintf(TempStr,"%i",pVdmperfInfo->WindowPositionY); WritePrivateProfileString("vdmperf","PositionY",TempStr,"vdmperf.ini"); wsprintf(TempStr,"%i",pVdmperfInfo->WindowSizeX); WritePrivateProfileString("vdmperf","SizeX",TempStr,"vdmperf.ini"); wsprintf(TempStr,"%i",pVdmperfInfo->WindowSizeY); WritePrivateProfileString("vdmperf","SizeY",TempStr,"vdmperf.ini"); for (Index=0;IndexDisplayElement[Index]); wsprintf(TempName,"DisplayElement%li",Index); WritePrivateProfileString("vdmperf",TempName,TempStr,"vdmperf.ini"); } wsprintf(TempStr,"%li",pVdmperfInfo->DisplayMode); WritePrivateProfileString("vdmperf","DisplayMode",TempStr,"vdmperf.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