home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / blx21.zip / OV2DLL.ARJ / SUPERC.C < prev    next >
C/C++ Source or Header  |  1992-04-11  |  4KB  |  144 lines

  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.   FARPROC lpOldWindowProc;
  6.   HWND HWin;
  7.   WNDCLASS MyWndClass;
  8.   HWND Wnd;
  9.   char ChildWin[50];
  10.   HWND ChildWinH;
  11.   FARPROC EnumFunc;
  12.   HANDLE LibInst;
  13.   HBITMAP hBitmp;
  14.   BITMAP Bitmp;
  15.  
  16. #pragma argsused
  17. int FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSegment,
  18.             WORD wHeapSize, LPSTR lpszCmdLine )
  19. {
  20.     // The startup code for the DLL initializes the local heap (if
  21.     // there is one) with a call to LocalInit which locks the data
  22.     // segment.
  23.     if ( wHeapSize != 0 )
  24.     UnlockData( 0 );
  25.     LibInst = hInstance;
  26.     return 1;   // Indicate that the DLL was initialized successfully.
  27. }
  28.  
  29. #pragma argsused
  30. int FAR PASCAL WEP ( int bSystemExit )
  31. {
  32.   return 1;
  33. }
  34.  
  35. DWORD FAR PASCAL _export WndProc( HWND rWin, WORD Message, WORD wParam, DWORD lParam )
  36. {
  37.   PAINTSTRUCT PS;
  38.   char s[20];
  39.   HDC MemDC;
  40.   RECT R;
  41.   DWORD LPos;
  42.   HDC DC, MemHDC;
  43.  
  44.  switch ( Message ) {
  45.    case WM_PAINT:
  46.      {
  47.      DC = BeginPaint( rWin, &PS );
  48.      MemHDC = CreateCompatibleDC( DC );
  49.      SelectObject( MemHDC,hBitmp );
  50.      GetObject(hBitmp, sizeof( Bitmp ), ( LPSTR ) &Bitmp );
  51.      GetClientRect( rWin, &R );
  52.      StretchBlt( DC, 0, 0, R.right, R.bottom, MemHDC, 0,0,
  53.      Bitmp.bmWidth, Bitmp.bmHeight, SRCCOPY );
  54.      ReleaseDC( rWin, DC );
  55.      DeleteDC( MemHDC );
  56.      EndPaint( rWin, &PS );
  57.      }
  58.  }
  59.  return DefWindowProc( rWin, Message, wParam, lParam );
  60. }
  61.  
  62. void RegisterMyClass()
  63. {
  64.   MyWndClass.style = CS_HREDRAW | CS_VREDRAW;
  65.   MyWndClass.lpfnWndProc = WndProc;
  66.   MyWndClass.cbClsExtra = 0;
  67.   MyWndClass.cbWndExtra = 0;
  68.   MyWndClass.hInstance = LibInst;
  69.   MyWndClass.hIcon = LoadIcon( 0, IDI_APPLICATION );
  70.   MyWndClass.hCursor = LoadCursor( 0, IDC_ARROW );
  71.   MyWndClass.hbrBackground = GetStockObject( WHITE_BRUSH );
  72.   MyWndClass.lpszMenuName = NULL;
  73.   MyWndClass.lpszClassName = "MyWindowClass";
  74.   RegisterClass( &MyWndClass );
  75. }
  76.  
  77. #pragma argsused
  78. DWORD FAR PASCAL _export NewWinProc( HWND rWin, WORD wMsg, WORD wParam, DWORD lParam )
  79. {
  80.   RECT R;
  81.   HDC DC;
  82.   DWORD LPos;
  83.  
  84.  switch ( wMsg ) {
  85.    case WM_COMMAND:
  86.      {
  87.        if ( wParam == 7 )
  88.        {
  89.      RegisterMyClass();
  90.      GetClientRect( ChildWinH, &R );
  91.      DC = GetDC( ChildWinH );
  92.      LPos = GetDCOrg( DC );
  93.      Wnd = CreateWindow( "MyWindowClass", "Client", WS_OVERLAPPED,
  94.         LOWORD(LPos), HIWORD(LPos), R.right, R.bottom,
  95.         HWin, 0, LibInst, NULL );
  96.      ShowWindow( Wnd, SW_SHOWNORMAL );
  97.      UpdateWindow( Wnd );
  98.      ReleaseDC( ChildWinH, DC );
  99.      SetFocus( Wnd );
  100.      return 1;
  101.        }
  102.      }
  103.    case WM_CLOSE:
  104.      {
  105.       DestroyWindow( Wnd );
  106.       SetWindowLong( HWin, GWL_WNDPROC, (DWORD) lpOldWindowProc );
  107.       DefWindowProc( HWin, wMsg, wParam, lParam );
  108.      }
  109.    }
  110.     return  CallWindowProc( lpOldWindowProc, rWin, wMsg, wParam, lParam );
  111. }
  112.  
  113. #pragma argsused
  114. BOOL FAR PASCAL _export EnumWinFunc( HWND hWindow, DWORD Continue )
  115. {
  116.   char PCH[50];
  117.  
  118.   if ( hWindow != 0 )
  119.   {
  120.     GetWindowText( hWindow, PCH, GetWindowTextLength( hWindow ) + 1 );
  121.     if ( _fstrstr(PCH, ChildWin) != NULL )
  122.     {
  123.       ChildWinH = hWindow;
  124.       return 0;
  125.     }
  126.     else
  127.       return 1;
  128.   }
  129.   else
  130.     return 1;
  131. }
  132.  
  133. int FAR PASCAL _export ReplaceProc ( HANDLE hInst, HWND hWindow, LPSTR Child )
  134. {
  135.   hBitmp = LoadBitmap( LibInst, "RACECAR" );
  136.   HWin = hWindow;
  137.   strcpy( ChildWin, Child );
  138.   EnumFunc = MakeProcInstance( EnumWinFunc, hInst );
  139.   EnumChildWindows( HWin, EnumFunc, 0 );
  140.   lpOldWindowProc = (FARPROC) SetWindowLong( HWin, GWL_WNDPROC, (DWORD) NewWinProc );
  141.   return 1;
  142. }
  143.  
  144.