ReactOS 0.4.15-dev-7958-gcd0bb1a
icontest.c
Go to the documentation of this file.
1#include <windows.h>
2#include "resource.h"
3#include <string.h>
4#include <stdio.h>
5
7
8const char titleDrwIco[] = "DrawIcon Output";
9const char titleMask[] = "Mask(AND image)";
10const char titleXor[] = "XOR(color image)";
11const char file[] = "Icon from file:";
12const char res[] = "Icon from Resource:";
13const char cursor[] = "Current Cursor:";
14const char cursormask[] = "Cursor Mask Bitmap";
15const char cursorcolor[] = "Cursor Color Bitmap";
16
19
21
22int WINAPI
24 HINSTANCE hPrevInstance,
25 LPSTR lpszCmdLine,
26 int nCmdShow)
27{
28 WNDCLASS wc;
29 MSG msg;
30 HWND hWnd;
31
33
34 #ifdef _GetCursorInfo
35 GetCursorInfo = (GETCURSORINFO)GetProcAddress(GetModuleHandleW(L"user32.dll"), "GetCursorInfo");
36 #endif
37
38 wc.lpszClassName = "IconTestClass";
44 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
45 wc.lpszMenuName = NULL;
46 wc.cbClsExtra = 0;
47 wc.cbWndExtra = 0;
48 if (RegisterClass(&wc) == 0)
49 {
50 DbgPrint("RegisterClass failed (last error 0x%X)\n", GetLastError());
51 return(1);
52 }
53
54 hWnd = CreateWindow("IconTestClass",
55 "Icon Test",
59 480,
60 480,
61 NULL,
62 NULL,
64 NULL);
65 if (hWnd == NULL)
66 {
67 DbgPrint("CreateWindow failed (last error 0x%X)\n", GetLastError());
68 return(1);
69 }
70
74
75 ShowWindow(hWnd, nCmdShow);
76
77 SetTimer(hWnd, 1, 1000, NULL);
78
79 while(GetMessage(&msg, NULL, 0, 0))
80 {
83 }
84
85 return msg.wParam;
86}
87
89{
90 PAINTSTRUCT ps;
91 HDC hDC;
93 HGDIOBJ hOld;
94 HDC hMemDC;
95 CURSORINFO cursorinfo;
96 ICONINFO iconinfo;
97 BITMAP bmp;
98 RECT rc;
99 CHAR str[20];
100
101 switch(msg)
102 {
103 case WM_PAINT:
104 hDC = BeginPaint(hWnd, &ps);
107
108 TextOut(hDC, 160, 10, file, strlen(file));
110 TextOut(hDC, 160, 85, titleMask, strlen(titleMask));
111 TextOut(hDC, 300, 85, titleXor, strlen(titleXor));
112
114 DrawIcon(hDC,50,50,hIcon);
115
116 hMemDC = CreateCompatibleDC(hDC);
117 GetIconInfo(hIcon, &iconinfo);
119
120 hOld = SelectObject(hMemDC, iconinfo.hbmMask);
121 BitBlt(hDC, 200, 50, 32, 32, hMemDC, 0, 0, SRCCOPY);
122 SelectObject(hMemDC, iconinfo.hbmColor);
123 BitBlt(hDC, 350, 50, 32, 32, hMemDC, 0, 0, SRCCOPY);
124
125 DeleteObject(iconinfo.hbmMask);
126 DeleteObject(iconinfo.hbmColor);
127
128 TextOut(hDC, 145, 150, res, strlen(res));
130 TextOut(hDC, 160, 225, titleMask, strlen(titleMask));
131 TextOut(hDC, 300, 225, titleXor, strlen(titleXor));
132
134 DrawIcon(hDC,50,190,hIcon);
135
136 GetIconInfo(hIcon, &iconinfo);
138
139 SelectObject(hMemDC, iconinfo.hbmMask);
140 BitBlt(hDC, 200, 190, 32, 32, hMemDC, 0, 0, SRCCOPY);
141 SelectObject(hMemDC, iconinfo.hbmColor);
142 BitBlt(hDC, 350, 190, 32, 32, hMemDC, 0, 0, SRCCOPY);
143
144 DeleteObject(iconinfo.hbmMask);
145 DeleteObject(iconinfo.hbmColor);
146
147 cursorinfo.cbSize = sizeof(CURSORINFO);
148 if(GetCursorInfo(&cursorinfo))
149 {
150 if(cursorinfo.hCursor && cursorinfo.flags)
151 {
152 TextOut(hDC, 160, 290, cursor, strlen(cursor));
153 DrawIcon(hDC, 50, 330, cursorinfo.hCursor);
154 GetIconInfo(cursorinfo.hCursor, &iconinfo);
156
157 sprintf(str, "Hotspot: %ld; %ld", iconinfo.xHotspot, iconinfo.yHotspot);
158 TextOut(hDC, 15, 380, str, strlen(str));
159
160 if(iconinfo.hbmMask)
161 {
162 GetObjectW(iconinfo.hbmMask, sizeof(BITMAP), &bmp);
163 SelectObject(hMemDC, iconinfo.hbmMask);
164 BitBlt(hDC, 200, 330, bmp.bmWidth, bmp.bmHeight, hMemDC, 0, 0, SRCCOPY);
165 DeleteObject(iconinfo.hbmMask);
166 TextOut(hDC, 160, 365 - 32 + bmp.bmHeight, cursormask, strlen(cursormask));
167
168 sprintf(str, "%dBPP", bmp.bmBitsPixel);
169 TextOut(hDC, 160, 380 - 32 + bmp.bmHeight, str, strlen(str));
170 }
171
172 if(iconinfo.hbmColor)
173 {
174 GetObjectW(iconinfo.hbmColor, sizeof(BITMAP), &bmp);
175 SelectObject(hMemDC, iconinfo.hbmColor);
176 BitBlt(hDC, 350, 330, bmp.bmWidth, bmp.bmHeight, hMemDC, 0, 0, SRCCOPY);
177 DeleteObject(iconinfo.hbmColor);
178 TextOut(hDC, 300, 365 - 32 + bmp.bmHeight, cursorcolor, strlen(cursorcolor));
179
180 sprintf(str, "%dBPP", bmp.bmBitsPixel);
181 TextOut(hDC, 300, 380 - 32 + bmp.bmHeight, str, strlen(str));
182 }
183 }
184 }
185
186 SelectObject(hMemDC, hOld);
187
188 DeleteObject(hMemDC);
189 EndPaint(hWnd, &ps);
190 break;
191
192 case WM_TIMER:
193 rc.left = 0;
194 rc.top = 330;
195 rc.right = 480;
196 rc.bottom = 480;
197 InvalidateRect(hWnd, &rc, TRUE);
198 break;
199
200 case WM_DESTROY:
202 break;
203
204 default:
206 }
207 return 0;
208}
static HDC hDC
Definition: 3dtext.c:33
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define __cdecl
Definition: accygwin.h:79
#define msg(x)
Definition: auth_time.c:54
#define IDI_ICON
Definition: resource.h:5
HWND hWnd
Definition: settings.c:17
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
#define CALLBACK
Definition: compat.h:35
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
static VOID BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:57
pKey DeleteObject()
GLuint res
Definition: glext.h:9613
#define DbgPrint
Definition: hal.h:12
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Definition: icontest.c:23
LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: icontest.c:88
HINSTANCE hInst
Definition: icontest.c:18
const char cursormask[]
Definition: icontest.c:14
const char titleMask[]
Definition: icontest.c:9
HFONT tf
Definition: icontest.c:17
const char titleXor[]
Definition: icontest.c:10
const char cursorcolor[]
Definition: icontest.c:15
const char titleDrwIco[]
Definition: icontest.c:8
const char cursor[]
Definition: icontest.c:13
#define sprintf(buf, format,...)
Definition: sprintf.c:55
BITMAP bmp
Definition: alphablend.c:62
static HDC
Definition: imagelist.c:92
static HICON
Definition: imagelist.c:84
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
HICON hIcon
Definition: msconfig.c:44
unsigned int UINT
Definition: ndis.h:50
CHAR * PCH
Definition: ntbasedef.h:391
#define L(x)
Definition: ntvdm.h:50
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define WS_VSCROLL
Definition: pedump.c:627
#define WS_HSCROLL
Definition: pedump.c:628
#define DefWindowProc
Definition: ros2win.h:31
const WCHAR * str
Definition: bl.h:1331
DWORD yHotspot
Definition: winuser.h:3125
DWORD xHotspot
Definition: winuser.h:3124
HBITMAP hbmColor
Definition: winuser.h:3127
HBITMAP hbmMask
Definition: winuser.h:3126
HBRUSH hbrBackground
Definition: winuser.h:3170
HICON hIcon
Definition: winuser.h:3168
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
int cbWndExtra
Definition: winuser.h:3166
UINT style
Definition: winuser.h:3163
LPCSTR lpszMenuName
Definition: winuser.h:3171
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
int cbClsExtra
Definition: winuser.h:3165
Definition: fci.c:127
DWORD flags
Definition: winuser.h:3720
DWORD cbSize
Definition: winuser.h:3719
HCURSOR hCursor
Definition: winuser.h:3721
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
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 FIXED_PITCH
Definition: wingdi.h:444
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
#define DEFAULT_QUALITY
Definition: wingdi.h:436
#define FF_DONTCARE
Definition: wingdi.h:448
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define TRANSPARENT
Definition: wingdi.h:950
#define SRCCOPY
Definition: wingdi.h:333
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:415
#define ANSI_CHARSET
Definition: wingdi.h:383
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:426
#define FW_NORMAL
Definition: wingdi.h:373
#define TA_BASELINE
Definition: wingdi.h:928
HFONT WINAPI CreateFontA(_In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_opt_ LPCSTR)
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
#define TextOut
Definition: wingdi.h:4483
#define WM_PAINT
Definition: winuser.h:1620
BOOL WINAPI GetCursorInfo(_Inout_ PCURSORINFO)
#define CS_VREDRAW
Definition: winuser.h:658
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
struct tagCURSORINFO CURSORINFO
#define LR_LOADFROMFILE
Definition: winuser.h:1092
#define IMAGE_ICON
Definition: winuser.h:212
BOOL WINAPI GetIconInfo(_In_ HICON, _Out_ PICONINFO)
Definition: cursoricon.c:2045
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
BOOL WINAPI DrawIcon(_In_ HDC, _In_ int, _In_ int, _In_ HICON)
Definition: cursoricon.c:2018
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define IDI_APPLICATION
Definition: winuser.h:704
#define CreateWindow
Definition: winuser.h:5754
#define GetMessage
Definition: winuser.h:5790
#define WM_TIMER
Definition: winuser.h:1742
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define LoadIcon
Definition: winuser.h:5813
#define LoadCursor
Definition: winuser.h:5812
#define CW_USEDEFAULT
Definition: winuser.h:225
#define LoadImage
Definition: winuser.h:5815
#define RegisterClass
Definition: winuser.h:5836
#define WM_DESTROY
Definition: winuser.h:1609
#define LR_DEFAULTSIZE
Definition: winuser.h:1094
#define DispatchMessage
Definition: winuser.h:5765
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define COLOR_BTNFACE
Definition: winuser.h:928
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2053
char * LPSTR
Definition: xmlstorage.h:182
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
char CHAR
Definition: xmlstorage.h:175