home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 1999 October / PCpro_1999_10.ISO / Tools / wingrep / Source / Editor.cpp next >
Encoding:
C/C++ Source or Header  |  1998-06-01  |  4.6 KB  |  150 lines

  1. #include <windows.h>
  2.  
  3.  
  4. char HexDigit[16]={'0','1','2','3',
  5.                    '4','5','6','7',
  6.                    '8','9','A','B',
  7.                    'C','D','E','F' };
  8.  
  9. LRESULT WINAPI GrepView( HWND hWnd, UINT wMsg, WPARAM wp, LPARAM lp )
  10. {
  11.   switch( wMsg )
  12.   {
  13.     case WM_PAINT:
  14.     {
  15.       PAINTSTRUCT ps;
  16.       HDC hDC;
  17.       RECT r, rOut;
  18.       char szOutPuffer[2048];
  19.       int iElementsPerRow;
  20.       HFONT hPrintFont, hOldFont;
  21.       POINT px;
  22.       char iVal;
  23.       int i,j;
  24.       SIZE s;
  25.  
  26.       hDC = BeginPaint( hWnd, &ps );
  27.  
  28.       hPrintFont = CreateFont( -MulDiv( 10, GetDeviceCaps( hDC, LOGPIXELSY ), 72L ),
  29.                          0,                      // logical average character width
  30.                          0,                      // angle of escapement
  31.                          0,                      // base-line orientation angle
  32.                          FW_NORMAL,              // font weight
  33.                          FALSE,                  // italic attribute flag
  34.                          FALSE,                  // underline attribute flag
  35.                          FALSE,                  // strikeout attribute flag
  36.                          ANSI_CHARSET,           // character set identifier
  37.                          OUT_DEFAULT_PRECIS,     // output precision
  38.                          CLIP_DEFAULT_PRECIS,    // clipping precision
  39.                          DEFAULT_QUALITY,        // output quality
  40.                          FF_MODERN,              // pitch and family
  41.                          "Courier New"           // pointer to typeface name string
  42.                       );
  43.       hOldFont = SelectObject( hDC, hPrintFont );
  44.       GetClientRect( hWnd, &r );
  45.  
  46.       rOut = r;
  47.       // Anzahl der Elemente pro Zeile
  48.       
  49.       GetTextExtentPoint( hDC, "  ", 2, &s );
  50.       // Zwei Spaces als Trenner
  51.       iElementsPerRow = (r.right - r.left) - s.cx;
  52.       // Jedes Element ben÷tigt mindestens eine Hex-DIgit und eine Ascii-Digit
  53.       
  54.       GetTextExtentPoint( hDC, "00 a", 2, &s );
  55.       if( s.cx )
  56.         iElementsPerRow /= s.cx;
  57.       else
  58.         iElementsPerRow = 1;
  59.  
  60.       do
  61.       {
  62.         j=0;
  63.         iVal = 'a';
  64.         for( i = 0; i < iElementsPerRow; i++ ) // MaxCount
  65.         {
  66.           szOutPuffer[j++]= HexDigit[(iVal>>4)];
  67.           szOutPuffer[j++]= HexDigit[(iVal&0x0F)];
  68.           szOutPuffer[j++]= ' ';
  69.           iVal++;
  70.         }
  71.         for( ; i < iElementsPerRow; i++ ) // MaxCount
  72.         {
  73.           szOutPuffer[j++]= ' ';
  74.           szOutPuffer[j++]= ' ';
  75.           szOutPuffer[j++]= ' ';
  76.         }
  77.         szOutPuffer[j++]= ' ';
  78.  
  79.         // Zeichen Ausgeben
  80.         for( i = 0; i < iElementsPerRow; i++ ) // MaxCount
  81.         {
  82.           if( isalpha( iVal ) || isdigit( iVal ) )
  83.           {
  84.             szOutPuffer[j++] = iVal;
  85.             iVal++;
  86.           }
  87.           else
  88.             szOutPuffer[j++] = '+';
  89.         }
  90.         for( ; i < iElementsPerRow; i++ ) // MaxCount
  91.         {
  92.           szOutPuffer[j++]= ' ';
  93.         }
  94.  
  95.         GetTextExtentPoint( hDC, " ", 1, &s );
  96.         if( !s.cy ) s.cy = 1;
  97.  
  98.         rOut.bottom = rOut.top + s.cy;
  99.         ExtTextOut( hDC, rOut.left, rOut.top, ETO_OPAQUE, &rOut, szOutPuffer, j, NULL );
  100.         rOut.top = rOut.bottom;
  101.       } 
  102.       while( rOut.top < r.bottom );
  103.       SelectObject( hDC, hOldFont );
  104.  
  105.       DeleteObject( hPrintFont );
  106.       EndPaint( hWnd, &ps );
  107.     }
  108.     break;
  109.   }
  110.   return DefWindowProc( hWnd, wMsg, wp, lp );
  111. }
  112.  
  113. BOOL RegisterViewer( HINSTANCE hInst )
  114. {
  115.   WNDCLASSEX wc;
  116.   wc.cbSize = sizeof(wc); 
  117.   wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW; 
  118.   wc.lpfnWndProc = GrepView; 
  119.   wc.cbClsExtra = 0; 
  120.   wc.cbWndExtra = sizeof( HANDLE);  // Platz fⁿr Dateihandle
  121.   wc.hInstance = hInst; 
  122.   wc.hIcon = NULL; 
  123.   wc.hCursor = NULL; 
  124.   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 
  125.   wc.lpszMenuName = NULL; //(LPSTR)MAKEINTRESOURCE(IDR_MAINMENU);
  126.   wc.lpszClassName = "VIEW"; 
  127.   wc.hIconSm = NULL; 
  128.   return RegisterClassEx( &wc );
  129. }
  130.  
  131. BOOL UnregisterViewer( HINSTANCE hInst )
  132. {
  133.   return UnregisterClass( "VIEW", hInst );
  134. }
  135.  
  136. BOOL CreateWindows( HINSTANCE hInst, HWND *hwndView, LPSTR lpFileName )
  137. {
  138.   *hwndView = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE,
  139.                               "VIEW",
  140.                               "Window",
  141.                               WS_THICKFRAME|WS_CAPTION|WS_SYSMENU,
  142.                               200,0,600,600,
  143.                               NULL,
  144.                               NULL,
  145.                               hInst,
  146.                               lpFileName );
  147.   if( *hwndView ) return TRUE;
  148.   return FALSE;
  149. }
  150.