ReactOS  0.4.14-dev-822-g065afd9
dib.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: PAINT for ReactOS
3  * LICENSE: LGPL
4  * FILE: base/applications/mspaint/dib.cpp
5  * PURPOSE: Some DIB related functions
6  * PROGRAMMERS: Benedikt Freisen
7  */
8 
9 /* INCLUDES *********************************************************/
10 
11 #include "precomp.h"
12 
13 /* FUNCTIONS ********************************************************/
14 
15 HBITMAP
17 {
18  BITMAPINFO bmi;
19  ZeroMemory(&bmi, sizeof(BITMAPINFO));
20  bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
21  bmi.bmiHeader.biWidth = width;
23  bmi.bmiHeader.biPlanes = 1;
24  bmi.bmiHeader.biBitCount = 24;
26  return CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
27 }
28 
29 int
31 {
32  BITMAP bm;
33  GetObject(hBitmap, sizeof(BITMAP), &bm);
34  return bm.bmWidth;
35 }
36 
37 int
39 {
40  BITMAP bm;
41  GetObject(hBitmap, sizeof(BITMAP), &bm);
42  return bm.bmHeight;
43 }
44 
45 void
47 {
48  CImage img;
49  img.Attach(hBitmap);
50  img.Save(FileName); // TODO: error handling
51  img.Detach();
52 
53  // update time and size
54 
55  HANDLE hFile =
58  return;
59 
60  if (time)
61  {
62  FILETIME ft;
63  GetFileTime(hFile, NULL, NULL, &ft);
65  }
66  if (size)
68 
69  // TODO: update hRes and vRes
70 
72 }
73 
75 {
76  CString strText;
78  CString strProgramName;
79  strProgramName.LoadString(IDS_PROGRAMNAME);
80  mainWindow.MessageBox(strText, strProgramName, MB_OK | MB_ICONEXCLAMATION);
81 }
82 
83 void
84 LoadDIBFromFile(HBITMAP * hBitmap, LPCTSTR name, LPSYSTEMTIME time, int *size, int *hRes, int *vRes)
85 {
86  CImage img;
87  img.Load(name);
88  *hBitmap = img.Detach();
89 
90  if (!hBitmap)
91  {
93  return;
94  }
95 
96  // update time and size
97  HANDLE hFile =
100  {
102  return;
103  }
104 
105  if (time)
106  {
107  FILETIME ft;
108  GetFileTime(hFile, NULL, NULL, &ft);
110  }
111  if (size)
112  *size = GetFileSize(hFile, NULL);
113 
114  HDC hScreenDC = GetDC(NULL);
115  *hRes = (int)(GetDeviceCaps(hScreenDC, LOGPIXELSX) * 1000 / 25.4);
116  *vRes = (int)(GetDeviceCaps(hScreenDC, LOGPIXELSY) * 1000 / 25.4);
117  ReleaseDC(NULL, hScreenDC);
118 
120 }
GLint GLint GLsizei width
Definition: gl.h:1546
#define LOGPIXELSX
Definition: wingdi.h:717
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define CloseHandle
Definition: compat.h:406
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1475
void SaveDIBToFile(HBITMAP hBitmap, LPTSTR FileName, HDC hDC, LPSYSTEMTIME time, int *size, int hRes, int vRes)
Definition: dib.cpp:46
HDC WINAPI GetDC(_In_opt_ HWND)
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
#define IDS_PROGRAMNAME
Definition: definitions.h:203
static HDC
Definition: imagelist.c:92
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
#define ZeroMemory
Definition: winbase.h:1642
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:668
int GetDIBHeight(HBITMAP hBitmap)
Definition: dib.cpp:38
__u16 time
Definition: mkdosfs.c:366
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define FILE_SHARE_READ
Definition: compat.h:125
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
void LoadDIBFromFile(HBITMAP *hBitmap, LPCTSTR name, LPSYSTEMTIME time, int *size, int *hRes, int *vRes)
Definition: dib.cpp:84
int GetDIBWidth(HBITMAP hBitmap)
Definition: dib.cpp:30
#define IDS_LOADERRORTEXT
Definition: definitions.h:238
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
DWORD biCompression
Definition: amvideo.idl:35
smooth NULL
Definition: ftsmooth.c:416
HBITMAP CreateDIBWithProperties(int width, int height)
Definition: dib.cpp:16
#define OPEN_EXISTING
Definition: compat.h:434
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:188
GLsizeiptr size
Definition: glext.h:5919
GLint GLvoid * img
Definition: gl.h:1956
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
#define GetObject
Definition: wingdi.h:4467
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
static HDC hDC
Definition: 3dtext.c:33
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
#define FILE_FLAG_SEQUENTIAL_SCAN
Definition: disk.h:43
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:197
Definition: bl.h:1331
#define MB_OK
Definition: winuser.h:784
void ShowFileLoadError(LPCTSTR name)
Definition: dib.cpp:74
Definition: name.c:38
BOOL LoadString(_In_ UINT nID)
Definition: cstringt.h:506
#define LOGPIXELSY
Definition: wingdi.h:718
static HBITMAP
Definition: button.c:44
#define DIB_RGB_COLORS
Definition: wingdi.h:366
int MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption=NULL, UINT nType=MB_OK)
Definition: atlwin.h:934
#define BI_RGB
Definition: precomp.h:41
static HBITMAP hBitmap
Definition: timezone.c:35
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:1046
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
CMainWindow mainWindow
Definition: main.cpp:62