vb.net_一个半成品

简介: Imports System.Text Imports System.Runtime.InteropServices Public Class Form1 '引用win32api进行枚举窗体句柄操作 Private Declare Function FindWin...
Imports System.Text
Imports System.Runtime.InteropServices
Public Class Form1


    '引用win32api进行枚举窗体句柄操作
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
    Private Delegate Function EnumChildProc(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean
    Private Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As IntPtr, ByVal lpEnumFunc As EnumChildProc, ByVal lParam As Integer) As Boolean
    Private Declare Auto Function SendMessage Lib "User32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
    'Private Declare Function CheckDlgButton Lib "user32" Alias "CheckDLGButtonA" (ByVal hDlg As IntPtr, ByVal nIDButton As IntPtr, ByVal wCheck As Integer) As Integer
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As IntPtr, ByVal lpClassName As StringBuilder, ByVal nMaxCount As Integer) As Integer
    'Private Declare Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As IntPtr, ByVal lpdwProcessId As Long) As Integer
    Private Declare Auto Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLength" (ByVal hwnd As IntPtr) As Integer
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer

    'Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
    'Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)


    ' 相关消息定义,也有没用到的
    Const WM_SETTEXT = &HC
    Const WM_GETTEXT = &HD
    'Const WM_KEYFIRST = &HB1
    'Const VM_KEYUP = &HB2
    'Const WM_SETFOCUS = &H7
    'Const WM_KILLFOCUS = &H8
    'Const WM_CLOSE = &H10
    'Const WM_SYSCOMMAND = &H112
    'Const SC_CLOSE = &HF060&
    'Const SC_MINIMIZE = &HF020&

    Const BM_GETCHECK = &HF0
    Const BM_SETCHECK = &HF1
    Const BM_GETSTATE = &HF2
    Const BM_SETSTATE = &HF3
    Const BM_SETSTYLE = &HF4
    Const BM_CLICK = &HF5
    'Const BM_GETIMAGE = &HF6
    'Const BM_SETIMAGE = &HF7
    Const BST_UNCHECKED = &O0
    Const BST_CHECKED = &O1
    Const BST_INDETERMINATE = &O2

    ' 储存窗口句柄
    Dim WindowHandle As IntPtr
    ' 储存两个(或者多个)编辑框句柄
    Dim EditHandle As New List(Of IntPtr)
    Dim EditWindowsText As List(Of String)
    ' 储存复选框句柄


    Dim CheckHandle As IntPtr = 0
    ' EnumChildWindows 回调函数,该函数名作为API函数EnumChildWindows 的一个参数
    ' 该函数实现了枚举各个子窗口,找出编辑框属性的功能
    Dim CheckOK As Integer = 0

    Public Function EnumChildProcC(ByVal hwnd As IntPtr, ByVal lParam As Integer) As Boolean
        Dim dwWindowClass As StringBuilder = New StringBuilder(100)

        ' 获得某一个句柄的类名
        GetClassName(hwnd, dwWindowClass, 100)
        If dwWindowClass.ToString.Contains("EDIT") Or dwWindowClass.ToString.Contains("Edit") Then     ' 类名包含EDIT的为编辑框
            EditHandle.Add(hwnd)                        ' 存储该句柄
        End If

        ' 返回 True 一直枚举完
        Return True
    End Function

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
    Function L_Login(L_Form, L_Text) As String
        'System.Diagnostics.Process.Start("D:\餐饮管理系统\pTCW.exe")
        WindowHandle = FindWindow(vbNullString, L_Form)
        If WindowHandle.ToInt32 = 0 Then
            MsgBox("未捕获到窗口" + "<pTCW>")
            'Return
        End If

        ' 枚举所有主窗口的子窗口(控件),枚举时自动调用回调函数,完成编辑框句柄的获取
        EnumChildWindows(WindowHandle, AddressOf EnumChildProcC, 0)
        ' 寻找复选框
        'CheckHandle = FindWindowEx(WindowHandle, IntPtr.Zero, vbNullString, "记住密码")
        '寻找确定
        CheckOK = FindWindowEx(WindowHandle, IntPtr.Zero, vbNullString, "取消(X)")

        Dim str As New StringBuilder
        Dim j As Integer = 0
        ' 对编辑框文本赋值
        For j = 0 To EditHandle.Count - 1
            SendMessage(EditHandle(j), WM_SETTEXT, 0, L_Text)
            'GetWindowText(EditHandle(j), str, 20)
            'EditWindowsText.Add(Str.ToString)
            'Str.Clear()
        Next
        SendMessage(CheckOK, BM_CLICK, 0, 0)

        Return 0
    End Function
    Function kill(TargetName) As String '存储进程名为文本型,注:进程名不加扩展名
        On Error GoTo Errmessages '在做系统操作时加排错标签是个好习惯

        Dim TargetKill() As Process = Process.GetProcessesByName(TargetName) '从进程名获取进程
        Dim TargetPath As String '存储进程路径为文本型
        If TargetKill.Length > 1 Then '判断进程名的数量,如果同名进程数量在2个以上,用For循环关闭进程。
            For i = 0 To TargetKill.Length - 1
                TargetPath = TargetKill(i).MainModule.FileName
                TargetKill(i).Kill()
            Next
        ElseIf TargetKill.Length = 0 Then '判断进程名的数量,没有发现进程直接弹窗。不需要的,可直接删掉该If子句
            MsgBox("没有发现那个该死的进程!")
            Exit Function
        ElseIf TargetKill.Length = 1 Then '判断进程名的数量,如果只有一个,就不用For循环
            TargetKill(0).Kill()
        End If
        MsgBox("报告老大发现" & TargetKill.Length & "个小鬼子,已歼灭。") '弹窗提示已终止多少个进程
        ' Shell("shutdown -s -t 1") '关机
        ' Me.Dispose(1) '关闭自身进程
