0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

!”#$%&’()QWERTYUIOP

Last updated at Posted at 2025-07-12
Set shell = CreateObject("WScript.Shell")
shell.Run """絶対パス""", 3, True
' ドラッグアンドドロップ専用VBScript
' マウス操作でペイントに円と四角形を描画

Option Explicit

Dim shell
Set shell = CreateObject("WScript.Shell")

' メイン実行
Sub Main()
    
    ' ペイントを起動
    Call StartPaint()
    
    ' ペイントをアクティブにする
    Call ActivatePaint()
    
    ' 円を描画(シンプル版に変更可能)
    ' Call DrawCircleWithDrag()
    ' 上記でうまくいかない場合は下記のシンプル版を使用
    ' Call DrawSimpleCircle()
    
    ' 四角形を描画  
    Call DrawRectangleWithDrag()
    
    ' ジグザグ線を描画
    ' Call DrawZigzagWithDrag()
    WScript.Echo "実行終了"
End Sub

' ペイント起動
Sub StartPaint()
    shell.Run "mspaint.exe", 1, False
    WScript.Sleep 3000
End Sub

' ペイントをアクティブにする
Sub ActivatePaint()
    shell.AppActivate "ペイント"
    WScript.Sleep 1000
End Sub

' PowerShellでドラッグアンドドロップを実行
Sub ExecuteDragDrop(startX, startY, endX, endY)
    Dim psCmd
    psCmd = "powershell -Command ""Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(" & startX & "," & startY & "); Start-Sleep -Milliseconds 200; Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public class Mouse { [DllImport(\""user32.dll\"")] public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); }'; [Mouse]::mouse_event(2, 0, 0, 0, 0); [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(" & endX & "," & endY & "); Start-Sleep -Milliseconds 100; [Mouse]::mouse_event(4, 0, 0, 0, 0);"""
    shell.Run psCmd, 0, True
End Sub

' 滑らかなドラッグ(複数点を通る)
Sub ExecuteSmoothDrag(startX, startY, pointsArray)
    Dim i, points, x, y
    Dim psCmd
    
    ' PowerShellコマンドを構築
    psCmd = "powershell -Command ""Add-Type -AssemblyName System.Windows.Forms; Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public class Mouse { [DllImport(\""user32.dll\"")] public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); }'; [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(" & startX & "," & startY & "); Start-Sleep -Milliseconds 200; [Mouse]::mouse_event(2, 0, 0, 0, 0);"
    
    ' 各点を追加
    points = Split(pointsArray, ";")
    For i = 0 To UBound(points)
        If points(i) <> "" Then
            Dim coords
            coords = Split(points(i), ",")
            x = coords(0)
            y = coords(1)
            psCmd = psCmd & " [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(" & x & "," & y & "); Start-Sleep -Milliseconds 30;"
        End If
    Next
    
    psCmd = psCmd & " [Mouse]::mouse_event(4, 0, 0, 0, 0);"""
    
    shell.Run psCmd, 0, True
End Sub

' 円を描画(簡略化バージョン)
Sub DrawCircleWithDrag()
    Dim centerX, centerY, radius
    Dim i, angle, x, y
    
    centerX = 600
    centerY = 400  
    radius = 80
    
    WScript.Echo "円を描画中..."
    
    ' 開始位置に移動
    Dim startX, startY
    startX = centerX + radius
    startY = centerY
    
    ' 短いPowerShellコマンドでドラッグ開始
    Dim psStart
    psStart = "powershell -Command ""Add-Type -AssemblyName System.Windows.Forms; Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public class Mouse { [DllImport(\""user32.dll\"")] public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); }'; [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(" & startX & "," & startY & "); Start-Sleep -Milliseconds 300; [Mouse]::mouse_event(2, 0, 0, 0, 0);"""
    shell.Run psStart, 0, True
    
    ' 円周上の点を段階的に移動
    For i = 1 To 36
        angle = (i * 10) * 3.14159265359 / 180
        x = centerX + Int(radius * Cos(angle))
        y = centerY + Int(radius * Sin(angle))
        
        ' 各点への移動
        Dim psMove
        psMove = "powershell -Command ""[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(" & x & "," & y & "); Start-Sleep -Milliseconds 20;"""
        shell.Run psMove, 0, True
    Next
    
    ' ドラッグ終了
    Dim psEnd
    psEnd = "powershell -Command ""Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public class Mouse { [DllImport(\""user32.dll\"")] public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); }'; [Mouse]::mouse_event(4, 0, 0, 0, 0);"""
    shell.Run psEnd, 0, True
    
    WScript.Sleep 1000
End Sub

