Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Integer) As Integer
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
上面是會用到的 API
下面是 VB.NET 自動執行永豐易利得方法還可以自動輸入帳密
#Region "ELEADER 視窗控制函數"
Private Function LoadEleader() As Status
LoadEleader = Status.Loading
Dim c As Char
For Each c In Pwd
password.AppendChar(c)
Application.DoEvents()
Next c
LoadEleader = Status.Loading_Completed
Try
Process.Start(Path + "VUp.exe", name, password, domain)
Catch ex As Exception
LoadEleader = Status.Loading_failed
RaiseEvent EleaderStatusEvent(Status.Loading_failed, ex.Message)
End Try
End Function
Private Function Input_Pwd() As Status
LoginInputPassword = Status.eNothing
Dim lngHwnd As IntPtr
lngHwnd = FindWindow(vbNullString, "CatXP Login") '尋找視窗標題 'e-Leader
SetForegroundWindow(lngHwnd)
If (lngHwnd) Then
SendKeys.Send(Pwd)
SendKeys.Send("{ENTER}")
LoginInputPassword = Status.LoginPassword_Completed
End If
Return LoginInputPassword
End Function
Private Function Version_Management() As Boolean
'--- 版本管理 ---
Version_Management = False
Dim lngHwnd As IntPtr
lngHwnd = FindWindow(vbNullString, "版本管理")
SetForegroundWindow(lngHwnd)
If (lngHwnd) Then
'SendMessage(lngHwnd, WM_CLOSE, 0, 0)
'SendMessage(lngHwnd, WM_COMMAND, &H2015, 0)
'SendKeys.Send("{ENTER}")
'E_Status = Status.Version_Management
Version_Management = True
End If
lngHwnd = Nothing
'TabControl1.SelectedTab = TabControl1.TabPages(0)
Return Version_Management
End Function
Private Function Entry_Eleader_System() As Status
EntryEleaderSystem = Status.eNothing
Dim lngHwnd As IntPtr
lngHwnd = FindWindow(vbNullString, "e-Leader") '尋找視窗標題 'e-Leader
'SetForegroundWindow(lngHwnd)
If (lngHwnd) Then
EntryEleaderSystem = Status.EntryEleaderSystem_Completed
End If
lngHwnd = Nothing
Return EntryEleaderSystem
End Function
Public Function Exit_Eleader_System() As Boolean
Dim lngHwnd As IntPtr
lngHwnd = FindWindow(vbNullString, "e-Leader") '[4306]期貨近月技術分析 :(0) TR<420503>
SetForegroundWindow(lngHwnd)
If (lngHwnd) Then
'SendMessage(lngHwnd, WM_CLOSE, 0, 0)
SendMessage(lngHwnd, WM_COMMAND, &H2015, 0)
'SendKeys.Send("{ENTER}")
'KWindows = False
'Timer1.Enabled = False ' 計數器停止計數
Exit_Eleader_System = True
Else
Exit_Eleader_System = False
End If
'TabControl1.SelectedTab = TabControl1.TabPages(0)
Return Exit_Eleader_System
End Function
Private Function Eleader_Error() As Status
'---連線中斷---
Dim lngHwnd As IntPtr
lngHwnd = FindWindow(vbNullString, "錯誤") '[4306]期貨近月技術分析 :(0) TR<420503>
SetForegroundWindow(lngHwnd)
If (lngHwnd) Then
'SendMessage(lngHwnd, WM_CLOSE, 0, 0)
'SendMessage(lngHwnd, WM_COMMAND, &H2015, 0)
SendKeys.Send("{ENTER}")
E_Status = Status.Running_Error
End If
lngHwnd = Nothing
'TabControl1.SelectedTab = TabControl1.TabPages(0)
Return E_Status
End Function
#End Region
抓取視窗的方法可以參考 SPY++開發工具
執行永豐易利得與自動輸入帳密接需要透過 Timer 去設定時間差去執行判斷
以上程式碼僅供參考
|