/* bitmap1.c      BitBlt() / StretchBlt() example */

#include <windows.h>
#include "bitmap1.h"

int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                             LPSTR lpszCmdLine, int nCmdShow)
{
    HWND        hWnd ;      /* the window's "handle" */
    MSG         msg ;       /* a message structure */
    WNDCLASS    wndclass ;  /* window class structure */
    
        wndclass.style          = CS_HREDRAW | CS_VREDRAW ;
        wndclass.lpfnWndProc    = WndProc ;
        wndclass.cbClsExtra     = 0 ;
        wndclass.cbWndExtra     = 0 ;
        wndclass.hInstance      = hInstance ;
        wndclass.hIcon          = LoadIcon (NULL, NULL) ;
        wndclass.hCursor        = LoadCursor (NULL, IDC_ARROW) ;
        wndclass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH) ;
        wndclass.lpszMenuName   = "MYMENU" ;
        wndclass.lpszClassName  = "MyClass" ;
                        /* register the window class */
        if (!RegisterClass (&wndclass))
            return 0 ;

    hWnd = CreateWindow ("MyClass", "Bitmap1 Program", WS_OVERLAPPEDWINDOW, 
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
        NULL, NULL, hInstance, NULL) ;
    ShowWindow (hWnd, nCmdShow) ;   /* display the window */    
    UpdateWindow (hWnd) ;
    while (GetMessage (&msg, NULL, 0, 0))   /* message loop */
    {
        TranslateMessage (&msg) ;   /* translate keyboard messages */
        DispatchMessage (&msg) ;    /* send message to WndProc() */
    }
    return (msg.wParam) ;
}

LRESULT CALLBACK WndProc (HWND hWnd, UINT wMessage,
                          WPARAM wParam, LPARAM lParam)
{
    HDC         hDC, hMemDC ;
    HBITMAP     hBitmap ;
    HINSTANCE   hInstance ;
    
    switch (wMessage)       /* process windows messages */
    {
    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case IDM_SHOW:
            hInstance = (HINSTANCE)GetWindowLong (hWnd, GWL_HINSTANCE) ;
            hBitmap = LoadBitmap (hInstance, "HOUSEBMP") ;
            hDC = GetDC (hWnd) ;
            hMemDC = CreateCompatibleDC (hDC) ;
            SelectObject (hMemDC, hBitmap) ;
            BitBlt (hDC, 0, 0, 32, 32, hMemDC, 0, 0, SRCCOPY) ;
            BitBlt (hDC, 50, 0, 64, 64, hMemDC, 0, 0, SRCCOPY) ;
            BitBlt (hDC, 150, 0, 32, 32, hMemDC, 32, 32, SRCCOPY) ;
            StretchBlt(hDC,0,100,32,32,hMemDC,0,0,64,64,SRCCOPY);
            StretchBlt(hDC,50,100,64,64,hMemDC,0,0,64,64,SRCCOPY);
            StretchBlt(hDC,150,100,128,128,hMemDC,0,0,32,32,SRCCOPY);
            DeleteDC (hMemDC) ;
            ReleaseDC (hWnd, hDC) ;
            DeleteObject (hBitmap) ;
            break ;
        case IDM_QUIT:              /* Quit menu item */
            DestroyWindow (hWnd) ;  /* destroy window, */
            break ;     /* terminating application */
        }
        break ;

        case WM_DESTROY:    /* stop application */
            PostQuitMessage (0) ;
            break ;
 
        default:        /* default windows message processing */
            return (DefWindowProc (hWnd, wMessage, wParam, lParam)) ;
    }
    return (0) ;
}