6 ULONG __cdecl
DbgPrint(IN PCH Format
, IN
...);
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";
20 LRESULT WINAPI
MainWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
23 WinMain(HINSTANCE hInstance
,
24 HINSTANCE hPrevInstance
,
35 GetCursorInfo
= (GETCURSORINFO
)GetProcAddress(GetModuleHandleW(L
"user32.dll"), "GetCursorInfo");
38 wc
.lpszClassName
= "IconTestClass";
39 wc
.lpfnWndProc
= MainWndProc
;
40 wc
.style
= CS_VREDRAW
| CS_HREDRAW
;
41 wc
.hInstance
= hInstance
;
42 wc
.hIcon
= LoadIcon(NULL
, (LPCTSTR
)IDI_APPLICATION
);
43 wc
.hCursor
= LoadCursor(NULL
, (LPCTSTR
)IDC_ARROW
);
44 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
45 wc
.lpszMenuName
= NULL
;
48 if (RegisterClass(&wc
) == 0)
50 DbgPrint("RegisterClass failed (last error 0x%X)\n", GetLastError());
54 hWnd
= CreateWindow("IconTestClass",
56 WS_OVERLAPPEDWINDOW
|WS_HSCROLL
|WS_VSCROLL
,
67 DbgPrint("CreateWindow failed (last error 0x%X)\n", GetLastError());
71 tf
= CreateFontA(14,0, 0, TA_BASELINE
, FW_NORMAL
, FALSE
, FALSE
, FALSE
,
72 ANSI_CHARSET
, OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
73 DEFAULT_QUALITY
, FIXED_PITCH
|FF_DONTCARE
, "Timmons");
75 ShowWindow(hWnd
, nCmdShow
);
77 SetTimer(hWnd
, 1, 1000, NULL
);
79 while(GetMessage(&msg
, NULL
, 0, 0))
81 TranslateMessage(&msg
);
82 DispatchMessage(&msg
);
88 LRESULT CALLBACK
MainWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
95 CURSORINFO cursorinfo
;
104 hDC
= BeginPaint(hWnd
, &ps
);
105 SelectObject(hDC
, tf
);
106 SetBkMode(hDC
, TRANSPARENT
);
108 TextOut(hDC
, 160, 10, file
, strlen(file
));
109 TextOut(hDC
, 15, 85, titleDrwIco
, strlen(titleDrwIco
));
110 TextOut(hDC
, 160, 85, titleMask
, strlen(titleMask
));
111 TextOut(hDC
, 300, 85, titleXor
, strlen(titleXor
));
113 hIcon
= LoadImage(NULL
, "icon.ico", IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
|LR_LOADFROMFILE
);
114 DrawIcon(hDC
,50,50,hIcon
);
116 hMemDC
= CreateCompatibleDC(hDC
);
117 GetIconInfo(hIcon
, &iconinfo
);
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
);
125 DeleteObject(iconinfo
.hbmMask
);
126 DeleteObject(iconinfo
.hbmColor
);
128 TextOut(hDC
, 145, 150, res
, strlen(res
));
129 TextOut(hDC
, 15, 225, titleDrwIco
, strlen(titleDrwIco
));
130 TextOut(hDC
, 160, 225, titleMask
, strlen(titleMask
));
131 TextOut(hDC
, 300, 225, titleXor
, strlen(titleXor
));
133 hIcon
= LoadImage(hInst
, MAKEINTRESOURCE(IDI_ICON
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
134 DrawIcon(hDC
,50,190,hIcon
);
136 GetIconInfo(hIcon
, &iconinfo
);
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
);
144 DeleteObject(iconinfo
.hbmMask
);
145 DeleteObject(iconinfo
.hbmColor
);
147 cursorinfo
.cbSize
= sizeof(CURSORINFO
);
148 if(GetCursorInfo(&cursorinfo
))
150 if(cursorinfo
.hCursor
&& cursorinfo
.flags
)
152 TextOut(hDC
, 160, 290, cursor
, strlen(cursor
));
153 DrawIcon(hDC
, 50, 330, cursorinfo
.hCursor
);
154 GetIconInfo(cursorinfo
.hCursor
, &iconinfo
);
155 TextOut(hDC
, 15, 365, titleDrwIco
, strlen(titleDrwIco
));
157 sprintf(str
, "Hotspot: %ld; %ld", iconinfo
.xHotspot
, iconinfo
.yHotspot
);
158 TextOut(hDC
, 15, 380, str
, strlen(str
));
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
));
168 sprintf(str
, "%dBPP", bmp
.bmBitsPixel
);
169 TextOut(hDC
, 160, 380 - 32 + bmp
.bmHeight
, str
, strlen(str
));
172 if(iconinfo
.hbmColor
)
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
));
180 sprintf(str
, "%dBPP", bmp
.bmBitsPixel
);
181 TextOut(hDC
, 300, 380 - 32 + bmp
.bmHeight
, str
, strlen(str
));
186 SelectObject(hMemDC
, hOld
);
188 DeleteObject(hMemDC
);
197 InvalidateRect(hWnd
, &rc
, TRUE
);
205 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);