Private Function LparamToScreenPositionXY(ByVal X As Long, ByVal Y As Long) As Int32
LparamToScreenPositionXY = (Y And &HFFFF&) * &H10000 Or (X And &HFFFF&)
' 좌표를 합친 롱 값을 만든다. 마우스 클릭 메시지 보낼때 필요한 좌표 정보를 만든다.
End Function
Dim rc As RECT
<StructLayout(LayoutKind.Sequential)>
Public Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure
Private Const WM_LBUTTONDOWN As Int32 = &H201
Private Const WM_LBUTTONUP As Int32 = &H202
Dim img As String = ImageSearch(rc.left, rc.top, rc.right, rc.bottom, "*TransFF00FF *50 " & Application.StartupPath & "\" & img & ".png")
'투명값 : *TransFF00FF
'오차율 : *50
'Application.StartupPath : 응용 프로그램의 실행 경로
Dim imgData() As String = Split(Marshal.PtrToStringAnsi(img), "|")
'이미지 서치 결과값 0번 = 결과 성공1 실패0 1,2번 = x,y 3,4번 = 이미지의 세로가로길이
'참고 링크 https://blog.naver.com/134686/220944621041
Dim client As String = FindWindow(ClassName, WindowName)
Dim clientEX As String = FindWindowEx(client, 0&, ClassName, WindowName)
' FindWindow FindWindowEX 사용법
' https://writes.tistory.com/entry/VBNET-FindWindow-FindWindowEX-API 참고
Dim p As Point
GetWindowRect(client, rc)
'GetWindowRect(clientEX, rc)
If imgData(0) = 1 Then
p.X = imgData(1)
p.Y = imgData(2)
'좌표값
ScreenToClient(client, p)
'ScreenToClient(clientEX, p)
SendMessage(client, WM_LBUTTONDOWN, &H1, LparamToScreenPositionXY(p.X, p.Y))
SendMessage(client, WM_LBUTTONUP, &H0, LparamToScreenPositionXY(p.X, p.Y))
'PostMessage
End If
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Auto Function FindWindowEx Lib "user32.dll" (
ByVal hwndParent As IntPtr,
ByVal hwndChildAfter As IntPtr,
ByVal lpszClass As String,
ByVal lpszWindow As String
) As IntPtr
Dim NoteFind As String
Dim NoteFindEx As String
NoteFind = FindWindow("Notepad", "테스트용 - Windows 메모장")
NoteFindEx = FindWindowEx(NoteFind, 0&, "Edit", vbNullString)
Private Const VK_H As Short = 72 Private Const VK_E As Short = 69 Private Const VK_L As Short = 76 Private Const VK_O As Short = 79
Private Const KEYEVENTF_KEYUP As Integer = &H2 Private Const INPUT_MOUSE As Integer = 0 Private Const INPUT_KEYBOARD As Integer = 1 Private Const INPUT_HARDWARE As Integer = 2
Private Structure MOUSEINPUT Public dx As Integer Public dy As Integer Public mouseData As Integer Public dwFlags As Integer Public time As Integer Public dwExtraInfo As IntPtr End Structure
Private Structure KEYBDINPUT Public wVk As Short Public wScan As Short Public dwFlags As Integer Public time As Integer Public dwExtraInfo As IntPtr End Structure
Private Structure HARDWAREINPUT Public uMsg As Integer Public wParamL As Short Public wParamH As Short End Structure
<StructLayout(LayoutKind.Explicit)> Private Structure INPUT <FieldOffset(0)> Public type As Integer <FieldOffset(4)> Public mi As MOUSEINPUT <FieldOffset(4)> Public ki As KEYBDINPUT <FieldOffset(4)> Public hi As HARDWAREINPUT End Structure
Private Declare Function SendInput Lib "user32" (ByVal nInputs As Integer, ByVal pInputs() As INPUT, ByVal cbSize As Integer) As Integer Private Declare Function AttachThreadInput Lib "user32" (ByVal idAttach As IntPtr, ByVal idAttachTo As IntPtr, ByVal fAttach As Boolean) As Boolean Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As IntPtr, ByVal lpwdProcessId As IntPtr) As IntPtr Private Declare Function GetCurrentThreadId Lib "kernel32" () As IntPtr Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As IntPtr) As Boolean
Private Sub SendKey(ByVal bKey As Short) Dim GInput(1) As INPUT
Private Const VK_0 As Short = 48 Private Const VK_1 As Short = 49 Private Const VK_2 As Short = 50 Private Const VK_3 As Short = 51 Private Const VK_4 As Short = 52 Private Const VK_5 As Short = 53 Private Const VK_6 As Short = 54 Private Const VK_7 As Short = 55 Private Const VK_8 As Short = 56 Private Const VK_9 As Short = 57 Private Const VK_Et As Short = 13 Private Const VK_Dn As Short = 40
Sub Main(key As Short) 'Dim notepad As Process = Process.Start("notepad.exe") 'If notepad.WaitForInputIdle() Then
'Dim hNotePad As IntPtr = notepad.MainWindowHandle Dim hNotePad As IntPtr = FindWindow(Nothing, "####")
Dim hNoteThread As IntPtr = GetWindowThreadProcessId(hNotePad, IntPtr.Zero)
If hNoteThread <> IntPtr.Zero Then If AttachThreadInput(GetCurrentThreadId(), hNoteThread, True) Then
Public Function hubeenGet(ByVal driveletter As String) As String Dim mobjSearcher As New ManagementObjectSearcher("SELECT VolumeSerialNumber FROM Win32_LogicalDisk WHERE Name = '" & driveletter & ":'") For Each obj As ManagementObject In mobjSearcher.Get Return obj("VolumeSerialNumber") Next Return -1 End Function
Public Class Form1 Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Integer) As Integer Public Declare Function IsZoomed Lib "user32" (ByVal hwnd As Integer) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim poc() As Process = Process.GetProcesses() Dim lResult As Integer For i As Integer = 0 To poc.Length - 1 If poc(i).MainWindowTitle <> "" Then Try lResult = IsWindowVisible(poc(i).MainWindowHandle) + IsZoomed(poc(i).MainWindowHandle) If lResult > 0 Then 'If poc(i).MainWindowTitle = "캡션명" Then ListBox1.Items.Add(poc(i).MainWindowHandle) 'End If End If Catch ex As Exception MsgBox(poc(i).ProcessName.ToString & " " & ex.Message) End Try End If Next
Private Function LparamToScreenPositionXY(ByVal X As Long, ByVal Y As Long) As Long LparamToScreenPositionXY = (Y And &HFFFF&) * &H10000 Or (X And &HFFFF&)
' 좌표를 합친 롱 값을 만든다. 마우스 클릭 메시지 보낼때 필요한 좌표 정보를 만든다. End Function