{"id":93,"date":"2015-11-24T05:14:00","date_gmt":"2015-11-23T20:14:00","guid":{"rendered":"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/2015\/11\/24\/c-%e3%83%90%e3%83%bc%e3%83%81%e3%83%a3%e3%83%ab%e3%83%87%e3%82%b9%e3%82%af%e3%83%88%e3%83%83%e3%83%97%e3%80%81%e3%81%a8%e3%82%8a%e3%81%82%e3%81%88%e3%81%9a%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab\/"},"modified":"2015-12-29T18:54:55","modified_gmt":"2015-12-29T09:54:55","slug":"c-%e3%83%90%e3%83%bc%e3%83%81%e3%83%a3%e3%83%ab%e3%83%87%e3%82%b9%e3%82%af%e3%83%88%e3%83%83%e3%83%97%e3%80%81%e3%81%a8%e3%82%8a%e3%81%82%e3%81%88%e3%81%9a%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab","status":"publish","type":"post","link":"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/2015\/11\/24\/c-%e3%83%90%e3%83%bc%e3%83%81%e3%83%a3%e3%83%ab%e3%83%87%e3%82%b9%e3%82%af%e3%83%88%e3%83%83%e3%83%97%e3%80%81%e3%81%a8%e3%82%8a%e3%81%82%e3%81%88%e3%81%9a%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab\/","title":{"rendered":"C# \u30d0\u30fc\u30c1\u30e3\u30eb\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u3001\u3068\u308a\u3042\u3048\u305a\u30d5\u30a1\u30a4\u30eb\u306e\u540c\u671f\u306f\u53d6\u308c\u305f"},"content":{"rendered":"<p>\u524d\u56de\u306eForm\u3092\u6700\u80cc\u9762\u306b\u3067\u304d\u305f\u3068\u3053\u308d\u304b\u3089\u306e\u7d9a\u304d\u3067\u3059\u3002<\/p>\n<p><b>Form\u3092\u5e38\u306b\u6700\u80cc\u9762\u306b\u3057\u3066\u304a\u304f\u306b\u306f<\/b><br \/><a href=\"http:\/\/non-it-salaryman.blogspot.jp\/2015\/11\/c-form.html\" target=\"_blank\">http:\/\/non-it-salaryman.blogspot.jp\/2015\/11\/c-form.html<\/a><\/p>\n<p>\u30d0\u30fc\u30c1\u30e3\u30eb\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u306b\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u6307\u5b9a\u306e\u30d5\u30a9\u30eb\u30c0\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u3068\u52d5\u6a5f\u304c\u53d6\u308c\u3066\u3044\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002\u3053\u308c\u306f\u96e3\u3057\u304f\u306a\u304f\u3001System.IO.Directory.GetFiles\u3067\u30d5\u30a1\u30a4\u30eb\u30ea\u30b9\u30c8\u3092\u53d6\u5f97\u3059\u308c\u3070OK\u3002\u3042\u3068\u306f\u30a2\u30a4\u30b3\u30f3\u3092\u751f\u6210\u3059\u308c\u3070\u3044\u3044\u308f\u3051\u3067\u3059\u3002\u30a2\u30a4\u30b3\u30f3\u306fPictureBox\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u753b\u50cf\u306e\u30bb\u30f3\u30bf\u30ea\u30f3\u30b0\u304c\u3067\u304d\u3066\u304a\u3089\u305a\u3001\u6587\u5b57\u3068\u5171\u306b\u5de6\u5bc4\u305b\u72b6\u614b\u3002\u3053\u308c\u306f\u4eca\u5f8c\u5bfe\u7b56\u3057\u3066\u3044\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001\u4e0b\u306e\u56f3\u306e\u3088\u3046\u306b\u6307\u5b9a\u30d5\u30a9\u30eb\u30c0\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u3068\u540c\u671f\u304c\u3068\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u4eca\u5f8c\u306f\u3053\u308c\u3089\u3092\u30c0\u30d6\u30eb\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u30d5\u30a1\u30a4\u30eb\u304c\u958b\u3051\u308b\u3088\u3046\u306b\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-content\/uploads\/blogger\/-jRJQI_17EpQ\/VlNwitcJ9FI\/AAAAAAAAE1o\/7xA9wyKDq3M\/s1600\/_a.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" height=\"222\" src=\"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-content\/uploads\/blogger\/-jRJQI_17EpQ\/VlNwitcJ9FI\/AAAAAAAAE1o\/7xA9wyKDq3M\/s400\/_a.png\" width=\"400\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: center;\"><\/div>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-content\/uploads\/blogger\/-z9DVK6NgxSA\/Vk_qiHfam2I\/AAAAAAAAExk\/vZ1pOcxEHK4\/s1600\/_a.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" height=\"280\" src=\"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-content\/uploads\/blogger\/-z9DVK6NgxSA\/Vk_qiHfam2I\/AAAAAAAAExk\/vZ1pOcxEHK4\/s400\/_a.png\" width=\"400\" \/><\/a><\/div>\n<p>\u4ee5\u4e0b\u304c\u30b3\u30fc\u30c9\u3002\uff08\u9577\u3044\u3067\u3059\u3002\uff09<\/p>\n<p><b>MainWindow.cs<\/b><\/p>\n<div>using System;<br \/>using System.Drawing;<br \/>using System.Windows.Forms;<br \/>using System.Runtime.InteropServices;<br \/>using System.Collections.Generic;<br \/>using System.IO;<\/p>\n<p>class Test{<br \/><span style=\"white-space: pre;\"> <\/span>static void Main(){<br \/><span style=\"white-space: pre;\">  <\/span>Application.Run(new FormMain());<br \/><span style=\"white-space: pre;\"> <\/span>}<br \/>}<\/p>\n<p>public class FormMain : Form{<br \/><span style=\"white-space: pre;\"> <\/span>private Panel pane;<br \/><span style=\"white-space: pre;\"> <\/span>private Label label;<br \/><span style=\"white-space: pre;\"> <\/span>private List&lt;IconPanel&gt; iconPaneList;<\/p>\n<p><span style=\"white-space: pre;\"> <\/span>const int WM_SYSCOMMAND = 0x0112;<br \/><span style=\"white-space: pre;\"> <\/span>const int SC_MOVE = 0xF010;<br \/><span style=\"white-space: pre;\"> <\/span>const int SC_SIZE = 0xF000;<\/p>\n<p>&nbsp; &nbsp; \/\/\u6700\u524d\u9762<br \/>&nbsp; &nbsp; [DllImport(&#8220;USER32.DLL&#8221;, CharSet=CharSet.Auto)]<br \/>&nbsp; &nbsp; private static extern System.IntPtr FindWindow(string lpClassName, string lpWindowName);<br \/>&nbsp; &nbsp; [DllImport(&#8220;USER32.DLL&#8221;, CharSet=CharSet.Auto)]<br \/>&nbsp; &nbsp; private static extern System.IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);<\/p>\n<p><span style=\"white-space: pre;\"> <\/span>\/\/Form\u5185\u3067\u81ea\u7531\u306b\u79fb\u52d5<br \/><span style=\"white-space: pre;\"> <\/span>[DllImport(&#8220;User32.dll&#8221;, EntryPoint = &#8220;SendMessage&#8221;)]<br \/><span style=\"white-space: pre;\"> <\/span>extern static int SendMessageGetTextLength(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);<br \/><span style=\"white-space: pre;\"> <\/span>[DllImport(&#8220;User32.dll&#8221;)]<br \/><span style=\"white-space: pre;\"> <\/span>public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);<br \/><span style=\"white-space: pre;\"> <\/span>[DllImport(&#8220;User32.dll&#8221;)]<br \/><span style=\"white-space: pre;\"> <\/span>public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, int lParam);<br \/><span style=\"white-space: pre;\"> <\/span>[DllImport(&#8220;User32.dll&#8221;)]<br \/><span style=\"white-space: pre;\"> <\/span>public static extern bool SetCapture(IntPtr hWnd);<br \/><span style=\"white-space: pre;\"> <\/span>[DllImport(&#8220;user32.dll&#8221;)]<br \/><span style=\"white-space: pre;\"> <\/span>public static extern bool ReleaseCapture();<\/p>\n<p><span style=\"white-space: pre;\"> <\/span>public FormMain(){<br \/><span style=\"white-space: pre;\">  <\/span>this.StartPosition = FormStartPosition.CenterScreen;<br \/><span style=\"white-space: pre;\">  <\/span>this.Width = Screen.PrimaryScreen.Bounds.Width;<br \/><span style=\"white-space: pre;\">  <\/span>this.Height = Screen.PrimaryScreen.Bounds.Height;<br \/><span style=\"white-space: pre;\">  <\/span>this.BackColor = Color.SteelBlue;<br \/><span style=\"white-space: pre;\">  <\/span>this.WindowState = FormWindowState.Maximized;<br \/><span style=\"white-space: pre;\">  <\/span>this.DoubleClick += new EventHandler(FormDoubleClicked);<br \/><span style=\"white-space: pre;\">  <\/span>this.FormBorderStyle = FormBorderStyle.None;<br \/><span style=\"white-space: pre;\">  <\/span>this.ShowInTaskbar = false;<br \/><span style=\"white-space: pre;\">  <\/span><\/p>\n<p><span style=\"white-space: pre;\">  <\/span>pane = new Panel(){<br \/><span style=\"white-space: pre;\">   <\/span>Size = new Size(200, 150),<br \/><span style=\"white-space: pre;\">   <\/span>BackColor = Color.Blue,<br \/><span style=\"white-space: pre;\">   <\/span>Location = new Point(500, 10),<br \/><span style=\"white-space: pre;\">   <\/span>Parent = this,<br \/><span style=\"white-space: pre;\">  <\/span>};<br \/><span style=\"white-space: pre;\">  <\/span>pane.MouseDown += new MouseEventHandler(this.Panel_MouseDown);<\/p>\n<p><span style=\"white-space: pre;\">  <\/span>label = new Label(){<br \/><span style=\"white-space: pre;\">   <\/span>Text = &#8220;\u3053\u308c\u306f\u4ed8\u7b8b\u7d19\u3002\u88fd\u4f5c\u4e2d&#8230;&#8221;,<br \/><span style=\"white-space: pre;\">   <\/span>Dock = DockStyle.Fill,<br \/><span style=\"white-space: pre;\">   <\/span>BackColor = Color.LightPink,<br \/><span style=\"white-space: pre;\">   <\/span>BorderStyle = BorderStyle.FixedSingle,<br \/><span style=\"white-space: pre;\">   <\/span>Parent=pane,<br \/><span style=\"white-space: pre;\">  <\/span>};<br \/><span style=\"white-space: pre;\">  <\/span>label.MouseDown += new MouseEventHandler(this.Panel_MouseDown);<\/p>\n<p><span style=\"white-space: pre;\">  <\/span>this.showIcon();<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; System.IntPtr hProgramManagerHandle = FindWindow(null, &#8220;Program Manager&#8221;);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u6b63\u3057\u304f\u53d6\u5f97\u3067\u304d\u305f\u5834\u5408\u306f\u3001Program Manager \u3092\u89aa\u30a6\u30a3\u30f3\u30c9\u30a6\u306b\u8a2d\u5b9a\u3059\u308b<br \/>&nbsp; &nbsp; &nbsp; &nbsp; if (! hProgramManagerHandle.Equals(System.IntPtr.Zero)) {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetParent(this.Handle, hProgramManagerHandle);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; }<br \/><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p><span style=\"white-space: pre;\"> <\/span>private void showIcon(){<br \/><span style=\"white-space: pre;\">  <\/span>iconPaneList = new List&lt;IconPanel&gt;();<br \/><span style=\"white-space: pre;\"> <\/span><br \/><span style=\"white-space: pre;\">  <\/span>string[] files = Directory.GetFiles(&#8220;C:\\&#8230;\\desktop&#8221;);<br \/><span style=\"white-space: pre;\">  <\/span><br \/><span style=\"white-space: pre;\">  <\/span>for (int i=0; i&lt; files.Length; i++){<br \/><span style=\"white-space: pre;\">   <\/span>iconPaneList.Add(new IconPanel(files[i]));<br \/><span style=\"white-space: pre;\">   <\/span>iconPaneList[iconPaneList.Count-1].Parent = this;<br \/><span style=\"white-space: pre;\">   <\/span>iconPaneList[iconPaneList.Count-1].setting(i, 10, 10+(70*i));<br \/><span style=\"white-space: pre;\">   <\/span>iconPaneList[iconPaneList.Count-1].MouseDown += new MouseEventHandler(this.Icon_MouseDown);<br \/><span style=\"white-space: pre;\">  <\/span>}<br \/><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p><span style=\"white-space: pre;\"> <\/span>private void Panel_MouseDown(object sender, MouseEventArgs e){<br \/><span style=\"white-space: pre;\">  <\/span>SetCapture(pane.Handle);<br \/><span style=\"white-space: pre;\">  <\/span>ReleaseCapture();<br \/><span style=\"white-space: pre;\">  <\/span>SendMessage(pane.Handle, WM_SYSCOMMAND, SC_MOVE | 2, 0);<br \/><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p><span style=\"white-space: pre;\"> <\/span>private void Icon_MouseDown(object sender, MouseEventArgs e){<br \/><span style=\"white-space: pre;\">  <\/span>int index = ((IconPanel)sender).getIndex();<br \/><span style=\"white-space: pre;\">  <\/span>SetCapture(iconPaneList[index].Handle);<br \/><span style=\"white-space: pre;\">  <\/span>ReleaseCapture();<br \/><span style=\"white-space: pre;\">  <\/span>SendMessage(iconPaneList[index].Handle, WM_SYSCOMMAND, SC_MOVE | 2, 0);<br \/><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p><span style=\"white-space: pre;\"> <\/span>private void FormDoubleClicked(object sender, EventArgs e){<br \/><span style=\"white-space: pre;\">  <\/span>Application.Exit();<br \/><span style=\"white-space: pre;\"> <\/span>}<br \/>}<\/div>\n<p><b>IconPanel.cs<\/b><\/p>\n<div>using System;<br \/>using System.Drawing;<br \/>using System.Windows.Forms;<\/p>\n<p>public class IconPanel : PictureBox{<br \/><span style=\"white-space: pre;\"> <\/span>private int index;<br \/><span style=\"white-space: pre;\"> <\/span><br \/><span style=\"white-space: pre;\"> <\/span>public IconPanel(string path){<br \/><span style=\"white-space: pre;\">  <\/span>this.Size = new Size(80, 60);<br \/><span style=\"white-space: pre;\">  <\/span>this.index = -1;<\/p>\n<p><span style=\"white-space: pre;\">  <\/span>Icon appIcon = Icon.ExtractAssociatedIcon(path);<br \/><span style=\"white-space: pre;\">  <\/span>this.Image = appIcon.ToBitmap();<\/p>\n<p><span style=\"white-space: pre;\">  <\/span>Label label = new Label(){<br \/><span style=\"white-space: pre;\">   <\/span>Dock = DockStyle.Bottom,<br \/><span style=\"white-space: pre;\">   <\/span>ForeColor = Color.White,<br \/><span style=\"white-space: pre;\">   <\/span>Parent=this,<br \/><span style=\"white-space: pre;\">  <\/span>};<br \/><span style=\"white-space: pre;\">  <\/span>this.Controls.Add(label);<br \/><span style=\"white-space: pre;\">  <\/span>label.Text = System.IO.Path.GetFileName(path);<br \/><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p><span style=\"white-space: pre;\"> <\/span>public void setting(int index, int w, int y){<br \/><span style=\"white-space: pre;\">  <\/span>this.index = index;<br \/><span style=\"white-space: pre;\">  <\/span>this.Location = new Point(w, y);<br \/><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p><span style=\"white-space: pre;\"> <\/span>public int getIndex(){ return index; }<br \/>}<\/div>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306eForm\u3092\u6700\u80cc\u9762\u306b\u3067\u304d\u305f\u3068\u3053\u308d\u304b\u3089\u306e\u7d9a\u304d\u3067\u3059\u3002 Form\u3092\u5e38\u306b\u6700\u80cc\u9762\u306b\u3057\u3066 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,5],"tags":[],"class_list":["post-93","post","type-post","status-publish","format-standard","hentry","category-csharp","category-ownappli"],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-json\/wp\/v2\/posts\/93","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-json\/wp\/v2\/comments?post=93"}],"version-history":[{"count":1,"href":"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-json\/wp\/v2\/posts\/93\/revisions"}],"predecessor-version":[{"id":297,"href":"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-json\/wp\/v2\/posts\/93\/revisions\/297"}],"wp:attachment":[{"href":"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-json\/wp\/v2\/media?parent=93"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-json\/wp\/v2\/categories?post=93"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pineplanter.moo.jp\/non-it-salaryman\/wp-json\/wp\/v2\/tags?post=93"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}