-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathConIcon.cpp
59 lines (51 loc) · 1.52 KB
/
ConIcon.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <Windows.h>
#include <Shlwapi.h>
#include <stdio.h>
#include <tchar.h>
#pragma comment(lib, "User32.lib")
#pragma comment(lib, "Shell32.lib")
#pragma comment(lib, "Shlwapi.lib")
int main(int argc, TCHAR* argv[])
{
TCHAR sIcon[MAX_PATH] = _T("");
for (int arg = 1; arg < argc; ++arg)
{
if (sIcon[0] == _T('\0'))
_tcscpy_s(sIcon, argv[arg]);
else
_ftprintf(stderr, _T("Unknown argument: %s\n"), argv[arg]);
}
if (sIcon[0] != _T('\0'))
{
WORD iIndex = (WORD) PathParseIconLocation(sIcon);
HINSTANCE hInstance = GetModuleHandle(NULL);
#if 1
HICON hIcon = ExtractAssociatedIcon(hInstance, sIcon, &iIndex);
#else
HICON hIcon = NULL;
PTSTR sExt = PathFindExtension(sIcon);
if (_tcsicmp(sExt, _T(".ico")) == 0)
hIcon = (HICON) LoadImage(NULL, sIcon, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
else if (_tcsicmp(sExt, _T(".exe")) == 0 || _tcsicmp(sExt, _T(".dll")) == 0)
hIcon = ExtractIcon(hInstance, sIcon, iIndex);
else
{
_ftprintf(stderr, _T("Unknown extension: %s\n"), sExt);
return 1;
}
#endif
if (hIcon == NULL)
{
_ftprintf(stderr, _T("Unable to load icon.\n"));
return 2;
}
HWND hWnd = GetConsoleWindow();
SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM) hIcon);
//DestroyIcon(hIcon);
}
else
{
// TODO Usage
}
return 0;
}