-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathImageList.c
114 lines (99 loc) · 2.77 KB
/
ImageList.c
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* CLCL
*
* ImageList.c
*
* Copyright (C) 1996-2019 by Ohno Tomoaki. All rights reserved.
* https://www.nakka.com/
*/
/* Include Files */
#define _INC_OLE
#include <windows.h>
#undef _INC_OLE
#include <commctrl.h>
#include "General.h"
#include "Format.h"
#include "Ini.h"
#include "dpi.h"
#include "resource.h"
/* Define */
#define LICONSIZE Scale(32)
#define SICONSIZE Scale(16)
/* Global Variables */
extern TCHAR work_path[];
// オプション
extern OPTION_INFO option;
/* Local Function Prototypes */
static int imagelist_icon_add(const HINSTANCE hInstance, const HIMAGELIST icon_list, const int index);
static int imagelist_fileicon_add(const HIMAGELIST icon_list, const TCHAR *path, const UINT flag);
/*
* imagelist_icon_add - イメージリストにアイコンを追加
*
* ファイルが指定されていない場合はリソースから取得
*/
static int imagelist_icon_add(const HINSTANCE hInstance, const HIMAGELIST icon_list, const int index)
{
HICON hIcon = NULL;
int ret;
hIcon = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(index), IMAGE_ICON,
SICONSIZE, SICONSIZE, 0);
// イメージリストにアイコンを追加
ret = ImageList_AddIcon(icon_list, hIcon);
DestroyIcon(hIcon);
return ret;
}
/*
* imagelist_fileicon_add - イメージリストに関連付けされたアイコンを追加
*/
static int imagelist_fileicon_add(const HIMAGELIST icon_list, const TCHAR *path, const UINT flag)
{
SHFILEINFO shfi;
HICON hIcon;
int ret;
if (SHGetFileInfo(path, SHGFI_USEFILEATTRIBUTES, &shfi, sizeof(SHFILEINFO),
SHGFI_ICON | SHGFI_SMALLICON | flag) == 0) {
return -1;
}
hIcon = shfi.hIcon;
if (hIcon == NULL) {
return -1;
}
// イメージリストにアイコンを追加
ret = ImageList_AddIcon(icon_list, hIcon);
DestroyIcon(hIcon);
return ret;
}
/*
* create_imagelist - イメージリストの作成
*/
HIMAGELIST create_imagelist(const HINSTANCE hInstance)
{
HIMAGELIST icon_list;
HICON hIcon;
int i;
BOOL free_icon;
icon_list = ImageList_Create(SICONSIZE, SICONSIZE, ILC_COLOR4 | ILC_MASK, 0, 0);
ImageList_SetBkColor(icon_list, GetSysColor(COLOR_WINDOW));
imagelist_icon_add(hInstance, icon_list, IDI_ICON_CLIPBOARD);
imagelist_icon_add(hInstance, icon_list, IDI_ICON_MAIN);
imagelist_icon_add(hInstance, icon_list, IDI_ICON_REGIST);
imagelist_icon_add(hInstance, icon_list, IDI_ICON_FOLDER);
imagelist_icon_add(hInstance, icon_list, IDI_ICON_FOLDER);
// 未定義の形式アイコン
imagelist_icon_add(hInstance, icon_list, IDI_ICON_DEFAULT);
// 形式毎のアイコン追加
for (i = 0; i < option.format_cnt; i++) {
free_icon = TRUE;
if ((hIcon = format_get_icon(i, SICONSIZE, &free_icon)) == NULL) {
imagelist_icon_add(hInstance, icon_list, IDI_ICON_DEFAULT);
} else {
ImageList_AddIcon(icon_list, hIcon);
if (free_icon == TRUE) {
DestroyIcon(hIcon);
}
}
}
return icon_list;
}
/* End of source */