コンソールウィンドウの表示を変更するコマンドをVB.NETで作る
ShowConsoleWindow.exe [ウィンドウスタイル]
ウィンドウスタイルの値は、
0 非表示
1 普通サイズ
2 最小化
3 最大化
省略すると、元のサイズに戻す。
vbc ShowConsoleWindow.VB
Imports Microsoft.VisualBasic
Imports System
Public Class Class1
Private Declare Function GetConsoleWindow Lib "kernel32" () As Integer
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Integer, ByVal nCmdShow As Short) As Integer
Private Const SW_HIDE As Short = 0s
Private Const SW_SHOWNORMAL As Short = 1s
Private Const SW_SHOWMINIMIZED As Short = 2s
Private Const SW_SHOWMAXIMIZED As Short = 3s
Private Const SW_SHOWNOACTIVATE As Short = 4s
Private Const SW_SHOW As Short = 5s
Private Const SW_MINIMIZE As Short = 6s
Private Const SW_SHOWMINNOACTIVE As Short = 7s
Private Const SW_SHOWNA As Short = 8s
Private Const SW_RESTORE As Short = 9s
Private Const SW_SHOWDEFAULT As Short = 10s
Public Shared Function Main(ByVal CmdArgs() As String) As Integer
Dim nCmdShow As Short = SW_RESTORE
If CmdArgs.Length=0 Then
ElseIf CmdArgs.Length=1 AndAlso IsNumeric(CmdArgs(0)) Then
nCmdShow=Convert.ToInt16(CmdArgs(0))
Else
Console.WriteLine("Usage: ShowConsoleWindow [nCmdShow]")
Return 0
End If
Dim hwnd As Integer = GetConsoleWindow()
Console.WriteLine(hwnd)
If hwnd Then ShowWindow(hwnd, nCmdShow)
Return hwnd
End Function
End Class
« コンソールアプリを非表示で実行するラッパーをVB.NETで作る。(その3) | トップページ | コマンドプロンプトのコンソールログを採取するコマンドをVB.NETで作る »