回答編集履歴
2
コード追加
test
CHANGED
@@ -9,3 +9,341 @@
|
|
9
9
|
|
10
10
|
|
11
11
|
[紛らわしいぞ!LPCTSTR、LPTSTR、LPSTR、LPCSTRは全部意味が違う!](https://www.usefullcode.net/2006/11/lpctstrlptstrlpstrlpcstr.html)
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
---
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
猫でもわかるのコードはVC++ 5.0位のかなり古いコンパイラが対象で修正しながらやるのは結構大変そうなので、文字セットを`マルチ バイト文字セットを仕様する`にしてコマンドラインに`/Zc:strictStrings-`で、
|
20
|
+
|
21
|
+
文字リテラルをconstにしないといけないのを回避してしまうのもありではないかと思います。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
```cpp
|
26
|
+
|
27
|
+
// listvw01.cpp
|
28
|
+
|
29
|
+
#pragma comment(lib, "comctl32.lib")
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
#define STRICT
|
34
|
+
|
35
|
+
#define ID_LISTVIEW 100
|
36
|
+
|
37
|
+
#include <windows.h>
|
38
|
+
|
39
|
+
#include <commctrl.h>
|
40
|
+
|
41
|
+
#include <tchar.h>
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
46
|
+
|
47
|
+
BOOL InitApp(HINSTANCE);
|
48
|
+
|
49
|
+
BOOL InitInstance(HINSTANCE, int);
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
TCHAR szClassName[] = _T("listvw01"); //ウィンドウクラス
|
54
|
+
|
55
|
+
HINSTANCE hInst;
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
int WINAPI _tWinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst,
|
60
|
+
|
61
|
+
LPTSTR lpsCmdLine, int nCmdShow)
|
62
|
+
|
63
|
+
{
|
64
|
+
|
65
|
+
MSG msg;
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
if (!InitApp(hCurInst))
|
70
|
+
|
71
|
+
return FALSE;
|
72
|
+
|
73
|
+
if (!InitInstance(hCurInst, nCmdShow))
|
74
|
+
|
75
|
+
return FALSE;
|
76
|
+
|
77
|
+
while (GetMessage(&msg, NULL, 0, 0)) {
|
78
|
+
|
79
|
+
TranslateMessage(&msg);
|
80
|
+
|
81
|
+
DispatchMessage(&msg);
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
return msg.wParam;
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
//ウィンドウ・クラスの登録
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
BOOL InitApp(HINSTANCE hInst)
|
96
|
+
|
97
|
+
{
|
98
|
+
|
99
|
+
WNDCLASSEX wc;
|
100
|
+
|
101
|
+
wc.cbSize = sizeof(WNDCLASSEX);
|
102
|
+
|
103
|
+
wc.style = CS_HREDRAW | CS_VREDRAW;
|
104
|
+
|
105
|
+
wc.lpfnWndProc = WndProc; //プロシージャ名
|
106
|
+
|
107
|
+
wc.cbClsExtra = 0;
|
108
|
+
|
109
|
+
wc.cbWndExtra = 0;
|
110
|
+
|
111
|
+
wc.hInstance = hInst; //インスタンス
|
112
|
+
|
113
|
+
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
114
|
+
|
115
|
+
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
116
|
+
|
117
|
+
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
|
118
|
+
|
119
|
+
wc.lpszMenuName = NULL; //メニュー名
|
120
|
+
|
121
|
+
wc.lpszClassName = (LPCTSTR)szClassName;
|
122
|
+
|
123
|
+
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
124
|
+
|
125
|
+
return (RegisterClassEx(&wc));
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
//ウィンドウの生成
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
136
|
+
|
137
|
+
{
|
138
|
+
|
139
|
+
HWND hWnd;
|
140
|
+
|
141
|
+
hInst = hInstance;
|
142
|
+
|
143
|
+
hWnd = CreateWindow(szClassName,
|
144
|
+
|
145
|
+
TEXT("猫でもわかるリストビュー"),//タイトルバーにこの名前が表示されます
|
146
|
+
|
147
|
+
WS_OVERLAPPEDWINDOW, //ウィンドウの種類
|
148
|
+
|
149
|
+
CW_USEDEFAULT, //X座標
|
150
|
+
|
151
|
+
CW_USEDEFAULT, //Y座標
|
152
|
+
|
153
|
+
CW_USEDEFAULT, //幅
|
154
|
+
|
155
|
+
CW_USEDEFAULT, //高さ
|
156
|
+
|
157
|
+
NULL,//親ウィンドウのハンドル、親を作るときはNULL
|
158
|
+
|
159
|
+
NULL,//メニューハンドル、クラスメニューを使うときはNULL
|
160
|
+
|
161
|
+
hInst,//インスタンスハンドル
|
162
|
+
|
163
|
+
NULL);
|
164
|
+
|
165
|
+
if (!hWnd)
|
166
|
+
|
167
|
+
return FALSE;
|
168
|
+
|
169
|
+
ShowWindow(hWnd, nCmdShow);
|
170
|
+
|
171
|
+
UpdateWindow(hWnd);
|
172
|
+
|
173
|
+
return TRUE;
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
//ウィンドウプロシージャ
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
184
|
+
|
185
|
+
{
|
186
|
+
|
187
|
+
int id;
|
188
|
+
|
189
|
+
static HWND hList;
|
190
|
+
|
191
|
+
LV_COLUMN lvcol;
|
192
|
+
|
193
|
+
LV_ITEM item;
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
switch (msg) {
|
198
|
+
|
199
|
+
case WM_CREATE:
|
200
|
+
|
201
|
+
InitCommonControls();
|
202
|
+
|
203
|
+
hList = CreateWindowEx(0,
|
204
|
+
|
205
|
+
WC_LISTVIEW, const_cast<LPTSTR>(_T("")),
|
206
|
+
|
207
|
+
WS_CHILD | WS_VISIBLE | LVS_REPORT,
|
208
|
+
|
209
|
+
0, 0, 0, 0,
|
210
|
+
|
211
|
+
hWnd,
|
212
|
+
|
213
|
+
(HMENU)ID_LISTVIEW,
|
214
|
+
|
215
|
+
hInst,
|
216
|
+
|
217
|
+
NULL);
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
lvcol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
|
222
|
+
|
223
|
+
lvcol.fmt = LVCFMT_LEFT;
|
224
|
+
|
225
|
+
lvcol.cx = 100;
|
226
|
+
|
227
|
+
lvcol.pszText = const_cast<LPTSTR>(_T("名前"));
|
228
|
+
|
229
|
+
lvcol.iSubItem = 0;
|
230
|
+
|
231
|
+
ListView_InsertColumn(hList, 0, &lvcol);
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
lvcol.cx = 200;
|
236
|
+
|
237
|
+
lvcol.pszText = const_cast<LPTSTR>(_T("住所"));
|
238
|
+
|
239
|
+
lvcol.iSubItem = 1;
|
240
|
+
|
241
|
+
ListView_InsertColumn(hList, 1, &lvcol);
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
item.mask = LVIF_TEXT;
|
246
|
+
|
247
|
+
item.pszText = const_cast<LPTSTR>(_T("粂井康孝"));
|
248
|
+
|
249
|
+
item.iItem = 0;
|
250
|
+
|
251
|
+
item.iSubItem = 0;
|
252
|
+
|
253
|
+
ListView_InsertItem(hList, &item);
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
item.pszText = const_cast<LPTSTR>(_T("北海道旭川市"));
|
258
|
+
|
259
|
+
item.iItem = 0;
|
260
|
+
|
261
|
+
item.iSubItem = 1;
|
262
|
+
|
263
|
+
ListView_SetItem(hList, &item);
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
item.pszText = const_cast<LPTSTR>(_T("粂井ひとみ"));
|
268
|
+
|
269
|
+
item.iItem = 1;
|
270
|
+
|
271
|
+
item.iSubItem = 0;
|
272
|
+
|
273
|
+
ListView_InsertItem(hList, &item);
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
item.pszText = const_cast<LPTSTR>(_T("東京都千代田区"));
|
278
|
+
|
279
|
+
item.iItem = 1;
|
280
|
+
|
281
|
+
item.iSubItem = 1;
|
282
|
+
|
283
|
+
ListView_SetItem(hList, &item);
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
item.pszText = const_cast<LPTSTR>(_T("粂井志麻"));
|
288
|
+
|
289
|
+
item.iItem = 2;
|
290
|
+
|
291
|
+
item.iSubItem = 0;
|
292
|
+
|
293
|
+
ListView_InsertItem(hList, &item);
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
item.pszText = const_cast<LPTSTR>(_T("北海道中富良野町"));
|
298
|
+
|
299
|
+
item.iItem = 2;
|
300
|
+
|
301
|
+
item.iSubItem = 1;
|
302
|
+
|
303
|
+
ListView_SetItem(hList, &item);
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
break;
|
308
|
+
|
309
|
+
case WM_SIZE:
|
310
|
+
|
311
|
+
MoveWindow(hList, 0, 0, LOWORD(lp), HIWORD(lp), TRUE);
|
312
|
+
|
313
|
+
break;
|
314
|
+
|
315
|
+
case WM_CLOSE:
|
316
|
+
|
317
|
+
id = MessageBox(hWnd,
|
318
|
+
|
319
|
+
_T("終了してもよいですか"),
|
320
|
+
|
321
|
+
_T("終了確認"),
|
322
|
+
|
323
|
+
MB_YESNO | MB_ICONQUESTION);
|
324
|
+
|
325
|
+
if (id == IDYES) {
|
326
|
+
|
327
|
+
DestroyWindow(hWnd);
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
break;
|
332
|
+
|
333
|
+
case WM_DESTROY:
|
334
|
+
|
335
|
+
PostQuitMessage(0);
|
336
|
+
|
337
|
+
break;
|
338
|
+
|
339
|
+
default:
|
340
|
+
|
341
|
+
return (DefWindowProc(hWnd, msg, wp, lp));
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
return 0L;
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
```
|
1
スクショを追加
test
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
![Projectのプロパティ](3b043beffefbe91e1535397a86a87250.png)
|
2
|
+
|
3
|
+
|
4
|
+
|
1
5
|
LPTSTRはプロジェクトの設定がワイド文字かマルチバイト文字かで型が変わりますね。
|
2
6
|
|
3
7
|
デフォルトはワイド文字でwchar_t型になったと思います。
|