回答編集履歴
2
コード追加
answer
CHANGED
@@ -3,4 +3,173 @@
|
|
3
3
|
LPTSTRはプロジェクトの設定がワイド文字かマルチバイト文字かで型が変わりますね。
|
4
4
|
デフォルトはワイド文字でwchar_t型になったと思います。
|
5
5
|
|
6
|
-
[紛らわしいぞ!LPCTSTR、LPTSTR、LPSTR、LPCSTRは全部意味が違う!](https://www.usefullcode.net/2006/11/lpctstrlptstrlpstrlpcstr.html)
|
6
|
+
[紛らわしいぞ!LPCTSTR、LPTSTR、LPSTR、LPCSTRは全部意味が違う!](https://www.usefullcode.net/2006/11/lpctstrlptstrlpstrlpcstr.html)
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
猫でもわかるのコードはVC++ 5.0位のかなり古いコンパイラが対象で修正しながらやるのは結構大変そうなので、文字セットを`マルチ バイト文字セットを仕様する`にしてコマンドラインに`/Zc:strictStrings-`で、
|
11
|
+
文字リテラルをconstにしないといけないのを回避してしまうのもありではないかと思います。
|
12
|
+
|
13
|
+
```cpp
|
14
|
+
// listvw01.cpp
|
15
|
+
#pragma comment(lib, "comctl32.lib")
|
16
|
+
|
17
|
+
#define STRICT
|
18
|
+
#define ID_LISTVIEW 100
|
19
|
+
#include <windows.h>
|
20
|
+
#include <commctrl.h>
|
21
|
+
#include <tchar.h>
|
22
|
+
|
23
|
+
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
24
|
+
BOOL InitApp(HINSTANCE);
|
25
|
+
BOOL InitInstance(HINSTANCE, int);
|
26
|
+
|
27
|
+
TCHAR szClassName[] = _T("listvw01"); //ウィンドウクラス
|
28
|
+
HINSTANCE hInst;
|
29
|
+
|
30
|
+
int WINAPI _tWinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst,
|
31
|
+
LPTSTR lpsCmdLine, int nCmdShow)
|
32
|
+
{
|
33
|
+
MSG msg;
|
34
|
+
|
35
|
+
if (!InitApp(hCurInst))
|
36
|
+
return FALSE;
|
37
|
+
if (!InitInstance(hCurInst, nCmdShow))
|
38
|
+
return FALSE;
|
39
|
+
while (GetMessage(&msg, NULL, 0, 0)) {
|
40
|
+
TranslateMessage(&msg);
|
41
|
+
DispatchMessage(&msg);
|
42
|
+
}
|
43
|
+
return msg.wParam;
|
44
|
+
}
|
45
|
+
|
46
|
+
//ウィンドウ・クラスの登録
|
47
|
+
|
48
|
+
BOOL InitApp(HINSTANCE hInst)
|
49
|
+
{
|
50
|
+
WNDCLASSEX wc;
|
51
|
+
wc.cbSize = sizeof(WNDCLASSEX);
|
52
|
+
wc.style = CS_HREDRAW | CS_VREDRAW;
|
53
|
+
wc.lpfnWndProc = WndProc; //プロシージャ名
|
54
|
+
wc.cbClsExtra = 0;
|
55
|
+
wc.cbWndExtra = 0;
|
56
|
+
wc.hInstance = hInst; //インスタンス
|
57
|
+
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
58
|
+
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
59
|
+
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
|
60
|
+
wc.lpszMenuName = NULL; //メニュー名
|
61
|
+
wc.lpszClassName = (LPCTSTR)szClassName;
|
62
|
+
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
63
|
+
return (RegisterClassEx(&wc));
|
64
|
+
}
|
65
|
+
|
66
|
+
//ウィンドウの生成
|
67
|
+
|
68
|
+
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
69
|
+
{
|
70
|
+
HWND hWnd;
|
71
|
+
hInst = hInstance;
|
72
|
+
hWnd = CreateWindow(szClassName,
|
73
|
+
TEXT("猫でもわかるリストビュー"),//タイトルバーにこの名前が表示されます
|
74
|
+
WS_OVERLAPPEDWINDOW, //ウィンドウの種類
|
75
|
+
CW_USEDEFAULT, //X座標
|
76
|
+
CW_USEDEFAULT, //Y座標
|
77
|
+
CW_USEDEFAULT, //幅
|
78
|
+
CW_USEDEFAULT, //高さ
|
79
|
+
NULL,//親ウィンドウのハンドル、親を作るときはNULL
|
80
|
+
NULL,//メニューハンドル、クラスメニューを使うときはNULL
|
81
|
+
hInst,//インスタンスハンドル
|
82
|
+
NULL);
|
83
|
+
if (!hWnd)
|
84
|
+
return FALSE;
|
85
|
+
ShowWindow(hWnd, nCmdShow);
|
86
|
+
UpdateWindow(hWnd);
|
87
|
+
return TRUE;
|
88
|
+
}
|
89
|
+
|
90
|
+
//ウィンドウプロシージャ
|
91
|
+
|
92
|
+
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
93
|
+
{
|
94
|
+
int id;
|
95
|
+
static HWND hList;
|
96
|
+
LV_COLUMN lvcol;
|
97
|
+
LV_ITEM item;
|
98
|
+
|
99
|
+
switch (msg) {
|
100
|
+
case WM_CREATE:
|
101
|
+
InitCommonControls();
|
102
|
+
hList = CreateWindowEx(0,
|
103
|
+
WC_LISTVIEW, const_cast<LPTSTR>(_T("")),
|
104
|
+
WS_CHILD | WS_VISIBLE | LVS_REPORT,
|
105
|
+
0, 0, 0, 0,
|
106
|
+
hWnd,
|
107
|
+
(HMENU)ID_LISTVIEW,
|
108
|
+
hInst,
|
109
|
+
NULL);
|
110
|
+
|
111
|
+
lvcol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
|
112
|
+
lvcol.fmt = LVCFMT_LEFT;
|
113
|
+
lvcol.cx = 100;
|
114
|
+
lvcol.pszText = const_cast<LPTSTR>(_T("名前"));
|
115
|
+
lvcol.iSubItem = 0;
|
116
|
+
ListView_InsertColumn(hList, 0, &lvcol);
|
117
|
+
|
118
|
+
lvcol.cx = 200;
|
119
|
+
lvcol.pszText = const_cast<LPTSTR>(_T("住所"));
|
120
|
+
lvcol.iSubItem = 1;
|
121
|
+
ListView_InsertColumn(hList, 1, &lvcol);
|
122
|
+
|
123
|
+
item.mask = LVIF_TEXT;
|
124
|
+
item.pszText = const_cast<LPTSTR>(_T("粂井康孝"));
|
125
|
+
item.iItem = 0;
|
126
|
+
item.iSubItem = 0;
|
127
|
+
ListView_InsertItem(hList, &item);
|
128
|
+
|
129
|
+
item.pszText = const_cast<LPTSTR>(_T("北海道旭川市"));
|
130
|
+
item.iItem = 0;
|
131
|
+
item.iSubItem = 1;
|
132
|
+
ListView_SetItem(hList, &item);
|
133
|
+
|
134
|
+
item.pszText = const_cast<LPTSTR>(_T("粂井ひとみ"));
|
135
|
+
item.iItem = 1;
|
136
|
+
item.iSubItem = 0;
|
137
|
+
ListView_InsertItem(hList, &item);
|
138
|
+
|
139
|
+
item.pszText = const_cast<LPTSTR>(_T("東京都千代田区"));
|
140
|
+
item.iItem = 1;
|
141
|
+
item.iSubItem = 1;
|
142
|
+
ListView_SetItem(hList, &item);
|
143
|
+
|
144
|
+
item.pszText = const_cast<LPTSTR>(_T("粂井志麻"));
|
145
|
+
item.iItem = 2;
|
146
|
+
item.iSubItem = 0;
|
147
|
+
ListView_InsertItem(hList, &item);
|
148
|
+
|
149
|
+
item.pszText = const_cast<LPTSTR>(_T("北海道中富良野町"));
|
150
|
+
item.iItem = 2;
|
151
|
+
item.iSubItem = 1;
|
152
|
+
ListView_SetItem(hList, &item);
|
153
|
+
|
154
|
+
break;
|
155
|
+
case WM_SIZE:
|
156
|
+
MoveWindow(hList, 0, 0, LOWORD(lp), HIWORD(lp), TRUE);
|
157
|
+
break;
|
158
|
+
case WM_CLOSE:
|
159
|
+
id = MessageBox(hWnd,
|
160
|
+
_T("終了してもよいですか"),
|
161
|
+
_T("終了確認"),
|
162
|
+
MB_YESNO | MB_ICONQUESTION);
|
163
|
+
if (id == IDYES) {
|
164
|
+
DestroyWindow(hWnd);
|
165
|
+
}
|
166
|
+
break;
|
167
|
+
case WM_DESTROY:
|
168
|
+
PostQuitMessage(0);
|
169
|
+
break;
|
170
|
+
default:
|
171
|
+
return (DefWindowProc(hWnd, msg, wp, lp));
|
172
|
+
}
|
173
|
+
return 0L;
|
174
|
+
}
|
175
|
+
```
|
1
スクショを追加
answer
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+

|
2
|
+
|
1
3
|
LPTSTRはプロジェクトの設定がワイド文字かマルチバイト文字かで型が変わりますね。
|
2
4
|
デフォルトはワイド文字でwchar_t型になったと思います。
|
3
5
|
|