showinfo.c
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:31k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. /*********************************************************************
  2.  * Microsoft Diagnostics Version 2.0
  3.  *
  4.  * A diagnostic utility to detect as much useful information about a
  5.  *   customer's computer system as is possible.
  6.  *
  7.  * Microsoft Diagnostics:  We detect the World.
  8.  *
  9.  * SHOWINFO.C - Source file for displaying information
  10.  ********************************************************************/
  11. /* Include Files */
  12. #include "msd.h"
  13. #ifdef CW_INCLUDED
  14. /********************************************************************
  15.  * ShowInfo - Displays the appropriate record in the info window.
  16.  *
  17.  * wRecordType - Record to display
  18.  *
  19.  * Returns: PWND of the info window, NULL if an error condition
  20.  *          occured.
  21.  ********************************************************************/
  22. PWND ShowInfo (WORD wRecordType)
  23. {
  24.   VOID *pStructForInfo = NULL;  /* Pointer to structure with data   */
  25.   WORD wStructSize;             /* Stores memory requirements for   */
  26.                                 /*   GetInfo record                 */
  27.   QSZ  *pqszStrings;            /* Array of strings to print        */
  28.   BOOL fReturnValue;            /* Stores return value from GetInfo */
  29.   PWND pwndInfo = NULL;         /* Info Window's PWND               */
  30.   /* Determine the memory required to store the record */
  31.   wStructSize = GetInfoSize (wRecordType, 0);
  32.   if (wStructSize == 0)
  33.     {
  34. #if HEAP_DEBUG
  35.       CHAR chBuff1[80];   /* String for error message */
  36.       sprintf (chBuff1, "%s, line %dn", __FILE__, __LINE__);
  37.       ShowError (MB_BEEP | MB_OK | 0x8000, "Invalid Record Type", "", "");
  38. #endif
  39.       return (NULL);
  40.     }
  41.   /* Allocate memory for the structure */
  42.   pStructForInfo = malloc (wStructSize);
  43. #if HEAP_DEBUG
  44.   HeapCheck ("In ShowInfo, After malloc (wStructSize)");
  45. #endif
  46.   if (pStructForInfo == NULL)
  47.     {
  48.       OutOfMemory();
  49.       return (NULL);
  50.     }
  51.   /* Zero out the structure */
  52.   memset (pStructForInfo, '', wStructSize);
  53.   /* If /I was used, set the flag stating that this information */
  54.   /*   is now available for reporting.                          */
  55.   rgfReportItemFlag[wRecordType] = TRUE;
  56.   rgfReportItemFlag[IDI_SUMMARY_SCREEN] = TRUE;
  57.   /* Fill it with the GetInfo data */
  58.   fReturnValue = GetInfo (wRecordType,
  59.                           pStructForInfo,
  60.                           FALSE,    /* Do not obtain minimum info */
  61.                           FALSE,    /* No include header record   */
  62.                           TRUE);    /* We are doing a report      */
  63. #if HEAP_DEBUG
  64.   HeapCheck ("In ShowInfo, After GetInfo()");
  65. #endif
  66.   if (fReturnValue)
  67.     {
  68.       free (pStructForInfo);
  69.       return (NULL);
  70.     }
  71.   /* Get the information into displayable strings */
  72.   pqszStrings = SprintInfo (wRecordType,
  73.                             pStructForInfo,
  74.                             NULL,
  75.                             FALSE);  /* We are not doing a report */
  76. #if HEAP_DEBUG
  77.   HeapCheck ("In ShowInfo, After SprintInfo()");
  78. #endif
  79.   /* Update the summary strings */
  80.   SprintInfo (wRecordType, pStructForInfo,
  81.               &(pSum->szSumStrings[wRecordType * 2]), TRUE);
  82. #if HEAP_DEBUG
  83.   HeapCheck ("In ShowInfo, After update of summary strings");
  84. #endif
  85.   /* PostMessage (pwndMainFrame, WM_PAINT, NULL, NULL); */
  86.   /* Display the strings in the window */
  87.   if (pqszStrings != NULL)
  88.     pwndInfo = CreateInfoWnd (paszButtonNames[wRecordType],
  89.                               pqszStrings,
  90.                               FALSE);
  91. #if HEAP_DEBUG
  92.   HeapCheck ("In ShowInfo, After CreateInfoWnd()");
  93. #endif
  94.   free (pStructForInfo);
  95. #if HEAP_DEBUG
  96.   HeapCheck ("In ShowInfo, After free (pStructForInfo)");
  97. #endif
  98.   return (pwndInfo);
  99. }
  100. BOOL fVisibleFlag;            /* Set if scroll bar should be visible    */
  101. /*********************************************************************
  102.  * CreateInfoWnd - Procedure to create the info provider window.
  103.  *
  104.  * pwndParent     - Parent window for this window.
  105.  * pszWindowTitle - Title for the info window.
  106.  * pqszStrings    - Strings to be displayed in the info window.
  107.  * fKeepFocus     - TRUE if this window should keep the focus.
  108.  *
  109.  * Returns:  PWND if creating Info Window was successful, NULL if an
  110.  *           error occured.
  111.  *********************************************************************/
  112. STATIC PWND CreateInfoWnd (PSZ  pszWindowTitle,
  113.                            QSZ  *pqszStrings,
  114.                            BOOL fKeepFocus)
  115. {
  116.   PWND pwndInfoFrame = NULL;  /* Handle to the info window's frame      */
  117.   PWND pwndInfoTxt = NULL;    /* Text window handle                     */
  118.   PWND pwndScrollBar = NULL;  /* Handle to the scroll bar               */
  119.   WORD wNmbrLines;            /* Number of lines in this string array   */
  120.   WORD wLongestLine = 0;      /* The length of the longest line         */
  121.   WORD wLength;               /* The length of the current line         */
  122.   AX   axRight;               /* Coordinates for the upper left corner  */
  123.   AY   ayTop;                 /*   of the info window.                  */
  124.   AX   axWidth;               /* Size of the info window                */
  125.   AY   ayHeight;
  126.   PSZ  pszNewWindowTitle;     /* New location (malloc'ed) for the title */
  127.   /* Determine the number of lines and the length of the longest line */
  128.   for (wNmbrLines = 0; pqszStrings[wNmbrLines] != NULL; ++wNmbrLines)
  129.     {
  130.       if ((wLength = DisplayLen (pqszStrings[wNmbrLines])) > wLongestLine)
  131.         wLongestLine = wLength;
  132.     }
  133.   /* Calculate the size of the window */
  134.   if (wNmbrLines > (WORD) ayMac - 7)
  135.     {
  136.       ayHeight = ayMac - (AY) 2;
  137.       axWidth  = (wLongestLine + 5> (WORD) axMac - 6) ?
  138.                  axMac - (AX) 2 : (AX) wLongestLine + (AX) 5;
  139.       fVisibleFlag = TRUE;
  140.     }
  141.   else
  142.     {
  143.       ayHeight = (AY) wNmbrLines + (AY) 5;
  144.       axWidth  = (wLongestLine + 4> (WORD) axMac - 6) ?
  145.                  axMac - (AX) 2 : (AX) wLongestLine + (AX) 4;
  146.       fVisibleFlag = FALSE;
  147.     }
  148.   /* Calculate the coordinates of the info window */
  149.   axRight = (AX) ((axMac / 2) - (axWidth / 2));
  150.   ayTop   = (AY) ((ayMac / 2) - (ayHeight / 2));
  151.   /* Copy the window title */
  152.   pszNewWindowTitle = malloc (strlen (pszWindowTitle) + 1);
  153.   if (pszNewWindowTitle == NULL)
  154.     return (NULL);
  155.   strcpy (pszNewWindowTitle, pszWindowTitle);
  156.   /* Create the window */
  157.   pwndInfoFrame = (PWND) CreateWindow (InfoWndCallID,
  158.                                        NULL,
  159.                                        WS_CLIPOUT | WS_BORDER |
  160.                                          WS_OVERLAP /* | WS_VSCROLL */ ,
  161.                                        WS_FRAME | WES_SHADOW |
  162.                                          WES_OWNERREDRAW,
  163.                                        axRight,
  164.                                        ayTop,
  165.                                        axWidth,
  166.                                        ayHeight,
  167.                                        (HWND) pwndMainFrame,
  168.                                        (HMENU) NULL,
  169.                                        NULL,
  170.                                        1);
  171.   if (pwndInfoFrame == NULL)
  172.     return (NULL);
  173.   /* Get the Info Text window's window handle */
  174.   pwndInfoTxt = GetDlgItem (pwndInfoFrame, InfoTxtID);
  175.   /* Set the pointer to the button's name */
  176.   SetWindowWord (pwndInfoFrame, WEB_WINDOW_TITLE, (WORD) pszNewWindowTitle);
  177.   /* Set the scroll bar's minimum value in the extra bytes */
  178.   SetWindowWord (pwndInfoTxt, WEB_MIN_SCROLL, 0);
  179.   /* Set the scroll bar's maximum value in the extra bytes */
  180.   SetWindowWord (pwndInfoTxt, WEB_MAX_SCROLL, wNmbrLines - (ayHeight - 5));
  181.   /* Set the total number of lines in this string array */
  182.   SetWindowWord (pwndInfoTxt, WEB_NMBR_LINES, wNmbrLines);
  183.   /* Set the number of scrollable lines in the window */
  184.   SetWindowWord (pwndInfoTxt, WEB_SCROLLABLE_LINES, (WORD) ayHeight - 5);
  185.   /* Set the pointer to the text to display */
  186.   SetWindowWord (pwndInfoTxt, WEB_PQSZ_TEXT, (WORD) pqszStrings);
  187.   /* Set the flag on wether this window should keep the focus or not */
  188.   SetWindowWord (pwndInfoTxt, WEB_KEEP_FOCUS, (WORD) fKeepFocus);
  189.   /* Set the ranges for the scroll bar */
  190.   pwndScrollBar = GetDlgItem (pwndInfoTxt, InfoScrollID);
  191.   SetScrollRange (pwndScrollBar,                /* Handle to scroll bar */
  192.                   0,                            /* Minimum scroll value */
  193.                   wNmbrLines - (ayHeight - 5),  /* Maximum scroll value */
  194.                   FALSE);                       /* Redraws when TRUE */
  195.   SetScrollPos (pwndScrollBar,     /* Handle to scroll bar */
  196.                 0,                 /* New scroll bar position */
  197.                 FALSE);            /* Redraws when TRUE */
  198.   EnableWindow (pwndInfoFrame, TRUE);
  199.   ShowWindow (pwndInfoFrame, SW_VISIBLE, TRUE);
  200.   /* Hide the scroll bar if it is not necessary */
  201.   if (fVisibleFlag == FALSE)
  202.     ShowWindow (pwndScrollBar, SW_INVISIBLE, TRUE);
  203.   /* Set the focus to the OK button */
  204.   SetFocus (pwndInfoFrame);
  205.   return (pwndInfoFrame);
  206. }
  207. /*********************************************************************
  208.  * InfoWndProc - Procedure for handling the "Information Provider"
  209.  *               window.
  210.  *********************************************************************/
  211. STATIC LONG FAR PASCAL InfoWndProc (PWND  pwnd,
  212.                                     WORD  message,
  213.                                     WORD  wParam,
  214.                                     DWORD lParam)
  215. {
  216.   switch (message)
  217.     {
  218.       case WM_CREATE:
  219.         CreateInfoChildWindows (pwnd);
  220.         break;
  221. #if 0
  222.       case WM_ACTIVATE:
  223.         {
  224.           PWND pwndInfoTxt = NULL;   /* Handle to the text window */
  225.           /* Get the window handles */
  226.           pwndInfoTxt   = GetDlgItem (pwnd, InfoTxtWndCallID);
  227.           if (GetWindowWord (pwndInfoTxt, WEB_KEEP_FOCUS))
  228.             return (rspActiveDecline);
  229.           else
  230.             return (rspActiveLive);
  231.           break;
  232.         }
  233. #endif
  234.       case WM_COMMAND:
  235.         /* Close window when OK button clicked */
  236.         if (HIWORD (lParam) == BN_CLICKED && wParam == OkButtonID)
  237.           PostMessage (pwnd, WM_CLOSE, NULL, NULL);
  238.         break;
  239.       case WM_CLOSE:
  240.         {
  241. #if HEAP_DEBUG
  242.           _heapset ('W');
  243. #endif
  244.           /* Free up the window title */
  245.           free ((PSZ) GetWindowWord (pwnd, WEB_WINDOW_TITLE));
  246. #if HEAP_DEBUG
  247.           _heapset ('X');
  248. #endif
  249.           /* Inform the summary window that we are shutting down */
  250.           SendMessage (pwnd->pwndParent, WM_INFO_WND_CLOSED, (WORD) pwnd,
  251.                        NULL);
  252.           /* Destroy this info window */
  253.           DestroyWindow (pwnd);
  254.           break;
  255.         }
  256.       case WM_FRAMEDRAW:
  257.         {
  258.           RRC rrc;  /* Relative rectangle of window */
  259.           GetClientRrc (pwnd, &rrc);
  260.           DrawBorderAlign (pwnd,
  261.                            pboxInfoBox,
  262.                            isaInfoActiveBorder,
  263.                            isaInfoActiveBorder,
  264.                            (PSZ) GetWindowWord (pwnd, WEB_WINDOW_TITLE),
  265.                            TRUE);
  266.           if (FIsTopWindow(pwnd))
  267.             DrawOverlapShadow (pwnd);
  268.           CharOutBorder (pwnd,
  269.                          0,
  270.                          (RY) (rrc.ryBottom - 2),
  271.                          '