listBox, listView の初期化に対応
@@ -7,6 +7,10 @@ | ||
7 | 7 | |
8 | 8 | #pragma comment(lib, "comctl32.lib") |
9 | 9 | |
10 | +#pragma comment(linker,"\"/manifestdependency:type='win32' \ | |
11 | +name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ | |
12 | +processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") | |
13 | + | |
10 | 14 | #define MAX_LOADSTRING 100 |
11 | 15 | |
12 | 16 | // グローバル変数: |
@@ -56,6 +60,13 @@ | ||
56 | 60 | return FALSE; |
57 | 61 | } |
58 | 62 | #endif |
63 | + INITCOMMONCONTROLSEX ic; | |
64 | + ic.dwSize = sizeof(INITCOMMONCONTROLSEX); | |
65 | + ic.dwICC = ICC_LISTVIEW_CLASSES; | |
66 | + if( !InitCommonControlsEx(&ic) ) | |
67 | + { | |
68 | + return FALSE; | |
69 | + } | |
59 | 70 | |
60 | 71 | hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SAMPLE)); |
61 | 72 |
@@ -537,7 +537,7 @@ | ||
537 | 537 | #region ListBox |
538 | 538 | else if (CSTypeHelper.IsDerived(fi.FieldType, typeof(ListBox))) |
539 | 539 | { |
540 | - if (!CSRCListBox.Serialize(form, (ListBox)obj, name, resIDs, out str)) continue; | |
540 | + if (!CSRCListBox.Serialize(form, (ListBox)obj, name, resIDs, out str, out init_str, ref m_InitFunction)) continue; | |
541 | 541 | } |
542 | 542 | #endregion |
543 | 543 | #region Label |
@@ -591,7 +591,7 @@ | ||
591 | 591 | #region ListView |
592 | 592 | else if (CSTypeHelper.IsDerived(fi.FieldType, typeof(ListView))) |
593 | 593 | { |
594 | - if (!CSRCListView.Serialize(form, (ListView)obj, name, resIDs, out str)) continue; | |
594 | + if (!CSRCListView.Serialize(form, (ListView)obj, name, resIDs, out str, out init_str, ref m_InitFunction)) continue; | |
595 | 595 | } |
596 | 596 | #endregion |
597 | 597 | #region TreeView |
@@ -944,10 +944,12 @@ | ||
944 | 944 | class CSRCListBox |
945 | 945 | { |
946 | 946 | #region Serialize |
947 | - public static bool Serialize(Form form, ListBox ctrl, string name, CSResID resIDs, out string buf) | |
947 | + public static bool Serialize(Form form, ListBox ctrl, string name, CSResID resIDs | |
948 | + , out string buf, out string init_buf, ref CSRCDlgInitFunction init_func) | |
948 | 949 | { |
949 | 950 | buf = ""; |
950 | - if (ctrl == null) return false; | |
951 | + init_buf = ""; | |
952 | + if (ctrl == null) return false; | |
951 | 953 | string strID = CSResID.MakeIDString("IDC_", name); |
952 | 954 | API.LBS style = (API.LBS)API.GetWindowLong(ctrl, API.GWL.GWL_STYLE) & API.LBS.MASK; |
953 | 955 | string notStyle = CSRCWindow.GetNotStyleString(ctrl); |
@@ -957,7 +959,13 @@ | ||
957 | 959 | , ctrl, null, strID, CSRCWindow.MakeStyleString(style.ToString(), notStyle)); |
958 | 960 | buf += CRLF; |
959 | 961 | |
960 | - return true; | |
962 | + foreach (var item in ctrl.Items) | |
963 | + { | |
964 | + string text = item.ToString(); | |
965 | + | |
966 | + init_func.ListBox_AddString(strID, text); | |
967 | + } | |
968 | + return true; | |
961 | 969 | } |
962 | 970 | #endregion |
963 | 971 |
@@ -1136,10 +1144,12 @@ | ||
1136 | 1144 | class CSRCListView |
1137 | 1145 | { |
1138 | 1146 | #region Serialize |
1139 | - public static bool Serialize(Form form, ListView ctrl, string name, CSResID resIDs, out string buf) | |
1140 | - { | |
1147 | + public static bool Serialize(Form form, ListView ctrl, string name, CSResID resIDs | |
1148 | + , out string buf, out string init_buf, ref CSRCDlgInitFunction init_func) | |
1149 | + { | |
1141 | 1150 | buf = ""; |
1142 | - if (ctrl == null) return false; | |
1151 | + init_buf = ""; | |
1152 | + if (ctrl == null) return false; | |
1143 | 1153 | RES.WS style = (RES.WS)API.GetWindowLong(ctrl, API.GWL.GWL_STYLE); |
1144 | 1154 | API.LVS ctrlstyle = (API.LVS)style & API.LVS.MASK; |
1145 | 1155 | style &= RES.WS.MASK; |
@@ -1153,6 +1163,33 @@ | ||
1153 | 1163 | strStyle += style.ToString().Replace(',', '|'); |
1154 | 1164 | } |
1155 | 1165 | |
1166 | + string strID = CSResID.MakeIDString("IDC_", name); | |
1167 | + foreach( ColumnHeader col in ctrl.Columns) | |
1168 | + { | |
1169 | + init_func.ListView_InsertColumn(strID, col.Index, (int)col.TextAlign, col.Width, col.Text, col.Index); | |
1170 | + } | |
1171 | + if( ctrl.Groups.Count > 0 ) | |
1172 | + { | |
1173 | + foreach (ListViewItem item in ctrl.Items) | |
1174 | + { | |
1175 | + if (item.Group == null) | |
1176 | + { | |
1177 | + init_func.ListView_InsertGroup(strID, 0, 0, "Default"); | |
1178 | + break; | |
1179 | + } | |
1180 | + } | |
1181 | + for (int i = 0; i < ctrl.Groups.Count; ++i) | |
1182 | + { | |
1183 | + ListViewGroup group = ctrl.Groups[i]; | |
1184 | + init_func.ListView_InsertGroup(strID, i+1, group.GetHashCode(), group.Header); | |
1185 | + } | |
1186 | + } | |
1187 | + foreach (ListViewItem item in ctrl.Items) | |
1188 | + { | |
1189 | + init_func.ListView_InsertItem(strID, item); | |
1190 | + } | |
1191 | + init_func.ListView_EnableGroupView(strID, ctrl.ShowGroups); | |
1192 | + | |
1156 | 1193 | return CSRCControl.Serialize(form, ctrl, name, resIDs, "SysListView32", strStyle, out buf); |
1157 | 1194 | } |
1158 | 1195 | #endregion |
@@ -2216,13 +2253,99 @@ | ||
2216 | 2253 | |
2217 | 2254 | public void ComboBox_AddString(string id, string text) |
2218 | 2255 | { |
2219 | - string buf = "SendMessage(GetDlgItem(" + hWndName + ", " + id + "), CB_ADDSTRING, 0, (LPARAM)TEXT(\"" + text + "\"));"; | |
2256 | + AddCode("SendMessage(GetDlgItem(" + hWndName + ", " + id + "), CB_ADDSTRING, 0, (LPARAM)TEXT(\"" + text + "\"));"); | |
2257 | + } | |
2258 | + public void ListBox_AddString(string id, string text) | |
2259 | + { | |
2260 | + AddCode("SendMessage(GetDlgItem(" + hWndName + ", " + id + "), LB_ADDSTRING, 0, (LPARAM)TEXT(\"" + text + "\"));"); | |
2261 | + } | |
2262 | + public void ListView_InsertColumn(string id, int index, int fmt, int cx, string text, int sub) | |
2263 | + { | |
2264 | + AddCode("{"); | |
2265 | + string buf = " LVCOLUMN col = { "; | |
2266 | + buf += "LVCF_FMT|LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM"; | |
2267 | + buf += ", 0x" + fmt.ToString("X"); | |
2268 | + buf += ", " + cx.ToString(); | |
2269 | + buf += ", TEXT(\"" + text + "\")"; | |
2270 | + buf += ", 0"; | |
2271 | + buf += ", " + sub.ToString(); | |
2272 | + buf += " };"; | |
2220 | 2273 | AddCode(buf); |
2274 | + AddCode(" ListView_InsertColumn(GetDlgItem(" + hWndName + ", " + id + "), " + index.ToString() + ", &col);" + CRLF); | |
2275 | + AddCode("}"); | |
2221 | 2276 | } |
2277 | + private void ListView_InsertItem(string id, int index, int indent, string text) | |
2278 | + { | |
2279 | + AddCode(" LVITEM item = {0};"); | |
2280 | + AddCode(" item.mask = LVIF_TEXT;"); | |
2281 | + AddCode(" item.iItem = " + index.ToString() + ";"); | |
2282 | + AddCode(" item.pszText = TEXT(\"" + text + "\");"); | |
2283 | + AddDefs("#if (_WIN32_IE >= 0x0300)"); | |
2284 | + AddCode(" item.mask |= LVIF_INDENT;"); | |
2285 | + AddCode(" item.iIndent = " + indent.ToString() + ";"); | |
2286 | + AddDefs("#endif"); | |
2287 | + } | |
2288 | + public void ListView_InsertItem(string id, ListViewItem item) | |
2289 | + { | |
2290 | + AddCode("{"); | |
2291 | + AddCode(" LVITEM item = {0};"); | |
2292 | + AddCode(" item.mask = LVIF_TEXT;"); | |
2293 | + AddCode(" item.iItem = " + item.Index.ToString() + ";"); | |
2294 | + AddCode(" item.pszText = TEXT(\"" + item.Text + "\");"); | |
2295 | + AddDefs("#if (_WIN32_IE >= 0x0300)"); | |
2296 | + AddCode(" item.mask |= LVIF_INDENT;"); | |
2297 | + AddCode(" item.iIndent = " + item.IndentCount.ToString() + ";"); | |
2298 | + AddDefs("#endif"); | |
2299 | + if( item.ListView.Groups.Count > 0 ) | |
2300 | + { | |
2301 | + AddDefs("#if (_WIN32_IE >= 0x0560)"); | |
2302 | + AddCode(" item.mask |= LVIF_GROUPID;"); | |
2303 | + if (item.Group != null) | |
2304 | + { | |
2305 | + AddCode(" item.iGroupId = " + item.Group.GetHashCode() + ";"); | |
2306 | + } | |
2307 | + else | |
2308 | + { | |
2309 | + AddCode(" item.iGroupId = 0;"); | |
2310 | + } | |
2311 | + AddDefs("#endif"); | |
2312 | + } | |
2313 | + AddCode(" ListView_InsertItem(GetDlgItem(" + hWndName + ", " + id + "), &item);"); | |
2314 | + for (int i = 1; i < item.SubItems.Count; ++i) | |
2315 | + { | |
2316 | + ListViewItem.ListViewSubItem sub = item.SubItems[i]; | |
2317 | + ListView_SetItem(id, item.Index, i, sub.Text); | |
2318 | + } | |
2319 | + AddCode("}"); | |
2320 | + } | |
2321 | + public void ListView_SetItem(string id, int index, int sub, string text) | |
2322 | + { | |
2323 | + AddCode(""); | |
2324 | + AddCode(" item.mask = LVIF_TEXT;"); | |
2325 | + AddCode(" item.iItem = " + index.ToString() + ";"); | |
2326 | + AddCode(" item.iSubItem = " + sub.ToString() + ";"); | |
2327 | + AddCode(" item.pszText = TEXT(\"" + text + "\");"); | |
2328 | + AddCode(" ListView_SetItem(GetDlgItem(" + hWndName + ", " + id + "), &item);"); | |
2329 | + } | |
2330 | + public void ListView_InsertGroup(string id, int index, int groupId, string text) | |
2331 | + { | |
2332 | + AddCode("{"); | |
2333 | + AddCode(" LVGROUP group = {0};"); | |
2334 | + AddCode(" group.cbSize = sizeof(LVGROUP);"); | |
2335 | + AddCode(" group.mask = LVGF_HEADER | LVGF_GROUPID;"); | |
2336 | + AddCode(" group.iGroupId = " + groupId.ToString() + ";"); | |
2337 | + AddCode(" group.pszHeader = TEXT(\"" + text + "\");"); | |
2338 | + AddCode(" ListView_InsertGroup(GetDlgItem(" + hWndName + ", " + id + "), " + index.ToString() + ", &group);"); | |
2339 | + AddCode("}"); | |
2340 | + } | |
2341 | + public void ListView_EnableGroupView(string id, bool enable) | |
2342 | + { | |
2343 | + AddCode("ListView_EnableGroupView(GetDlgItem(" + hWndName + ", " + id + "), " + (enable ? "TRUE" : "FALSE") + ");"); | |
2344 | + } | |
2345 | + | |
2222 | 2346 | public void SetText(string id, string text) |
2223 | 2347 | { |
2224 | - string buf = "SetDlgItemText(" + hWndName + ", " + id + ", TEXT(\"" + Regex.Escape(text) + "\"));"; | |
2225 | - AddCode(buf); | |
2348 | + AddCode("SetDlgItemText(" + hWndName + ", " + id + ", TEXT(\"" + Regex.Escape(text) + "\"));"); | |
2226 | 2349 | } |
2227 | 2350 | |
2228 | 2351 | public void AddCode(string code) |
@@ -2232,6 +2355,12 @@ | ||
2232 | 2355 | m_code += CRLF; |
2233 | 2356 | } |
2234 | 2357 | |
2358 | + public void AddDefs(string code) | |
2359 | + { | |
2360 | + m_code += code; | |
2361 | + m_code += CRLF; | |
2362 | + } | |
2363 | + | |
2235 | 2364 | public string GetCode() |
2236 | 2365 | { |
2237 | 2366 | string buf = "void " + FunctionName + "(" + FunctionArguments + ")"; |
@@ -29,6 +29,15 @@ | ||
29 | 29 | private void InitializeComponent() |
30 | 30 | { |
31 | 31 | this.components = new System.ComponentModel.Container(); |
32 | + System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup("ListViewGroup", System.Windows.Forms.HorizontalAlignment.Left); | |
33 | + System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] { | |
34 | + "Hoge", | |
35 | + "X", | |
36 | + "Y", | |
37 | + "Z"}, -1); | |
38 | + System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] { | |
39 | + "Fuga", | |
40 | + "Fuga"}, -1); | |
32 | 41 | this.IDCANCEL = new System.Windows.Forms.Button(); |
33 | 42 | this.button2 = new System.Windows.Forms.Button(); |
34 | 43 | this.IDOK = new System.Windows.Forms.Button(); |
@@ -45,6 +54,9 @@ | ||
45 | 54 | this.tabPage2 = new System.Windows.Forms.TabPage(); |
46 | 55 | this.listBox1 = new System.Windows.Forms.ListBox(); |
47 | 56 | this.listView1 = new System.Windows.Forms.ListView(); |
57 | + this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); | |
58 | + this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); | |
59 | + this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); | |
48 | 60 | this.treeView1 = new System.Windows.Forms.TreeView(); |
49 | 61 | this.textBox2 = new System.Windows.Forms.TextBox(); |
50 | 62 | this.textBox3 = new System.Windows.Forms.TextBox(); |
@@ -230,15 +242,42 @@ | ||
230 | 242 | // |
231 | 243 | // listView1 |
232 | 244 | // |
233 | - this.listView1.Location = new System.Drawing.Point(137, 408); | |
245 | + this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { | |
246 | + this.columnHeader1, | |
247 | + this.columnHeader2, | |
248 | + this.columnHeader3}); | |
249 | + listViewGroup1.Header = "ListViewGroup"; | |
250 | + listViewGroup1.Name = "listViewGroup1"; | |
251 | + this.listView1.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] { | |
252 | + listViewGroup1}); | |
253 | + listViewItem2.Group = listViewGroup1; | |
254 | + this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] { | |
255 | + listViewItem1, | |
256 | + listViewItem2}); | |
257 | + this.listView1.Location = new System.Drawing.Point(405, 304); | |
234 | 258 | this.listView1.Name = "listView1"; |
235 | - this.listView1.Size = new System.Drawing.Size(121, 88); | |
259 | + this.listView1.Size = new System.Drawing.Size(217, 192); | |
236 | 260 | this.listView1.TabIndex = 12; |
237 | 261 | this.listView1.UseCompatibleStateImageBehavior = false; |
262 | + this.listView1.View = System.Windows.Forms.View.Details; | |
238 | 263 | // |
264 | + // columnHeader1 | |
265 | + // | |
266 | + this.columnHeader1.Text = "A"; | |
267 | + // | |
268 | + // columnHeader2 | |
269 | + // | |
270 | + this.columnHeader2.Text = "B"; | |
271 | + this.columnHeader2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; | |
272 | + // | |
273 | + // columnHeader3 | |
274 | + // | |
275 | + this.columnHeader3.Text = "C"; | |
276 | + this.columnHeader3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; | |
277 | + // | |
239 | 278 | // treeView1 |
240 | 279 | // |
241 | - this.treeView1.Location = new System.Drawing.Point(264, 408); | |
280 | + this.treeView1.Location = new System.Drawing.Point(281, 304); | |
242 | 281 | this.treeView1.Name = "treeView1"; |
243 | 282 | this.treeView1.Size = new System.Drawing.Size(118, 88); |
244 | 283 | this.treeView1.TabIndex = 13; |
@@ -265,7 +304,7 @@ | ||
265 | 304 | // textBox4 |
266 | 305 | // |
267 | 306 | this.textBox4.AcceptsReturn = true; |
268 | - this.textBox4.Location = new System.Drawing.Point(388, 408); | |
307 | + this.textBox4.Location = new System.Drawing.Point(163, 304); | |
269 | 308 | this.textBox4.Multiline = true; |
270 | 309 | this.textBox4.Name = "textBox4"; |
271 | 310 | this.textBox4.Size = new System.Drawing.Size(112, 88); |
@@ -489,6 +528,9 @@ | ||
489 | 528 | private System.Windows.Forms.ToolStripMenuItem tesuto2ToolStripMenuItem; |
490 | 529 | private System.Windows.Forms.ToolStripMenuItem テスト3ToolStripMenuItem; |
491 | 530 | private System.Windows.Forms.MaskedTextBox maskedTextBox1; |
531 | + private System.Windows.Forms.ColumnHeader columnHeader1; | |
532 | + private System.Windows.Forms.ColumnHeader columnHeader2; | |
533 | + private System.Windows.Forms.ColumnHeader columnHeader3; | |
492 | 534 | } |
493 | 535 | } |
494 | 536 |
@@ -99,7 +99,7 @@ | ||
99 | 99 | this.richTextBox1.Name = "richTextBox1"; |
100 | 100 | this.richTextBox1.Size = new System.Drawing.Size(100, 96); |
101 | 101 | this.richTextBox1.TabIndex = 5; |
102 | - this.richTextBox1.Text = ""; | |
102 | + this.richTextBox1.Text = "abcde"; | |
103 | 103 | // |
104 | 104 | // trackBar1 |
105 | 105 | // |