「Windowsのクリップボードを用いた選択コンテンツの取得」の版間の差分

Notion-MW
Notion-MW
タグ: 差し戻し済み
167行目: 167行目:
に従い、コンストラクタの冒頭に
に従い、コンストラクタの冒頭に


<syntaxhighlight lang="vb.net">this.Visible = false;
<pre class="visual">this.Visible = false;
this.WindowState = FormWindowState.Minimized;
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;</syntaxhighlight>
this.ShowInTaskbar = false;</pre>
を入れると、一見消えているように見えるが、Alt+Tabなどをすると表示されているのが見えてしまうので、自分のHWNDを対象にSW_HIDEを指定してShowWindowをすると完全に消える。
を入れると、一見消えているように見えるが、Alt+Tabなどをすると表示されているのが見えてしまうので、自分のHWNDを対象にSW_HIDEを指定してShowWindowをすると完全に消える。


<syntaxhighlight lang="vb.net">case WM_SHOWWINDOW:
<pre class="visual">case WM_SHOWWINDOW:
                 this.CenterToScreen();
                 this.CenterToScreen();
                 if ((int)message.WParam == 1)
                 if ((int)message.WParam == 1)
178行目: 178行目:
                     if (!window_init_done)
                     if (!window_init_done)
                     {//being shown
                     {//being shown
                         Console.WriteLine("Hiding");
                         Console.WriteLine(&quot;Hiding&quot;);
                         window_init_done = true;
                         window_init_done = true;
                         ShowWindow(this.Handle, SW_HIDE);
                         ShowWindow(this.Handle, SW_HIDE);
                     }
                     }
                 }
                 }
                 break;</syntaxhighlight>
                 break;</pre>
==== conhostでの実行 ====
==== conhostでの実行 ====


215行目: 215行目:
C&#35;の<code>NamedPipeClientStream</code>ではパイプの名前を<code>&quot;.&quot;</code> <code>&quot;test&quot;</code>とコンピュータ名/パイプ名で分けているのに対して(AutoHotkeyで呼び出されている)Win32 APIの関数<code>CreateNamedPipe</code>では<code>&quot;\\.\</code><strong><code>pipe\</code></strong><code>test&quot;</code>と書く必要があるようなので注意。
C&#35;の<code>NamedPipeClientStream</code>ではパイプの名前を<code>&quot;.&quot;</code> <code>&quot;test&quot;</code>とコンピュータ名/パイプ名で分けているのに対して(AutoHotkeyで呼び出されている)Win32 APIの関数<code>CreateNamedPipe</code>では<code>&quot;\\.\</code><strong><code>pipe\</code></strong><code>test&quot;</code>と書く必要があるようなので注意。


<syntaxhighlight lang="vb.net">using System;
<pre class="visual">using System;
using System.IO.Pipes;
using System.IO.Pipes;


226行目: 226行目:
     public static void Main(string[] args)
     public static void Main(string[] args)
     {
     {
       NamedPipeClientStream npcs = new NamedPipeClientStream(".", "test", PipeDirection.InOut);
       NamedPipeClientStream npcs = new NamedPipeClientStream(&quot;.&quot;, &quot;test&quot;, PipeDirection.InOut);
       npcs.Connect();
       npcs.Connect();
       byte[] dat = System.Text.Encoding.Unicode.GetBytes("XYZ");
       byte[] dat = System.Text.Encoding.Unicode.GetBytes(&quot;XYZ&quot;);
       byte[] buf = new byte[6];
       byte[] buf = new byte[6];
       if (npcs.IsConnected == true) {
       if (npcs.IsConnected == true) {
240行目: 240行目:
     }
     }
   }
   }
}</syntaxhighlight>
}</pre>
<syntaxhighlight lang="vb.net">ptr := A_PtrSize ? "Ptr" : "UInt"
<pre class="visual">ptr := A_PtrSize ? &quot;Ptr&quot; : &quot;UInt&quot;
char_size := A_IsUnicode ? 2 : 1
char_size := A_IsUnicode ? 2 : 1
pipe := DllCall("CreateNamedPipe", "str", "\\.\pipe\test", "uint", 3, "uint", 4, "uint", 10, "uint", 100, "uint", 100, "uint", 0, ptr, 0, ptr)
pipe := DllCall(&quot;CreateNamedPipe&quot;, &quot;str&quot;, &quot;\\.\pipe\test&quot;, &quot;uint&quot;, 3, &quot;uint&quot;, 4, &quot;uint&quot;, 10, &quot;uint&quot;, 100, &quot;uint&quot;, 100, &quot;uint&quot;, 0, ptr, 0, ptr)
DllCall("ConnectNamedPipe", ptr, pipe, ptr, 0)
DllCall(&quot;ConnectNamedPipe&quot;, ptr, pipe, ptr, 0)
MsgBox ConnectNamedPipe(0 is OK): %ErrorLevel%/%A_LastError%
MsgBox ConnectNamedPipe(0 is OK): %ErrorLevel%/%A_LastError%
VarSetCapacity(Buffer, char_size * 3)
VarSetCapacity(Buffer, char_size * 3)
DllCall("WriteFile", ptr, pipe, "str", "345", "uint", char_size * 3, "uint*", 0, ptr, 0)
DllCall(&quot;WriteFile&quot;, ptr, pipe, &quot;str&quot;, &quot;345&quot;, &quot;uint&quot;, char_size * 3, &quot;uint*&quot;, 0, ptr, 0)
DllCall("ReadFile", "UInt", pipe, "Str", Buffer, "UInt", char_size * 3, "UIntP", BytesRead, "UInt", 0)
DllCall(&quot;ReadFile&quot;, &quot;UInt&quot;, pipe, &quot;Str&quot;, Buffer, &quot;UInt&quot;, char_size * 3, &quot;UIntP&quot;, BytesRead, &quot;UInt&quot;, 0)
MsgBox, 64, %BytesRead%, %Buffer%</syntaxhighlight>
MsgBox, 64, %BytesRead%, %Buffer%</pre>
なお、これは一応(Windows11で)動いた例というだけで、使用されている関数の細かいパラメータやエラーハンドリング、Closeの仕方、Unicode/非Unicodeや32bit/64bitの扱い、バイト数の計算の仕方など、不完全な部分がいくつもあると思われる。
なお、これは一応(Windows11で)動いた例というだけで、使用されている関数の細かいパラメータやエラーハンドリング、Closeの仕方、Unicode/非Unicodeや32bit/64bitの扱い、バイト数の計算の仕方など、不完全な部分がいくつもあると思われる。