Oval Window Example

With 32-bit Windows, you can develop applications with arbitrary shaped window regions! Here is a C++ code example of an application with an oval window. It doesn't do anything useful except to demonstrate that oval shaped windows are possible in 32-bit Windows. It is essentially uncommented, but hopefully short enough to understand without comments.
#include "windows.h"

void SetRgn(HWND hW)
{
   RECT rect,wrect;
   GetClientRect(hW,&rect);
   GetWindowRect(hW,&wrect);
   int barwidth = wrect.right-wrect.left;
   int brdrwidth = (barwidth-rect.right)/2;
   int barheight = wrect.bottom-wrect.top-rect.bottom-brdrwidth;
   HRGN hRgnE = CreateEllipticRgn(brdrwidth-1, barheight-2, brdrwidth+rect.right+2, barheight+rect.bottom+2);
   HRGN hRgn = CreateRectRgn(0,0,barwidth,barheight);     // handle to region
   CombineRgn(hRgn,hRgn,hRgnE,RGN_OR);
   SetWindowRgn(hW,hRgn,TRUE);
}

long FAR PASCAL AlohaProc( HWND hW, unsigned msg, unsigned wP, LONG lP)
{
   HDC hdc;
   PAINTSTRUCT ps;
   RECT rect;
   static ticks=0;
   switch (msg) {
   case WM_TIMER:
      ticks++;
      GetClientRect(hW,&rect);
      InvalidateRect(hW,&rect,0);
      UpdateWindow(hW);
      return 0;
   case WM_PAINT:
      hdc = BeginPaint(hW,&ps);
      GetClientRect(hW,&rect);
      SelectObject(hdc,GetStockObject((ticks&1)?BLACK_PEN:WHITE_PEN));
      Ellipse(hdc, rect.left, rect.top, rect.right, rect.bottom);
      EndPaint(hW,&ps);
      return 0;
   case WM_SIZE:
      SetRgn(hW);
      return 0;
   case WM_LBUTTONDOWN:
   case WM_DESTROY:
      PostQuitMessage(0);
      return 0;
   }
   return DefWindowProc(hW,msg,wP,lP);
}

int PASCAL WinMain(HANDLE hI, HANDLE hPI, LPSTR cL, int nCS)
{
    static char ApN[]="Aloha";
    HWND hwnd;
    MSG msg;
    WNDCLASS wc={0};
    if (!hPI) {
       wc.lpfnWndProc = AlohaProc;
       wc.hInstance = hI;
       wc.lpszClassName = ApN;
       wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
       wc.style = CS_HREDRAW | CS_VREDRAW ;
       RegisterClass(&wc);
    }
    hwnd = CreateWindow( ApN, "Aloha!", WS_OVERLAPPEDWINDOW,
              100,100,       // xy pos
              200,200,       // xy size
              NULL,NULL,hI,  // parent, window, instance
              NULL);          // creation parameters
    SetRgn(hwnd);
    ShowWindow(hwnd,nCS);
    SetTimer(hwnd,1, 1000, NULL);
    while (GetMessage(&msg,NULL,0,0)) {
       TranslateMessage(&msg);
       DispatchMessage(&msg);
    }
    KillTimer(hwnd,1);
    return msg.wParam;
}

Nov 1999 - Ted Shaneyfelt