-
Notifications
You must be signed in to change notification settings - Fork 7
/
dibsect.h
87 lines (74 loc) · 1.79 KB
/
dibsect.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* $Id: dibsect.h,v 1.1 2004/03/16 01:37:20 ctrondlp Exp $
*
* Adapted from code submitted by Jarek Jurasz
* <[email protected]>. Thanks!
*
* This file is part of the Win32::GuiTest Perl module.
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License.
*
*/
#ifndef DIBSECT_H
#define DIBSECT_H 1
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/*
JJ DibSection wrapper
Currently only 24bit bitmaps fully supported
*/
class DibSect
: public BITMAPINFOHEADER
{
public:
DibSect();
~DibSect() { Destroy(); }
bool Destroy();
bool Load (const char * szFile);
bool SaveAs(const char * szFile);
bool Invert();
bool ToGrayScale();
HBITMAP CopyWndClient
(
HWND hWnd,
RECT * pr = NULL
);
bool ToClipboard();
// copy BMIH only, no result on created DibSection
DibSect& operator=(const DibSect & rhs)
{
CopyMemory(this, &rhs, sizeof(BITMAPINFOHEADER));
return *this;
}
operator HBITMAP() const
{
return hBitmap;
}
HBITMAP Create(HDC hDC);
// the C++ object loses the ownership over DIB object
HBITMAP StealBitmap()
{
HBITMAP hbm = hBitmap;
hBitmap = NULL;
return hbm;
}
PBYTE GetBits() const
{
return pBits;
}
UINT GetWidthBytes() const
{
return cWidthBytes;
}
HMETAFILE AsMetafile();
protected:
// returns variable size of BITMAPINFO depending on color depth
UINT GetBmiSize() const;
private:
HBITMAP hBitmap;
PBYTE pBits; // bitmap's bytes
int cySize; // also in biHeight, but may be inverted
UINT cWidthBytes; // bitmap width in bytes
};//class DibSect---------------------------------------------------------------
#endif // DIBSECT_H