专栏首页landvvb.net_一个半成品

vb.net_一个半成品

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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 办公用品管理系统VB——模块

    landv
  • [OHIF-Viewers]医疗数字阅片-医学影像-数字胶片直接下载,不再弹窗进行设置

    \Viewers\extensions\cornerstone\src\commandsModule.js

    landv
  • [OHIF-Viewers]医疗数字阅片-医学影像-Lodash 是一个一致性、模块化、高性能的 JavaScript 实用工具库。_.throttle(func, [wait=0], [option

    https://www.lodashjs.com/docs/lodash.throttle

    landv
  • VB6.0用GDI+保存图像为BMP\JPG\PNG\GIF格式终结版。

    鉴于之前在http://blog.csdn.net/laviewpbt/article/details/756547发布的代码很匆忙,也存在不少错误,现发布比较...

    用户1138785
  • .NET中的密钥加密

    本教程将演示如何通过System.Security.Cryptography在.NET Framework 1.1中实现对称加密/密钥加密。

    MelodyS
  • VB.NET 纯代码生成code39条形码

    ode39是条形码的一种,也被称为3 of 9 code、USD-3或者LOGMARS,由于编制简单、能够对任意长度的数据进行编码、支持设备广泛等特性而被广泛采...

    巴西_prince
  • vb.net 连接MYSQL数据库,需要MySql.Data.dll连接控件!

    '---------------------------------------------------------------------------...

    巴西_prince
  • MD5的介绍,算法和C、VB、Delphi实现

    http://download.winzheng.com/infoView/Article_861.htm

    阿敏总司令
  • 类模块——举例

    前面使用Open 进行的文件操作,使用起来不是很方便,但是FileSystemObject里的TextStream使用起来就比较方便了,知道了类之后,就可以使用...

    用户7388849
  • SqlServer 获取数据库全部字段

    用户2657851

扫码关注云+社区

领取腾讯云代金券