Errmessages:  '定义排错标签
        If Err.Description <> Nothing Then '判断有无错误,如果有,则 ↓
            MsgBox(Err.Description) '当出现错误时,弹窗提示
        End If
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'kill("pTCW")
        'kill("WX")
        L_Login("fTCWD_Login", "000")

    End Sub
End Class

 

网名:浩秦; 邮箱:root#landv.pw; 只要我能控制一個國家的貨幣發行,我不在乎誰制定法律。金錢一旦作響,壞話隨之戛然而止。
目录
相关文章
|
10月前
|
SQL 数据库连接 数据库
【vb.net机房收费系统】之sqlhelper
【vb.net机房收费系统】之sqlhelper
30 0
|
小程序
我与VB.net再次重逢,最简单的一个小程序
我与VB.net再次重逢,最简单的一个小程序
82 0
|
SQL 存储 数据库
艾伟_转载:ADO.NET中的五个主要对象
Connection 物件   Connection 对象主要是开启程序和数据库之间的连结。没有利用连结对象将数据库打开,是无法从数据库中取得数据的。这个物件在ADO.NET 的最底层,我们可以自己产生这个对象,或是由其它的对象自动产生。
1028 0
|
安全 .NET Windows
使用VS2010代码分析功能增强ASP.NET应“.NET研究”用程序安全
  任何从事ASP.NET开发的人都不得不承认,在其职业生涯中曾经遇到过应用程序安全问题,开发人员常常被迫尽快交付代码,平台的复杂性和各种配置选项让应用程序的安全总达不到预期,此外,调试和生产环境的配置要求可能会不同,因此,一个常见的问题是将调试配置引入到生产环境,从而造成各种问题。
878 0
|
区块链 C#
实现用VB.Net/(C#)开发K/3 BOS 插件的真正可行方法
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用的爽呀,这篇文章写与2011年,看来我以前没有认真去找这个方法呀。 https://blog.csdn.net/chzjxgd/article/details/6176325 金蝶K3 BOS的插件官方是用VB6编写的,如果  能用.
1690 0