#相談内容
とあるRPAを自作しています。
外部アプリケーションを動かしますが、windowsのDPIが96(100%),144(150%)とか
違うためか、思った場所でマウスクリックできません。
そこでRPAにマウス座標の校正をさせるために、
エリア側で微調させるUIを設けたいと考えています。
#構想
ユーザーに、四角(半透明のWINDOW)で指定するようにしたいと思います。
#VBA
現在、USERFORMで半透明のWINDOWを作りましたが、
このサイズを右下コーナーのドラッグで動かす機能を足したいと思います。
#質問
ドラッグして動かすには何を足せばいいでしょうか?
VBA
1Option Explicit 2 3Private Declare Function GetForegroundWindow Lib "user32" () As Long 4Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long 5Private Const HWND_TOPMOST As Long = -1 6Private Const SWP_NOSIZE As Long = &H1& 7Private Const SWP_NOMOVE As Long = &H2& 8 9Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long 10Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long 11Private Declare Sub SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) 12Private Declare Sub SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Long, ByVal dwFlags As Long) 13Private Declare Sub DrawMenuBar Lib "user32" (ByVal hwnd As Long) 14 15Private Const GWL_EXSTYLE As Long = 0 ' _0 &= -20& 16Private Const WS_EX_LAYERED As Long = 0 '&H80000 17Private Const LWA_ALPHA As Long = 0 '&H2& 18Private Const WS_THICKFRAME = &H40000 19Private Const WS_MINIMIZEBOX = &H20000 20Private Const WS_MAXIMIZEBOX = &H10000 21 22Private Sub UserForm_Initialize() 23 24Dim myFrame As MSForms.Control 25Dim myHwnd As Long 26Dim myWindowLong As Long 27Dim myAlpha As Long 28 29myAlpha = 150 30Set myFrame = Me.Controls.Add("Forms.Frame.1") 31myHwnd = GetParent(GetParent(myFrame.[_GethWnd])) 32Me.Controls.Remove myFrame.name 33Set myFrame = Nothing 34myWindowLong = GetWindowLong(myHwnd, GWL_EXSTYLE) 35myWindowLong = myWindowLong Or WS_EX_LAYERED Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX 36SetWindowLong myHwnd, GWL_EXSTYLE, myWindowLong 37SetLayeredWindowAttributes myHwnd, 0&, myAlpha, LWA_ALPHA 38 39With Me 40.Top = 0 41.Left = 0 42.Width = 200 43.Height = 150 44 45End With 46 47Call SetWindowPos(GetForegroundWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE) 48 49End Sub 50
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。