ReactOS 0.4.16-dev-329-g9223134
showimg.c
Go to the documentation of this file.
1// Released to the Public Domain by Doug Lyons on April 16th, 2024.
2
3#include <windows.h>
4#include <stdio.h>
5
6WCHAR szWindowClass[] = L"testclass";
7
8static LRESULT CALLBACK
10{
11 static HBITMAP hBmp;
13 CHAR buffer[32];
14
15 switch (message)
16 {
17 case WM_CREATE:
18 {
20 sprintf(buffer, "%p", handle);
21 MessageBoxA(NULL, buffer, "handle", 0);
23 sprintf(buffer, "%p", hBmp);
24 MessageBoxA(NULL, buffer, "Bmp", 0);
25 sprintf(buffer, "%ld", GetLastError());
26 MessageBoxA(NULL, buffer, "LastError", 0);
27 break;
28 }
29
30 case WM_PAINT:
31 {
32 PAINTSTRUCT ps;
33 HDC hdc, hdcMem;
35 BITMAPINFO bmi;
36 hdc = BeginPaint(hWnd, &ps);
37 HGLOBAL hMem;
38 LPVOID lpBits;
39
41 SelectObject(hdcMem, hBmp);
42 GetObject(hBmp, sizeof(BITMAP), &bitmap);
43
44 memset(&bmi, 0, sizeof(bmi));
45 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
46 bmi.bmiHeader.biWidth = bitmap.bmWidth;
47 bmi.bmiHeader.biHeight = bitmap.bmHeight;
48 bmi.bmiHeader.biPlanes = bitmap.bmPlanes;
49 bmi.bmiHeader.biBitCount = bitmap.bmBitsPixel;
51 bmi.bmiHeader.biSizeImage = 0;
52
53 hMem = GlobalAlloc(GMEM_MOVEABLE, ((bitmap.bmWidth *
54 bmi.bmiHeader.biBitCount + 31) / 32) * 4 * bitmap.bmHeight);
55 lpBits = GlobalLock(hMem);
56 GetDIBits(hdc, hBmp, 0, bitmap.bmHeight, lpBits, &bmi, DIB_RGB_COLORS);
57
58 // increasing the multiplier makes the image larger
59 StretchDIBits(hdc, 0, 0, bitmap.bmWidth * 3, bitmap.bmHeight * 3, 0, 0,
60 bitmap.bmWidth, bitmap.bmHeight,lpBits, &bmi, DIB_RGB_COLORS, SRCCOPY);
61 GlobalUnlock(hMem);
62 GlobalFree(hMem);
63
65
66 EndPaint(hWnd, &ps);
67 break;
68 }
69
70 case WM_DESTROY:
72 break;
73 default:
75 }
76 return 0;
77}
78
79
80static ATOM
82{
83 WNDCLASSEX wcex;
84
85 wcex.cbSize = sizeof(WNDCLASSEX);
86
88 wcex.lpfnWndProc = WndProc;
89 wcex.cbClsExtra = 0;
90 wcex.cbWndExtra = 0;
91 wcex.hInstance = hInstance;
92 wcex.hIcon = NULL;
94 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
95 wcex.lpszMenuName = NULL;
97 wcex.hIconSm = NULL;
98
99 return RegisterClassEx(&wcex);
100}
101
102
103static BOOL
105{
106 HWND hWnd;
107
110 L"Bmp test",
114 300,
115 120,
116 NULL,
117 NULL,
118 hInstance,
119 NULL);
120
121 if (!hWnd)
122 return FALSE;
123
124 ShowWindow(hWnd, nCmdShow);
126
127 return TRUE;
128}
129
130int WINAPI
132 HINSTANCE hPrevInstance,
133 LPTSTR lpCmdLine,
134 int nCmdShow)
135{
136 MSG msg;
137
139
140 if (!InitInstance(hInstance, nCmdShow))
141 return FALSE;
142
143 while (GetMessage(&msg, NULL, 0, 0))
144 {
147 }
148
149 return (int)msg.wParam;
150}
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
WORD ATOM
Definition: dimm.idl:113
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CALLBACK
Definition: compat.h:35
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:288
#define BI_RGB
Definition: precomp.h:56
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint buffer
Definition: glext.h:5915
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define sprintf(buf, format,...)
Definition: sprintf.c:55
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define DefWindowProc
Definition: ros2win.h:31
#define memset(x, y, z)
Definition: compat.h:39
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
Definition: showimg.c:131
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: showimg.c:9
static ATOM MyRegisterClass(HINSTANCE hInstance)
Definition: showimg.c:81
static BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
Definition: showimg.c:104
WCHAR szWindowClass[]
Definition: showimg.c:6
Definition: bl.h:1331
int cbClsExtra
Definition: winuser.h:3207
HINSTANCE hInstance
Definition: winuser.h:3209
HCURSOR hCursor
Definition: winuser.h:3211
LPCSTR lpszMenuName
Definition: winuser.h:3213
HICON hIconSm
Definition: winuser.h:3215
UINT style
Definition: winuser.h:3205
int cbWndExtra
Definition: winuser.h:3208
UINT cbSize
Definition: winuser.h:3204
WNDPROC lpfnWndProc
Definition: winuser.h:3206
LPCSTR lpszClassName
Definition: winuser.h:3214
HICON hIcon
Definition: winuser.h:3210
HBRUSH hbrBackground
Definition: winuser.h:3212
Definition: uimain.c:89
Definition: tftpd.h:60
USHORT biBitCount
Definition: precomp.h:46
ULONG biCompression
Definition: precomp.h:47
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
HDC hdcMem
Definition: welcome.c:104
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:368
#define GMEM_MOVEABLE
Definition: winbase.h:320
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define DIB_RGB_COLORS
Definition: wingdi.h:367
int WINAPI GetDIBits(_In_ HDC hdc, _In_ HBITMAP hbm, _In_ UINT start, _In_ UINT cLines, _Out_opt_ LPVOID lpvBits, _At_((LPBITMAPINFOHEADER) lpbmi, _Inout_) LPBITMAPINFO lpbmi, _In_ UINT usage)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define SRCCOPY
Definition: wingdi.h:333
#define GetObject
Definition: wingdi.h:4468
BOOL WINAPI DeleteDC(_In_ HDC)
int WINAPI StretchDIBits(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_opt_ const VOID *, _In_ const BITMAPINFO *, _In_ UINT, _In_ DWORD)
#define WM_PAINT
Definition: winuser.h:1623
#define CS_VREDRAW
Definition: winuser.h:658
#define CreateWindowEx
Definition: winuser.h:5767
#define IMAGE_BITMAP
Definition: winuser.h:211
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define COLOR_WINDOW
Definition: winuser.h:921
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define WM_CREATE
Definition: winuser.h:1611
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
int WINAPI MessageBoxA(_In_opt_ HWND hWnd, _In_opt_ LPCSTR lpText, _In_opt_ LPCSTR lpCaption, _In_ UINT uType)
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
#define GetMessage
Definition: winuser.h:5802
#define RegisterClassEx
Definition: winuser.h:5849
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5824
WNDCLASSEXA WNDCLASSEX
Definition: winuser.h:5731
#define CW_USEDEFAULT
Definition: winuser.h:225
#define LoadImage
Definition: winuser.h:5827
#define LR_DEFAULTCOLOR
Definition: winuser.h:1090
#define WM_DESTROY
Definition: winuser.h:1612
#define DispatchMessage
Definition: winuser.h:5777
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define MAKEINTRESOURCE
Definition: winuser.h:591
__wchar_t WCHAR
Definition: xmlstorage.h:180
CHAR * LPTSTR
Definition: xmlstorage.h:192
char CHAR
Definition: xmlstorage.h:175