summaryrefslogtreecommitdiffhomepage
path: root/Magic2/Thumbnail.cpp
blob: f8550844c4181f214af26b4542ba647276763670 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*  Project Magic 2.0
    Destroyer Studios LLC
    Copyright © 1997-2004. All Rights Reserved.

    SUBSYSTEM:    Magic.exe
    FILE:         Thumbnail.h
    AUTHOR:       John DiCamillo


    OVERVIEW
    ========
    Thumbnail.cpp : implementation file
*/

#include "stdafx.h"
#include "Bitmap.h"

// +--------------------------------------------------------------------+
// Preview a bitmap image in the desired window
// +--------------------------------------------------------------------+

void ThumbPreview(HWND hprev, Bitmap* bitmap)
{
   HDC         hdc      = ::GetDC(hprev);
   RECT        rect;
   BITMAPINFO* pbmiDIB  = new BITMAPINFO;

   if (!pbmiDIB)
      return;

   ::GetClientRect(hprev, &rect);

   pbmiDIB->bmiHeader.biSize           = sizeof(BITMAPINFOHEADER);
   pbmiDIB->bmiHeader.biWidth          = bitmap->Width();
   pbmiDIB->bmiHeader.biHeight         = -bitmap->Height();
   pbmiDIB->bmiHeader.biPlanes         = 1;
   pbmiDIB->bmiHeader.biBitCount       = 32;
   pbmiDIB->bmiHeader.biCompression    = BI_RGB;
   pbmiDIB->bmiHeader.biSizeImage      = 0;
   pbmiDIB->bmiHeader.biXPelsPerMeter  = 0;
   pbmiDIB->bmiHeader.biYPelsPerMeter  = 0;
   pbmiDIB->bmiHeader.biClrUsed        = 0;
   pbmiDIB->bmiHeader.biClrImportant   = 0;

   int result =
   ::StretchDIBits(hdc, 
                   1,         1,        128,             128,
                   0,         0,        bitmap->Width(), bitmap->Height(),
                   bitmap->HiPixels(),
                   pbmiDIB,
                   DIB_RGB_COLORS,
                   SRCCOPY);

   ::ReleaseDC(hprev, hdc);

   delete pbmiDIB;
}