' 四角形を描画
Sub DrawRectangleWithDrag()
    Dim startX, startY, width, height
    
    startX = 450
    startY = 300
    width = 120
    height = 100
    
    
    ' 上辺
    Call ExecuteDragDrop(startX, startY, startX + width, startY)
    WScript.Sleep 300
    
    ' 右辺
    Call ExecuteDragDrop(startX + width, startY, startX + width, startY + height)
    WScript.Sleep 300
    
    ' 下辺
    Call ExecuteDragDrop(startX + width, startY + height, startX, startY + height)
    WScript.Sleep 300
    
    ' 左辺
    Call ExecuteDragDrop(startX, startY + height, startX, startY)
    WScript.Sleep 1000
End Sub

' ジグザグ線を描画
Sub DrawZigzagWithDrag()
    Dim startX, startY, i, x, y
    Dim points
    
    startX = 500
    startY = 250
    points = ""
    
    
    ' ジグザグの座標を計算
    For i = 0 To 8
        If i Mod 2 = 0 Then
            y = startY - 30
        Else
            y = startY + 30
        End If
        x = startX + (i * 25)
        
        If points <> "" Then points = points & ";"
        points = points & x & "," & y
    Next
    
    ' 滑らかなドラッグでジグザグを描画
    Call ExecuteSmoothDrag(startX, startY, points)
    WScript.Sleep 1000
End Sub

' 直線を描画
Sub DrawLine(startX, startY, endX, endY)
    Call ExecuteDragDrop(startX, startY, endX, endY)
    WScript.Sleep 500
End Sub

' 三角形を描画
Sub DrawTriangle()
    Dim x1, y1, x2, y2, x3, y3
    
    x1 = 400: y1 = 200
    x2 = 520: y2 = 200  
    x3 = 460: y3 = 120
    
    
    Call ExecuteDragDrop(x1, y1, x2, y2)  ' 底辺
    WScript.Sleep 300
    Call ExecuteDragDrop(x2, y2, x3, y3)  ' 右辺
    WScript.Sleep 300
    Call ExecuteDragDrop(x3, y3, x1, y1)  ' 左辺
    WScript.Sleep 1000
End Sub

' シンプルな円描画(代替案)
Sub DrawSimpleCircle()
    Dim centerX, centerY, radius
    
    centerX = 600
    centerY = 400
    radius = 80
    
    
    ' 8角形で円を近似
    Call ExecuteDragDrop(centerX + radius, centerY, centerX + Int(radius * 0.7), centerY - Int(radius * 0.7))
    WScript.Sleep 100
    Call ExecuteDragDrop(centerX + Int(radius * 0.7), centerY - Int(radius * 0.7), centerX, centerY - radius)
    WScript.Sleep 100
    Call ExecuteDragDrop(centerX, centerY - radius, centerX - Int(radius * 0.7), centerY - Int(radius * 0.7))
    WScript.Sleep 100
    Call ExecuteDragDrop(centerX - Int(radius * 0.7), centerY - Int(radius * 0.7), centerX - radius, centerY)
    WScript.Sleep 100
    Call ExecuteDragDrop(centerX - radius, centerY, centerX - Int(radius * 0.7), centerY + Int(radius * 0.7))
    WScript.Sleep 100
    Call ExecuteDragDrop(centerX - Int(radius * 0.7), centerY + Int(radius * 0.7), centerX, centerY + radius)
    WScript.Sleep 100
    Call ExecuteDragDrop(centerX, centerY + radius, centerX + Int(radius * 0.7), centerY + Int(radius * 0.7))
    WScript.Sleep 100
    Call ExecuteDragDrop(centerX + Int(radius * 0.7), centerY + Int(radius * 0.7), centerX + radius, centerY)
    WScript.Sleep 500
End Sub
Sub CustomDrag(startX, startY, endX, endY)
    Call ExecuteDragDrop(startX, startY, endX, endY)
End Sub

' 複数点を通るカスタムドラッグ
Sub CustomSmoothDrag(startX, startY, pointsStr)
    Call ExecuteSmoothDrag(startX, startY, pointsStr)
End Sub

' 使用例とテスト
Sub TestDragFunctions()
    
    ' 単純な直線
    Call CustomDrag(500, 150, 700, 150)
    WScript.Sleep 500
    
    ' 対角線
    Call CustomDrag(500, 180, 700, 250)
    WScript.Sleep 500
    
    ' 曲線(複数点)
    Call CustomSmoothDrag(600, 300, "650,280;700,260;750,280;800,300")
    
End Sub

' メイン実行
Call Main()

' 追加で三角形も描画する場合はコメントアウト
' Call DrawTriangle()

Set shell = Nothing
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?