10 const char titleDrwIco
[] = "DrawIcon Output";
11 const char titleMask
[] = "Mask(AND image)";
12 const char titleXor
[] = "XOR(color image)";
13 const char file
[] = "Icon from file:";
14 const char res
[] = "Icon from Resorce:";
15 const char cursor
[] = "Current Cursor:";
16 const char cursormask
[] = "Cursor Mask Bitmap";
17 const char cursorcolor
[] = "Cursor Color Bitmap";
20 typedef BOOL (__stdcall
*GETCURSORINFO
) (CURSORINFO
*CursorInfo
);
22 static GETCURSORINFO GetCursorInfo
= NULL
;
28 LRESULT WINAPI
MainWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
31 WinMain(HINSTANCE hInstance
,
32 HINSTANCE hPrevInstance
,
43 GetCursorInfo
= (GETCURSORINFO
)GetProcAddress(GetModuleHandleW(L
"user32.dll"), "GetCursorInfo");
46 wc
.lpszClassName
= "IconTestClass";
47 wc
.lpfnWndProc
= MainWndProc
;
48 wc
.style
= CS_VREDRAW
| CS_HREDRAW
;
49 wc
.hInstance
= hInstance
;
50 wc
.hIcon
= LoadIcon(NULL
, (LPCTSTR
)IDI_APPLICATION
);
51 wc
.hCursor
= LoadCursor(NULL
, (LPCTSTR
)IDC_ARROW
);
52 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
53 wc
.lpszMenuName
= NULL
;
56 if (RegisterClass(&wc
) == 0)
58 DbgPrint("RegisterClass failed (last error 0x%X)\n", GetLastError());
62 hWnd
= CreateWindow("IconTestClass",
64 WS_OVERLAPPEDWINDOW
|WS_HSCROLL
|WS_VSCROLL
,
75 DbgPrint("CreateWindow failed (last error 0x%X)\n", GetLastError());
79 tf
= CreateFontA(14,0, 0, TA_BASELINE
, FW_NORMAL
, FALSE
, FALSE
, FALSE
,
80 ANSI_CHARSET
, OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
81 DEFAULT_QUALITY
, FIXED_PITCH
|FF_DONTCARE
, "Timmons");
83 ShowWindow(hWnd
, nCmdShow
);
85 SetTimer(hWnd
, 1, 1000, NULL
);
87 while(GetMessage(&msg
, NULL
, 0, 0))
89 TranslateMessage(&msg
);
90 DispatchMessage(&msg
);
96 LRESULT CALLBACK
MainWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
103 CURSORINFO cursorinfo
;
112 hDC
= BeginPaint(hWnd
, &ps
);
113 SelectObject(hDC
, tf
);
114 SetBkMode(hDC
, TRANSPARENT
);
116 TextOut(hDC
, 160, 10, file
, strlen(file
));
117 TextOut(hDC
, 15, 85, titleDrwIco
, strlen(titleDrwIco
));
118 TextOut(hDC
, 160, 85, titleMask
, strlen(titleMask
));
119 TextOut(hDC
, 300, 85, titleXor
, strlen(titleXor
));
121 hIcon
= LoadImage(NULL
, "icon.ico", IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
|LR_LOADFROMFILE
);
122 DrawIcon(hDC
,50,50,hIcon
);
124 hMemDC
= CreateCompatibleDC(hDC
);
125 GetIconInfo(hIcon
, &iconinfo
);
128 hOld
= SelectObject(hMemDC
, iconinfo
.hbmMask
);
129 BitBlt(hDC
, 200, 50, 32, 32, hMemDC
, 0, 0, SRCCOPY
);
130 SelectObject(hMemDC
, iconinfo
.hbmColor
);
131 BitBlt(hDC
, 350, 50, 32, 32, hMemDC
, 0, 0, SRCCOPY
);
133 DeleteObject(iconinfo
.hbmMask
);
134 DeleteObject(iconinfo
.hbmColor
);
136 TextOut(hDC
, 145, 150, res
, strlen(res
));
137 TextOut(hDC
, 15, 225, titleDrwIco
, strlen(titleDrwIco
));
138 TextOut(hDC
, 160, 225, titleMask
, strlen(titleMask
));
139 TextOut(hDC
, 300, 225, titleXor
, strlen(titleXor
));
141 hIcon
= LoadImage(hInst
, MAKEINTRESOURCE(IDI_ICON
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
142 DrawIcon(hDC
,50,190,hIcon
);
144 GetIconInfo(hIcon
, &iconinfo
);
147 SelectObject(hMemDC
, iconinfo
.hbmMask
);
148 BitBlt(hDC
, 200, 190, 32, 32, hMemDC
, 0, 0, SRCCOPY
);
149 SelectObject(hMemDC
, iconinfo
.hbmColor
);
150 BitBlt(hDC
, 350, 190, 32, 32, hMemDC
, 0, 0, SRCCOPY
);
152 DeleteObject(iconinfo
.hbmMask
);
153 DeleteObject(iconinfo
.hbmColor
);
155 cursorinfo
.cbSize
= sizeof(CURSORINFO
);
156 if(GetCursorInfo(&cursorinfo
))
158 if(cursorinfo
.hCursor
&& cursorinfo
.flags
)
160 TextOut(hDC
, 160, 290, cursor
, strlen(cursor
));
161 DrawIcon(hDC
, 50, 330, cursorinfo
.hCursor
);
162 GetIconInfo(cursorinfo
.hCursor
, &iconinfo
);
163 TextOut(hDC
, 15, 365, titleDrwIco
, strlen(titleDrwIco
));
165 sprintf(str
, "Hotspot: %ld; %ld", iconinfo
.xHotspot
, iconinfo
.yHotspot
);
166 TextOut(hDC
, 15, 380, str
, strlen(str
));
170 GetObjectW(iconinfo
.hbmMask
, sizeof(BITMAP
), &bmp
);
171 SelectObject(hMemDC
, iconinfo
.hbmMask
);
172 BitBlt(hDC
, 200, 330, bmp
.bmWidth
, bmp
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
173 DeleteObject(iconinfo
.hbmMask
);
174 TextOut(hDC
, 160, 365 - 32 + bmp
.bmHeight
, cursormask
, strlen(cursormask
));
176 sprintf(str
, "%dBPP", bmp
.bmBitsPixel
);
177 TextOut(hDC
, 160, 380 - 32 + bmp
.bmHeight
, str
, strlen(str
));
180 if(iconinfo
.hbmColor
)
182 GetObjectW(iconinfo
.hbmColor
, sizeof(BITMAP
), &bmp
);
183 SelectObject(hMemDC
, iconinfo
.hbmColor
);
184 BitBlt(hDC
, 350, 330, bmp
.bmWidth
, bmp
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
185 DeleteObject(iconinfo
.hbmColor
);
186 TextOut(hDC
, 300, 365 - 32 + bmp
.bmHeight
, cursorcolor
, strlen(cursorcolor
));
188 sprintf(str
, "%dBPP", bmp
.bmBitsPixel
);
189 TextOut(hDC
, 300, 380 - 32 + bmp
.bmHeight
, str
, strlen(str
));
194 SelectObject(hMemDC
, hOld
);
196 DeleteObject(hMemDC
);
205 InvalidateRect(hWnd
, &rc
, TRUE
);
213 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);