summaryrefslogtreecommitdiffhomepage
path: root/Magic2/Thumbnail.cpp
blob: ee6eb154014aa092f16c8857702e6325efb12a16 (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
/*  Starshatter: The Open Source Project
    Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
    Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
    Copyright (c) 1997-2006, Destroyer Studios LLC.

    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;
}