/* The original version of this program can be found at http://damb.dk */
#define _WIN32_WINNT 0x0500
#include <windows.h>

#define IDC_BUTTON1  1200

HINSTANCE InstanceHandle;
bool Running = true;
HBITMAP BackBitMap;

BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
{
   InvalidateRect(hwnd, 0, TRUE);
   return TRUE;
}

void DrawWindow(HWND hwnd)
{
   HDC DC = GetWindowDC(hwnd);
   HDC MemDC = CreateCompatibleDC(DC);
   SelectObject(MemDC, BackBitMap);
   BitBlt(DC, 0, 0, 150, 100, MemDC, 0, 0, SRCCOPY);
   DeleteDC(MemDC);
   ReleaseDC(hwnd, DC);
   EnumChildWindows(hwnd, EnumChildProc, 0);
}

LRESULT CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
   switch(msg)
   {
   case WM_CREATE:
      CreateWindow("BUTTON",
                   "Push Me",
                   WS_CHILD | WS_VISIBLE,
                   25, 10, 100, 30,
                   hwndDlg,
                   (HMENU)(IDC_BUTTON1),
                   InstanceHandle,
                   0);
      BackBitMap = (HBITMAP )LoadImage(0, "round.bmp", IMAGE_BITMAP, 150, 100, LR_LOADFROMFILE);
      SetWindowLong(hwndDlg, GWL_EXSTYLE, GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_LAYERED);
      SetLayeredWindowAttributes(hwndDlg, RGB(0xC0, 0xC0, 0xC0), 0, LWA_COLORKEY);
      DrawWindow(hwndDlg);
      break;
   case WM_PAINT:
   {
      PAINTSTRUCT PaintStruct;
      BeginPaint(hwndDlg, &PaintStruct);
      EndPaint(hwndDlg, &PaintStruct);
   }
   case WM_ACTIVATE:
   case WM_NCACTIVATE:
   case WM_NCPAINT:
   {
      DrawWindow(hwndDlg);
      return 0;
   }
   case WM_COMMAND:
      EndDialog(hwndDlg, 0);
      Running = false;
      break;
   }
   return DefWindowProc(hwndDlg, msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, INT nCmdShow)
{
   InstanceHandle = hInstance;

   WNDCLASS wc;
   memset(&wc, 0, sizeof(WNDCLASS));
   wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
   wc.lpfnWndProc = DialogProc;
   wc.hInstance = InstanceHandle;
   wc.hbrBackground = (HBRUSH )(COLOR_BTNFACE + 1);
   wc.lpszClassName = "WhateverClass";
   wc.hCursor = LoadCursor(NULL, IDC_ARROW);
   if(!RegisterClass(&wc))
      return FALSE;

   HWND WindowHandle = CreateWindow("WhateverClass",
                                    "",
                                    WS_VISIBLE,
                                    300, 100, 150, 100,
                                    NULL,
                                    NULL,
                                    InstanceHandle,
                                    0);
   MSG Msg;
   while(Running && GetMessage(&Msg, WindowHandle, 0, 0xFFFF) > 0)
   {
      if(!IsDialogMessage(WindowHandle, &Msg))
      {
         TranslateMessage(&Msg);
         DispatchMessage(&Msg);
      }
   }
   return 0;
}