setdrw.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 12k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. /****************************************************************************
  4.     FUNCTION: MakeRect 
  5.     PURPOSE:  Fill in RECT structure given contents. 
  6. ****************************************************************************/
  7. VOID MakeRect( PRECT pRect, INT xmin, INT ymin, INT xmax, INT ymax )
  8. {
  9.     pRect->left= xmin;
  10.     pRect->right= xmax;
  11.     pRect->bottom= ymin;
  12.     pRect->top= ymax;
  13. }
  14. // type constants for DrawArrow
  15. #define AW_TOP      1   // top
  16. #define AW_BOTTOM   2   // bottom
  17. #define AW_LEFT     3   // left
  18. #define AW_RIGHT    4   // right
  19. /****************************************************************************
  20.     FUNCTION: DrawArrow 
  21.     PURPOSE:  Draw one arrow in a given color. 
  22. ****************************************************************************/
  23. static
  24. VOID DrawArrow( HDC hDC, INT type, INT xPos, INT yPos, COLORREF crPenColor )
  25. {
  26.     INT shaftlen=30;         // length of arrow shaft
  27.     INT headlen=15;          // height or width of arrow head (not length)
  28.     HPEN hPen, hPrevPen = NULL;   // pens
  29.     INT x,y;
  30.     INT xdir, ydir;          // directions of x and y (1,-1)
  31.     hPen= CreatePen( PS_SOLID, 1, crPenColor );
  32.     if( hPen )
  33.         hPrevPen= SelectObject( hDC, hPen );
  34.     MoveToEx( hDC, xPos, yPos, NULL );
  35.     xdir= ydir= 1;   // defaults
  36.     switch( type )
  37.     {
  38.         case AW_BOTTOM:
  39.             ydir= -1;
  40.         case AW_TOP:
  41.             LineTo(hDC, xPos, yPos+ydir*shaftlen);
  42.             for( x=0; x<3; x++ )
  43.             {
  44.                 MoveToEx( hDC, xPos,             yPos+ydir*x, NULL );
  45.                 LineTo(   hDC, xPos-(headlen-x), yPos+ydir*headlen );
  46.                 MoveToEx( hDC, xPos,             yPos+ydir*x, NULL );
  47.                 LineTo(   hDC, xPos+(headlen-x), yPos+ydir*headlen );
  48.             }
  49.             break;
  50.         case AW_RIGHT:
  51.             xdir= -1;
  52.         case AW_LEFT:
  53.             LineTo( hDC, xPos + xdir*shaftlen, yPos );
  54.             for( y=0; y<3; y++ )
  55.             {
  56.                 MoveToEx( hDC, xPos + xdir*y, yPos, NULL );
  57.                 LineTo(   hDC, xPos + xdir*headlen, yPos+(headlen-y));
  58.                 MoveToEx( hDC, xPos + xdir*y, yPos, NULL );
  59.                 LineTo(   hDC, xPos + xdir*headlen, yPos-(headlen-y));
  60.             }
  61.             break;
  62.     }
  63.     if( hPrevPen )
  64.         SelectObject( hDC, hPrevPen );
  65.     if (hPen)
  66.         DeleteObject(hPen);
  67. }
  68. /****************************************************************************
  69.     FUNCTION: LabelRect 
  70.     PURPOSE:  Label a rectangle with centered text given resource ID.
  71. ****************************************************************************/
  72. static
  73. VOID LabelRect(HDC hDC, PRECT pRect, UINT idString )
  74. {
  75.     UINT iStatus;
  76.     INT xStart, yStart;
  77.     SIZE Size;              // for size of string
  78.     TCHAR szMsg[CCH_MAX_STRING];
  79.     if( idString == 0 )     // make it easy to ignore call
  80.         return;
  81.     SetBkMode( hDC, OPAQUE );
  82.     SetBkColor( hDC, RGB(0,0,0) );
  83.     SetTextColor( hDC, RGB(255,255,255) );
  84.     // center
  85.     xStart= (pRect->left+pRect->right) /2;
  86.     yStart= (pRect->top+pRect->bottom) /2;
  87.     iStatus= LoadString( hInstance, idString, szMsg, sizeof(szMsg) );
  88.     if( !iStatus )
  89.     {
  90.         return;      // can't find string - print nothing
  91.     }
  92.     GetTextExtentPoint32( hDC, szMsg, lstrlen(szMsg), &Size );
  93.     TextOut( hDC, xStart-Size.cx/2, yStart-Size.cy/2, szMsg, lstrlen(szMsg) );
  94. }
  95. /****************************************************************************
  96.     FUNCTION: PaintRect 
  97.     PURPOSE:  Color in a rectangle and label it. 
  98. ****************************************************************************/
  99. static
  100. VOID PaintRect(
  101. HDC hDC,         // DC to paint 
  102. INT lowx,        // coordinates describing rectangle to fill 
  103. INT lowy,        //  
  104. INT highx,       // 
  105. INT highy,       // 
  106. COLORREF rgb,    // color to fill in rectangle with 
  107. UINT idString )  // resource ID to use to label or 0 is none
  108. {
  109.     RECT rct;
  110.     HBRUSH hBrush;
  111.     MakeRect( &rct, lowx, lowy, highx, highy );
  112.     hBrush= CreateSolidBrush( rgb );
  113.     FillRect( hDC, &rct, hBrush );
  114.     DeleteObject( hBrush );
  115.     LabelRect( hDC, &rct, idString ); 
  116. }
  117. /****************************************************************************
  118.     FUNCTION: DrawArrows 
  119.     PURPOSE:  Draw all the arrows showing edges of resolution.
  120. ****************************************************************************/
  121. VOID DrawArrows( HDC hDC, INT xRes, INT yRes )
  122. {
  123.     INT dx,dy;
  124.     INT x,y;
  125.     COLORREF color= RGB(0,0,0);    // color of arrow
  126.     dx= xRes/8;
  127.     dy= yRes/8;
  128.     for( x=0; x<xRes; x += dx )
  129.     {
  130.         DrawArrow( hDC, AW_TOP,    dx/2+x,   0,      color ); 
  131.         DrawArrow( hDC, AW_BOTTOM, dx/2+x,   yRes-1, color );
  132.     }
  133.     for( y=0; y<yRes; y += dy )
  134.     {
  135.         DrawArrow( hDC, AW_LEFT,       0, dy/2+y,   color  ); 
  136.         DrawArrow( hDC, AW_RIGHT, xRes-1, dy/2+y,   color );
  137.     }
  138. }
  139. /****************************************************************************
  140.     FUNCTION: LabelResolution 
  141.     PURPOSE:  Labels the resolution in a form a user may understand.
  142.               bugbug: We could label vertically too. 
  143. ****************************************************************************/
  144. VOID LabelResolution( HDC hDC, INT xmin, INT ymin, INT xmax, INT ymax )
  145. {
  146.    TCHAR szRes[120];    // text for resolution
  147.    TCHAR szFmt[CCH_MAX_STRING];    // format string
  148.    SIZE  Size;
  149.    INT iStatus;
  150.    iStatus= LoadString( hInstance, IDS_RESOLUTION_FMT, szFmt, sizeof(szFmt) );
  151.    if( !iStatus || iStatus==sizeof(szFmt) )
  152.    { 
  153.        lstrcpy(szFmt,TEXT("%d x %d"));   // make sure we get something
  154.    }
  155.    wsprintf( szRes, szFmt, xmax, ymax );
  156.    SetBkMode( hDC, TRANSPARENT );
  157.    SetTextColor( hDC, RGB(0,0,0) );
  158.    GetTextExtentPoint32( hDC, szRes, lstrlen(szRes), &Size );
  159.    // Text near bottom of screen ~10 pixels from bottom
  160.    TextOut( hDC, xmax/2 - Size.cx/2, ymax - 10-Size.cy, szRes, lstrlen(szRes) );
  161. // table of resolutions that we show off.
  162. // if the resolution is larger, then we show that one too.
  163. typedef struct tagRESTAB {
  164.     INT xRes;
  165.     INT yRes;
  166.     COLORREF crColor;           // color to paint this resolution
  167. } RESTAB;
  168. RESTAB ResTab[] ={
  169.    { 1600, 1200, RGB(255,0,0)},
  170.    { 1280, 1024, RGB(0,255,0)},
  171.    { 1152,  900, RGB(0,0,255)},
  172.    { 1024,  768, RGB(255,0,0)},
  173.    {  800,  600, RGB(0,255,0)},
  174.    // 640x480 or 640x400 handled specially
  175.    { 0, 0, 0}         // end of table
  176.    };
  177. /****************************************************************************
  178.     FUNCTION: Set1152Mode
  179.     PURPOSE:  Set the height of the 1152 mode since it varies from card to
  180.               card.
  181. ****************************************************************************/
  182. VOID Set1152Mode(int height)
  183. {
  184.     ResTab[2].yRes = height;
  185. }
  186. /****************************************************************************
  187.     FUNCTION: DrawBmp
  188.     PURPOSE:  Show off a fancy screen so the user has some idea
  189.               of what will be seen given this resolution, colour
  190.               depth and vertical refresh rate.  Note that we do not
  191.               try to simulate the font sizes.  
  192. ****************************************************************************/
  193. VOID DrawBmp( HDC hDC )
  194. {
  195.     INT    nBpp;          // bits per pixel
  196.     INT    nWidth;        // width of screen in pixels
  197.     INT    nHeight;       // height of screen in pixels
  198.     INT    xUsed,yUsed;   // amount of x and y to use for dense bitmap
  199.     INT    dx,dy;         // delta x and y for color bars
  200.     RECT   rct;           // rectangle for passing bounds
  201.     HFONT  hPrevFont=0;   // previous font in DC
  202. //    HFONT  hFont;         // stock font for logfont
  203.     HFONT  hNewFont;      // new font if possible
  204. //    LOGFONT lf;           // for creating new font
  205.     HPEN   hPrevPen;      // previous pen handle
  206.     INT    x,y,i;
  207.     INT    off;           // offset in dx units
  208.     // try to use bigger better looking font
  209.     //hFont= GetStockObject( DEVICE_DEFAULT_FONT );
  210.     //GetObject( hFont, sizeof(LOGFONT), &lf );
  211.     //lf.lfHeight= 30;
  212.     //hNewFont= CreateFontIndirect( &lf );
  213.     hNewFont = (HFONT)NULL;
  214.     if( hNewFont )                              // if no font, use old
  215.         hPrevFont= SelectObject( hDC, hNewFont );
  216.     // get surface information
  217.     nBpp= GetDeviceCaps( hDC, BITSPIXEL ) * GetDeviceCaps( hDC, PLANES );
  218.     nWidth= GetDeviceCaps( hDC, HORZRES );
  219.     nHeight= GetDeviceCaps( hDC, VERTRES );
  220.     // background for everything is yellow.
  221.     PaintRect( hDC, 0,0,nWidth, nHeight, RGB(255,255,0),0 );
  222.     LabelResolution( hDC, 0,0,nWidth, nHeight );
  223.     // Background for various resolutions
  224.     // biggest ones first
  225.     for( i=0; ResTab[i].xRes !=0; i++ )
  226.     {
  227.         // Only draw if it will show
  228.         if( ( nWidth>=ResTab[i].xRes ) | ( nHeight>=ResTab[i].yRes ) )
  229.         {
  230.            PaintRect(hDC,0,0,ResTab[i].xRes,ResTab[i].yRes,ResTab[i].crColor,0);
  231.            LabelResolution( hDC, 0, 0, ResTab[i].xRes, ResTab[i].yRes);
  232.         }
  233.     }
  234.     // color bars - only in standard vga area 
  235.     xUsed= min( nWidth, 640 );    // only use vga width
  236.     yUsed= min( nHeight, 480 );   // could be 400 on some boards
  237.     dx= xUsed/2;
  238.     dy= yUsed/6;
  239.     PaintRect( hDC, 0,   0, dx, dy*1,  RGB(255,0,0),   IDS_COLOR_RED );
  240.     PaintRect( hDC, 0,dy*1, dx, dy*2,  RGB(0,255,0),   IDS_COLOR_GREEN );
  241.     PaintRect( hDC, 0,dy*2, dx, dy*3,  RGB(0,0,255),   IDS_COLOR_BLUE );
  242.     PaintRect( hDC, 0,dy*3, dx, dy*4,  RGB(255,255,0 ),IDS_COLOR_YELLOW );
  243.     PaintRect( hDC, 0,dy*4, dx, dy*5,  RGB(255,0,255), IDS_COLOR_MAGENTA  );
  244.     PaintRect( hDC, 0,dy*5, dx, yUsed, RGB(0,255,255), IDS_COLOR_CYAN  );
  245.     // gradations of colors for true color detection
  246.     for( x=dx; x<xUsed; x++ )
  247.     {
  248.         INT level;
  249.         level= 255- ( 256*(x-dx) ) / dx;
  250.         PaintRect( hDC, x, dy*0, x+1,  dy*1, RGB( level,0,0 ),0 );
  251.         PaintRect( hDC, x, dy*1, x+1,  dy*2, RGB( 0,level,0 ),0 );
  252.         PaintRect( hDC, x, dy*2, x+1,  dy*3, RGB( 0,0,level ),0 );
  253.         PaintRect( hDC, x, dy*5, x+1,  dy*6, RGB( level,level,level), 0 );
  254.     }
  255.     MakeRect( &rct, dx,0,dx*2,dy*1 );
  256.     LabelRect( hDC, &rct, IDS_RED_SHADES );
  257.     MakeRect( &rct, dx,dy,dx*2,dy*2);
  258.     LabelRect( hDC, &rct, IDS_GREEN_SHADES );
  259.     MakeRect( &rct, dx,2*dy,dx*2,dy*3);
  260.     LabelRect( hDC, &rct, IDS_BLUE_SHADES );
  261.     MakeRect( &rct, dx,5*dy,dx*2,dy*6);
  262.     LabelRect( hDC, &rct, IDS_GRAY_SHADES );
  263.     // horizontal lines for interlace detection
  264.     off= 3;
  265.     PaintRect(hDC, dx,dy*off, xUsed, dy*(off+1),RGB(255,255,255),0 );// white
  266.     hPrevPen= SelectObject( hDC, GetStockObject(BLACK_PEN) );
  267.     for( y=dy*off; y<dy*(off+1); y= y+2 )
  268.     {
  269.         MoveToEx( hDC, dx,   y, NULL );
  270.         LineTo(   hDC, dx*2, y );
  271.     }
  272.     SelectObject( hDC, hPrevPen );
  273.     MakeRect( &rct, dx, dy*off, dx*2, dy*(off+1) );
  274.     LabelRect( hDC, &rct, IDS_PATTERN_HORZ );
  275.     // vertical lines for bad dac detection
  276.     off= 4;
  277.     PaintRect(hDC, dx,dy*off, xUsed,dy*(off+1), RGB(255,255,255),0 );  // white
  278.     hPrevPen= SelectObject( hDC, GetStockObject(BLACK_PEN) );
  279.     for( x=dx; x<xUsed; x= x+2 )
  280.     {
  281.         MoveToEx( hDC, x, dy*off, NULL );
  282.         LineTo(   hDC, x, dy*(off+1) );
  283.     }
  284.     SelectObject( hDC, hPrevPen );
  285.     MakeRect( &rct, dx, dy*off, dx*2, dy*(off+1) );
  286.     LabelRect( hDC, &rct, IDS_PATTERN_VERT );
  287.     DrawArrows( hDC, nWidth, nHeight ); 
  288.     LabelResolution(hDC, 0,0, xUsed, yUsed );
  289.     // delete created font if one was created
  290.     if( hPrevFont )
  291.     {
  292.         hPrevFont= SelectObject( hDC, hPrevFont );
  293.         DeleteObject( hPrevFont );
  294.     }
  295. }