ReactOS  0.4.12-dev-918-g6c6e7b8
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 
8 const char titleDrwIco[] = "DrawIcon Output";
9 const char titleMask[] = "Mask(AND image)";
10 const char titleXor[] = "XOR(color image)";
11 const char file[] = "Icon from file:";
12 const char res[] = "Icon from Resource:";
13 const char cursor[] = "Current Cursor:";
14 const char cursormask[] = "Cursor Mask Bitmap";
15 const char cursorcolor[] = "Cursor Color Bitmap";
16 
19 
21 
22 int WINAPI
24  HINSTANCE hPrevInstance,
25  LPSTR lpszCmdLine,
26  int nCmdShow)
27 {
28  WNDCLASS wc;
29  MSG msg;
30  HWND hWnd;
31 
32  hInst = hInstance;
33 
34  #ifdef _GetCursorInfo
35  GetCursorInfo = (GETCURSORINFO)GetProcAddress(GetModuleHandleW(L"user32.dll"), "GetCursorInfo");
36  #endif
37 
38  wc.lpszClassName = "IconTestClass";
41  wc.hInstance = hInstance;
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,
63  hInstance,
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;
92  HICON hIcon;
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);
105  SelectObject(hDC, tf);
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:
201  PostQuitMessage(0);
202  break;
203 
204  default:
205  return DefWindowProc(hWnd, msg, wParam, lParam);
206  }
207  return 0;
208 }
#define IDI_ICON
Definition: resource.h:5
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define IN
Definition: typedefs.h:38
#define DispatchMessage
Definition: winuser.h:5631
BOOL WINAPI TranslateMessage(_In_ const MSG *)
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define IMAGE_ICON
Definition: winuser.h:212
#define DEFAULT_QUALITY
Definition: wingdi.h:435
#define CreateWindow
Definition: winuser.h:5620
#define FF_DONTCARE
Definition: wingdi.h:447
#define __cdecl
Definition: accygwin.h:79
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
#define LR_LOADFROMFILE
Definition: winuser.h:1082
DWORD yHotspot
Definition: winuser.h:3078
LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: icontest.c:88
char CHAR
Definition: xmlstorage.h:175
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Definition: icontest.c:23
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
HWND hWnd
Definition: settings.c:17
LONG top
Definition: windef.h:292
HFONT tf
Definition: icontest.c:17
struct tagCURSORINFO CURSORINFO
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
int cbClsExtra
Definition: winuser.h:3118
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define CS_HREDRAW
Definition: winuser.h:648
LPCSTR lpszMenuName
Definition: winuser.h:3124
HINSTANCE hInst
Definition: icontest.c:18
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define IDI_APPLICATION
Definition: winuser.h:699
UINT_PTR WPARAM
Definition: windef.h:207
HBRUSH hbrBackground
Definition: winuser.h:3123
LONG left
Definition: windef.h:291
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
char * LPSTR
Definition: xmlstorage.h:182
LONG right
Definition: windef.h:293
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:416
BOOL WINAPI GetIconInfo(_In_ HICON, _Out_ PICONINFO)
Definition: cursoricon.c:2014
WPARAM wParam
Definition: combotst.c:138
#define sprintf(buf, format,...)
Definition: sprintf.c:55
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1032
int cbWndExtra
Definition: winuser.h:3119
HINSTANCE hInstance
Definition: charmap.c:20
#define FIXED_PITCH
Definition: wingdi.h:443
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define TA_BASELINE
Definition: wingdi.h:927
HBITMAP hbmMask
Definition: winuser.h:3079
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:425
HCURSOR hCursor
Definition: winuser.h:3122
CHAR * PCH
Definition: ntbasedef.h:398
#define TRANSPARENT
Definition: wingdi.h:949
#define CW_USEDEFAULT
Definition: winuser.h:225
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
HBITMAP hbmColor
Definition: winuser.h:3080
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
BOOL WINAPI GetCursorInfo(_Inout_ PCURSORINFO)
const char titleDrwIco[]
Definition: icontest.c:8
#define CS_VREDRAW
Definition: winuser.h:653
#define LR_DEFAULTSIZE
Definition: winuser.h:1084
DWORD xHotspot
Definition: winuser.h:3077
#define WM_TIMER
Definition: winuser.h:1718
#define WINAPI
Definition: msvc.h:8
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
const char titleMask[]
Definition: icontest.c:9
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:414
BITMAP bmp
Definition: alphablend.c:62
#define WS_HSCROLL
Definition: pedump.c:628
#define WM_PAINT
Definition: winuser.h:1602
static const WCHAR L[]
Definition: oid.c:1250
#define COLOR_BTNFACE
Definition: winuser.h:918
LPCSTR lpszClassName
Definition: winuser.h:3125
#define LoadCursor
Definition: winuser.h:5678
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)
HCURSOR hCursor
Definition: winuser.h:3663
UINT style
Definition: winuser.h:3116
static HDC hDC
Definition: 3dtext.c:33
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
BOOL WINAPI DrawIcon(_In_ HDC, _In_ int, _In_ int, _In_ HICON)
Definition: cursoricon.c:1987
const char cursor[]
Definition: icontest.c:13
HINSTANCE hInstance
Definition: winuser.h:3120
HICON hIcon
Definition: msconfig.c:44
Definition: bl.h:1331
const char cursormask[]
Definition: icontest.c:14
ULONG __cdecl DbgPrint(IN PCH Format, IN ...)
unsigned int UINT
Definition: ndis.h:50
#define WS_VSCROLL
Definition: pedump.c:627
#define GetMessage
Definition: winuser.h:5656
#define FW_NORMAL
Definition: wingdi.h:372
DWORD cbSize
Definition: winuser.h:3661
WNDPROC lpfnWndProc
Definition: winuser.h:3117
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
const char cursorcolor[]
Definition: icontest.c:15
GLuint res
Definition: glext.h:9613
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
unsigned int ULONG
Definition: retypes.h:1
#define TextOut
Definition: wingdi.h:4461
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:845
LONG bottom
Definition: windef.h:294
#define GetProcAddress(x, y)
Definition: compat.h:410
#define LoadImage
Definition: winuser.h:5681
#define RegisterClass
Definition: winuser.h:5702
#define LoadIcon
Definition: winuser.h:5679
#define ANSI_CHARSET
Definition: wingdi.h:382
LONG_PTR LRESULT
Definition: windef.h:209
DWORD flags
Definition: winuser.h:3662
LPARAM lParam
Definition: combotst.c:139
const char titleXor[]
Definition: icontest.c:10
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define SRCCOPY
Definition: wingdi.h:332
HICON hIcon
Definition: winuser.h:3121
Definition: fci.c:126