Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cWndBitmap.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cWndBitmap_H
7 #define _INC_cWndBitmap_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cWndGDI.h"
13 #include "../System/cAppRes.h"
14 
15 #ifdef _WIN32
16 #include "GrayCore/include/cFile.h"
18 
19 namespace GrayLib
20 {
21  UNITTEST2_PREDEF(cWndBitmap);
22 
23  class cImageBMP;
24  class cWndDC;
25  class cWndDCOwn;
26  class cSurfaceBitmapInfo;
27 
28  class GRAYLIB_LINK cWndBitmap
29 #ifdef _MFC_VER // Only need sub-set if using MFC.
30  : public CBitmap
31 #else
32  : public cWndGDIT<HBITMAP>
33 #endif
34  {
39 #ifdef _MFC_VER // Only need sub-set if using MFC.
40  typedef CBitmap SUPER_t;
41 #else
42  typedef cWndGDIT<HBITMAP> SUPER_t;
43 #endif
44 
45  public:
46  cWinSize m_Size;
47 
48  public:
49  cWndBitmap(HBITMAP hBitmap)
50  {
51  Attach(hBitmap);
52  }
53  cWndBitmap(const FILECHAR_t* pFileName)
54  {
55  LoadFile(pFileName);
56  }
57  cWndBitmap(cImageBMP* pDIB)
58  {
59  CreateBitmap(pDIB);
60  }
61  cWndBitmap()
62  {
63  }
64  ~cWndBitmap()
65  {
66  DeleteObject();
67  }
68 
69 #ifdef _MFC_VER // Only need sub-set if using MFC.
70  HBITMAP get_HBitmap() const
71  {
73  return((HBITMAP)m_hObject);
74  }
75 #endif // _MFC_VER
76 
77  static HBITMAP GRAYCALL Bitmap_MakeCopy(HBITMAP hBitmap);
78 
79  // Info functions.
80  operator HBITMAP() const
81  {
82  return(get_HBitmap());
83  }
84 
85  int GetWidth() const
86  {
87  return(m_Size.cx);
88  }
89  int GetHeight() const
90  {
91  return(m_Size.cy);
92  }
93  bool isLoaded() const
94  {
95  return(this != nullptr && get_HBitmap() != WINHANDLE_NULL);
96  }
97 
98  size_t get_DIBSize() const;
99  int GetDIB(cWndDC& dc, HPALETTE hPal, cSurfaceBitmapInfo* pBMI, void* pvBits) const;
100  bool GetBITMAPINFO(cSurfaceBitmapInfo& bmi) const;
101 
102  bool Attach(HBITMAP hBitmap);
103  HBITMAP Detach();
104 
105  bool CreateBitmap(tagBITMAPINFO* pDIB, const void FAR* pBits);
106  bool CreateBitmap(cImageBMP* pDIB);
107 
108  HBITMAP CreateCompatibleBitmap(HDC hDC, int cx, int cy)
109  {
110  // Special version of Attach()
111  Attach(::CreateCompatibleBitmap(hDC, cx, cy));
112  return get_HBitmap();
113  }
114 
115  void Copy(HBITMAP hBitmap);
116  HBITMAP MakeCopy() const;
117 
118  HRESULT ReadBMP(cStreamInput& strIn, bool bHeader = true);
119  HRESULT WriteBMP(cStreamOutput* pOutput, bool bHeader = true) const;
120 
121  virtual HRESULT ReadStream(cStreamInput& strIn)
122  {
123  return ReadBMP(strIn, true);
124  }
125  virtual HRESULT WriteStream(cStreamOutput* pOutput) const
126  {
127  return WriteBMP(pOutput, true);
128  }
129 
130  virtual HRESULT LoadFile(const FILECHAR_t* pFileName);
131  virtual HRESULT SaveFile(const FILECHAR_t* pFileName) const;
132 
133  bool LoadResource(HINSTANCE hInst, RESOURCEID_t id)
134  {
136  return(Attach(_GTN(::LoadBitmap)(hInst, cAppRes::MakeIntResource(id))));
137  }
138 
139  void BltCopy(HDC hDC, int x = 0, int y = 0) const;
140  void BltStretch(HDC hDC, int cx, int cy, int x = 0, int y = 0) const;
141 
142  HBITMAP CreateAnd(void) const;
143  void Paint(
144  HDC hDC, HBITMAP hbmpAnd, int xDst = 0, int yDst = 0,
145  int cxDst = -1, int cyDst = -1,
146  int xSrc = 0, int ySrc = 0) const;
147 
148  UNITTEST2_PREDEF(cWndBitmap);
149  };
150 
151 #ifndef _MFC_VER
152  typedef cWndBitmap CBitmap;
153 #endif
154 }
155 #endif // _WIN32
156 #endif
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define _GTN(c)
_WIN32 name has a A or W for UTF8 or UNICODE (like _FNF)
Definition: StrConst.h:28
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define WINHANDLE_NULL
HWND, HPEN, etc are NOT OS Handles. like HWND_DESKTOP. like HANDLEPTR_NULL. This is a WINAPI void* ha...
Definition: cOSHandle.h:23
static constexpr const GChar_t * MakeIntResource(RESOURCEID_t id) noexcept
Definition: cWinResource.h:45
Definition: cMesh.h:22
UNITTEST2_PREDEF(cQuadtree)
class __DECL_IMPORT cStreamOutput
Definition: cString.h:27
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
WORD RESOURCEID_t
A resource in .RC attached to a file/module. like MAKEINTRESOURCE(). https://docs....
Definition: cResourceBase.h:19
class __DECL_IMPORT cStreamInput
Definition: cString.h:26