スクリーンキーボード作りたいから
Windows アプリケーションの作成を参考にしてたけどそのままだとPInvoke~とか言われる。SetWindowPosとかのhWndとかの型が違うので直したげると動いた。
Imports System.Runtime.InteropServices
Public Class Form1
Public Const HWND_TOPMOST = (-1)
Public Const SWP_SHOWWINDOW = &H40&
Public Const SWP_NOSIZE = &H1&
Public Const SWP_NOMOVE = &H2&
Public Const WS_EX_NOACTIVATE = &H8000000
Public Const GWL_EXSTYLE As Long = (-20)
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, _
ByVal hWndInsertAfter As IntPtr, _
ByVal X As Integer, _
ByVal Y As Integer, _
ByVal cx As Integer, _
ByVal cy As Integer, _
ByVal uFlags As UInteger) As Boolean
End Function
<DllImport("user32.dll")> _
Private Shared Function SetWindowLong(hWnd As IntPtr, _
<MarshalAs(UnmanagedType.I4)> nIndex As Integer, _
dwNewLong As IntPtr) As Integer
End Function
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function GetWindowLong(hWnd As IntPtr, _
<MarshalAs(UnmanagedType.I4)> nIndex As Integer) As Integer
End Function
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim p As CreateParams = MyBase.CreateParams
If Not MyBase.DesignMode Then
p.ExStyle = p.ExStyle Or (WS_EX_NOACTIVATE)
End If
Return p
End Get
End Property
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim lngRet As Long = SetWindowPos(Me.Handle, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE)
Call SetWindowLong(Me.Handle, GWL_EXSTYLE, GetWindowLong(Me.Handle, GWL_EXSTYLE) Or WS_EX_NOACTIVATE)
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles ButtonEx1.Click
SendKey(Keys.A)
End Sub
End Class