#include <windows.h>

#ifdef WIN32
#define INTFUNC  __stdcall
#define EXPFUNC  __stdcall 
#else
#define INTFUNC PASCAL
#define EXPFUNC CALLBACK _export
#endif

HANDLE GModule;
BOOL drawRectangle;

#ifdef WIN32

BOOL WINAPI DllMain (HANDLE hInst, DWORD fdwReason, LPVOID lpReserved)
{
switch (fdwReason) 
  {
  case DLL_PROCESS_ATTACH:  // case of libentry call in win 3.x
    GModule = hInst;
    break;
    
  case DLL_THREAD_ATTACH:
    break;
    
  case DLL_PROCESS_DETACH:  // case of wep call in win 3.x
    break;
    
  case DLL_THREAD_DETACH:
    break;
    
  default:
    break;
  } /* switch */

return TRUE;                                                                
                                                                                
UNREFERENCED_PARAMETER(lpReserved);                                         
} /* LibMain */                                                                 

#else // if Win 3.x

/* ----------------
   | Library Main |
   ---------------- */
int FAR PASCAL EXPFUNC LibMain(HANDLE hModule, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine)
{
GModule = hModule;
return 1;
}

/* --------------------------
   | Windows exit procedure |
   -------------------------- */
int FAR PASCAL EXPFUNC WEP (bSystemExit)
int  bSystemExit;
{
return 1;
}
#endif


LRESULT CALLBACK EXPFUNC WndProc(
                        HWND  hwnd,	// handle of window
                        UINT  uMsg,	// message identifier
                        WPARAM  wParam,	// first message parameter
                        LPARAM  lParam 	// second message parameter
                        )
{
switch (uMsg) 
  { 
  case WM_PAINT: 
    {
    HDC hdc;
    PAINTSTRUCT ps; 
    RECT rc;

    GetClientRect(hwnd, &rc); 

      // Paint the window's client area. 
    hdc = BeginPaint(hwnd, &ps); 

    SelectObject(hdc, GetStockObject(BLACK_PEN));
    if (drawRectangle)
      Rectangle(hdc, rc.left + 10, rc.top + 10, rc.right - 10, rc.bottom - 10);
    else
      Ellipse(hdc, rc.left + 10, rc.top + 10, rc.right - 10, rc.bottom - 10);

    EndPaint(hwnd, &ps); 
    return 0; 
    }

  case WM_SIZE: 
    // Set the size and position of the window. 
    InvalidateRect(hwnd, NULL, TRUE);
    return 0; 

  case WM_DESTROY: 
    // Clean up window-specific data objects. 
    return 0; 

  // Process other messages. 

  default: 
    return DefWindowProc(hwnd, uMsg, wParam, lParam); 
  } 
return 0; 
}


BOOL FAR PASCAL EXPFUNC SetRectangle(HWND hwnd, BOOL nval)
{
  BOOL old = drawRectangle;
  drawRectangle = nval;
  InvalidateRect(hwnd, NULL, TRUE);
  return old;
}
