Option Explicit
Const C_WorkProgress = 3
Class UI_Class
    Public Form, Tip, config, AppName
    Private Angel, hMenu1(1), hMenu2(0)
    Private Sub Create()
        Dim i, v, s, j, arr
        Set Form = Api.NewFrom()
        With Form
            Form.Caption = "软件定制337855632"
            Call Api.ECall("user32.dll", "SetWindowLongA", .hwnd, -16, Api.ECall("user32.dll", "GetWindowLongA", .hwnd, -16) And Not (&H10000 Or &H40000))
            .Move 0, 0, 0, 0
            .Width = (790 - .ScaleWidth) * Globals("Screen").TwipsPerPixelX + .Width
            .Height = (430 - .ScaleHeight) * Globals("Screen").TwipsPerPixelY + .Height
        End With
        Const Width = 100
        Const Top = 335
        Const Margin = 2
        Const UpDate = "2021-05-11"
        config = ".\Angel.ini"
        AppName = "Angel_BP"
        If CDate(UpDate) > CDate(File.ReadINI(AppName, "UpDate", config, "2020-01-01")) Then
            File.Delete config
            File.WriteINI AppName, "UpDate", UpDate, config
        End if
        Call CreateListView
        arr = Array("使用帮助", "常用功能", "会员服务", "启动游戏", "中止全部", "清除进度")
        For i = 0 To UBound(arr)
            With Form.Controls.Add("VB.CommandButton", arr(i))
                .Caption = arr(i)
                .Move 660 + 60 * (i \ 3), Top + (20 + Margin) * (i Mod 3), 60, 21
                .Visible = True
            End With
        Next
        Form.Controls("启动游戏").ToolTipText = "快捷键(F9)"
        Form.Controls("中止全部").ToolTipText = "快捷键(F10)"
        Form.Controls("清除进度").ToolTipText = "手动中止后。游戏进度会被保存以备启动继续。清除后可以完全重新开始"
        arr = Array(227, 653)   '230
        For i = 0 To UBound(arr)
            With Form.Controls.Add("VB.Line", "Line" & i)
                .X1 = arr(i)
                .X2 = .X1
                .Y1 = Top
                .Y2 = .Y1 + 65
                .BorderColor = &H555555
                .Visible = True
            End With
        Next
        arr = Array("上号间隔" & Space(6) & "秒", 5, 1, "登录重试" & Space(6) & "次", 3, 1, "服务端口" & Space(6) & "号", 8888, 0)
        For i = 0 To UBound(arr) Step 3
            s = Left(arr(i), 4)
            With Form.Controls.Add("VB.TextBox", s & "T")
                .Move 78, Top + (20 + Margin) * i \ 3, 30, 20
                .Visible = True
                .Text = File.ReadINI(AppName, s & "T.Text", config, arr(i + 1))
            End With
            With Form.Controls.Add("VB.CheckBox", s)
                .Caption = arr(i)
                .Move 10, Top + (20 + Margin) * i \ 3, 120, 20
                .Visible = True
                .Value = File.ReadINI(AppName, s & ".Value", config, arr(i + 2))
            End With
            Call Form_Event(Form.Controls(s & "T"), &H30000 * &H100, 0)
            Call Form_Event(Form.Controls(s), &H100 * &H100, 0)
        Next

        arr = Array("上号等待", 50, "同时线程", 6, "游戏降耗", 0)
        For i = 0 To UBound(arr) Step 2
            With Form.Controls.Add("VB.TextBox", arr(i))
                .Move 190, Top + (20 + Margin) * i \ 2, 30, 20
                .Visible = True
                .Text = File.ReadINI(AppName, arr(i) & ".text", config, arr(i + 1))
            End With
            With Form.Controls.Add("VB.Label", arr(i) & "L")
                .Move 130, Top + 3 + (20 + Margin) * i \ 2, 100, 20
                .Caption = arr(i) & ":"
                .Visible = True
            End With
            Call Form_Event(Form.Controls(arr(i)), &H30000 * &H100, 0)
        Next
        Form.Controls("上号等待").ToolTipText = "登录游戏时的读条时间:秒"

        arr = Array("窗口排列", "左竖叠加|左竖平铺|左横平铺|右竖叠加|右竖平铺|右横平铺", "方向按键", "上下左右|W A S D", "游戏完成", "不做处理|播放音乐|关闭电脑")
        For i = 0 To UBound(arr) Step 2
            With Form.Controls.Add("VB.Label", arr(i) & "L")
                .Move 235, Top + 3 + (20 + Margin) * i \ 2, 60, 20
                .Caption = arr(i) & ":"
                .Visible = True
            End With
            With Form.Controls.Add("VB.ComboBox", arr(i))
                .Move 235 + 60, Top + (20 + Margin) * i \ 2, 73
                .Visible = True
                Call ComboBoxStyle(Form.Controls(arr(i)), arr(i + 1), 0)
                .ListIndex = File.ReadINI(AppName, arr(i) & ".ListIndex", config, 0)
            End With
            Call Form_Event(Form.Controls(arr(i)), &H100 * &H100, 0)
        Next

        arr = Array("定时功能", "0启动辅助|0终止辅助|0关闭电脑", "异常设置", "1游戏超时|1准备超时", "其他设置", "0开机启动|0开机上号|1自动截图|1自动滑块|0飞车路径")
        For i = 0 To UBound(arr) Step 2
            With Form.Controls.Add("VB.Label", arr(i) & "L")
                .Move 375, Top + 3 + (20 + Margin) * i \ 2, 60, 20
                .Caption = arr(i) & ":"
                .Visible = True
            End With
            With Form.Controls.Add("QQSpeed.ComboList", arr(i))
                .Move 375 + 60, Top + (20 + Margin) * i \ 2, 73
                .Visible = True
                s = File.ReadINI(AppName, arr(i), config, arr(i) & "|" & arr(i + 1))
                .object.List = s
                File.WriteINI AppName, arr(i), s, config
            End With
        Next
        Form.SetEvent Form.Controls(arr(0)), Me, "ActiveXEvents", "ComboBox"

        arr = Array("使用权限", "免费使用|试用会员|登录会员", "启动方式", "提取名字|自动上号", "优化方式", "进程优化|帧数优化")
        For i = 0 To UBound(arr) Step 2
            With Form.Controls.Add("VB.Label", arr(i) & "L")
                .Move 515, Top + 3 + (20 + Margin) * i \ 2, 60, 20
                .Caption = arr(i) & ":"
                .Visible = True
            End With
            With Form.Controls.Add("VB.ComboBox", arr(i))
                .Move 515 + 60, Top + (20 + Margin) * i \ 2, 73
                .Visible = True
                Call ComboBoxStyle(Form.Controls(arr(i)), arr(i + 1), 0)
                .ListIndex = File.ReadINI(AppName, arr(i) & ".ListIndex", config, 0)
            End With
        Next
        Call Form_Event(Form.Controls("优化方式"), &H100 * &H100, 0)
        SetListView1 Form.Controls("启动方式").ListIndex
        
        Form.SetUnloadEvent Me, "Form_Unload"
        Const WM_HOTKEY = &H312
        Const WM_CLOSE = &H10
        Const WM_COMMAND = &H111
        Const WM_SIZE = &H5
        Const WM_USER = &H400
        Form.SetEventLong Form.hwnd, Array(WM_CLOSE, WM_HOTKEY, WM_COMMAND, WM_SIZE, WM_USER + 4), Me, "Form"
        Form.Show
        Call Api.ECall("user32", "RegisterHotKey", Form.hwnd, 1, 0, &H78)
        Call Api.ECall("user32", "RegisterHotKey", Form.hwnd, 2, 0, &H79)
        Call Api.ECall("user32", "RegisterHotKey", Form.hwnd, 3, 0, &H24)

    End Sub
    Private Sub Form_Event(Obj, wParam, lParam)
        Dim i, b
        Select Case TypeName(Obj)
        Case "CommandButton"
            Select Case Obj.Name
            Case "使用帮助"
                Call Window.MessageBox(Form.Hwnd, "请查阅使用说明文本,其他加QQ群:123066586", "提示", 0, 0)
            Case "常用功能"
                MsgBox "功能正在添加中!", 4096
            Case "会员服务"
                MsgBox "请登录!", 4096
            Case "清除进度"
                Globals("QQSpeed").RemoveAll
            Case Else
                Dim j, y
                With Form.Controls("ListView1").object.ListView
                    j = 0
                    y = Int(Form.Controls("同时线程").Text)
                    For i = 1 To .ListItems.Count
                        Select Case Obj.Name
                        Case "启动游戏"
                            ' j = j + 1
                            ' If .ListItems(i).Checked Then '继续游戏
                                'Call Api.ECall("kernel32.dll", "ResumeThread", Int(.ListItems(i).Tag))
                            ' ElseIf j <= y Then
                            '     .ListItems(i).Checked = True
                            '     ListView1_ItemCheck .ListItems(i)
                            ' End If
                            If .ListItems(i).Checked Then
                                j = j + 1
                            End If
                        Case "中止全部"
                            If .ListItems(i).Checked Then
                                .ListItems(i).Checked = False
                                ListView1_ItemCheck .ListItems(i)
                            End If
                        End Select
                    Next
                    If Obj.Name = "启动游戏" Then
                        For i = 1 To .ListItems.Count
                            If j >= y Then Exit For
                            If Not .ListItems(i).Checked Then
                                b = True
                                If Globals("QQSpeed").Exists(i - 1) Then
                                    b = Globals("QQSpeed").Item(i - 1)(0)(C_WorkProgress + 3) = 0
                                End If
                                If b Then
                                    .ListItems(i).Checked = True
                                    ListView1_ItemCheck .ListItems(i)
                                    j = j + 1
                                End If
                            End If
                        Next
                    End If
                End With
            End Select
        Case "CheckBox"
            Select Case Obj.Name

            End Select
            File.WriteINI AppName, Obj.Name & ".Value", Obj.Value, config
        Case "TextBox"
            Select Case wParam \ &H100
            Case &H20000
                If IsNumeric(Obj.Text) = False Then
                    Obj.Text = "0"
                ElseIf Obj.Text < 0 Then
                    Obj.Text = "0"
                End If
            Case &H30000
                File.WriteINI AppName, Obj.Name & ".Text", Obj.Text, config
            End Select
        Case "ComboBox"
            Select Case wParam \ &H100
            Case &H100
                Select Case Obj.Name
                Case "使用权限"
                Case "启动方式"
                    If Obj.ListIndex = 1 Then
                        If Angel.Vip Is Nothing Then
                            Obj.ListIndex = 0
                            Exit Sub
                        End If
                    End If
                    Form.Controls("ListView1").object.ListView.OLEDropMode = Obj.ListIndex
                    SetListView1 Obj.ListIndex
                End Select
                File.WriteINI AppName, Obj.Name & ".ListIndex", Obj.ListIndex, config
            End Select
        End Select
    End Sub
    Public Sub Form_GetMessage(cHwnd, Message, wParam, lParam)
        Dim i, j, Obj, b
        Select Case Message
        Case &H404
            i = Globals("QQSpeed").Item(wParam - 1)(0)(C_WorkProgress + 3)
            i = IIf(i And 2, i \ &H10000, 5) * 2
            If i Then
                With Form.Controls("StatusBar").object
                    .Panels(i).Text = Int(.Panels(i).Text) + 1
                End With
            End If
            With Form.Controls("ListView1").object.ListView
                For i = wParam + 1 To .ListItems.Count
                    If .ListItems(i).Checked = False Then
                        b = True
                        If Globals("QQSpeed").Exists(i - 1) Then
                            b = Globals("QQSpeed").Item(i - 1)(0)(C_WorkProgress + 3) = 0
                        End If
                        If b Then
                            .ListItems(i).Checked = True
                            ListView1_ItemCheck .ListItems(i)
                            Exit For
                        End If
                    Else
                        j = j + 1
                    End If
                Next
            End With
            If b = False And j = 0 Then
                Select Case Form.Controls("游戏完成").ListIndex
                Case 1
                    Call Api.ECall("winmm.dll", "mciSendStringW", "open ""http://music.player.E5%90%8D%E4%BE%A6%E6%8E%A2%E6%9F%AF%E5%8D%97.mid?0.mp3"" alias mysong", 0, 0, 0)
                    Call Api.ECall("winmm.dll", "mciSendStringW", "play mysong", 0, 0, 0)
                    MsgBox "游戏已全部完成!", 4096
                    Call Api.ECall("winmm.dll", "mciSendStringW", "Close mysong", 0, 0, 0)
                Case 2
                    Const SHUTDOWN = 0
                    Const RESTART = 1
                    Const POWEROFF = 2
                    Const SE_SHUTDOWN_PRIVILEGE = 19
                    Call Api.ECall("ntdll.dll", "RtlAdjustPrivilege", SE_SHUTDOWN_PRIVILEGE, 1, 0, Api.VarPtr(i) + 8) '提权
                    Call Api.ECall("ntdll.dll", "NtShutdownSystem", SHUTDOWN)
                End Select
            End If
        Case &H10   '内置的窗口好像不响应这个'
            MsgBox "WM_CLOSE", , Message
        Case &H5 'WM_SIZE'
            If Form.WindowState = 1 Then
                'Form.Visible = False
            End If
        Case &H111 ' "WM_COMMAND"
            For Each Obj In Form.Controls
                If InStr("CommandButton|CheckBox|TextBox|ComboBox", TypeName(Obj)) Then
                    If Obj.hwnd = lParam Then
                        Form_Event Obj, wParam, lParam
                    End If
                End If
            Next
        Case &H312
            Select Case wParam
            Case 1
                Call Form_Event(Form.Controls("启动游戏"), 0, 0)
            Case 2
                Call Form_Event(Form.Controls("中止全部"), 0, 0)
            Case 3
                Call ListView1_MouseMove(1, 0, &H202 * Globals("Screen").TwipsPerPixelX, 0)
            End Select
        End Select
    End Sub

    Public Sub ComboBox_Click(byEvent, Parameters)
        Select Case Parameters(0).Value
        Case "定时功能"
            'Form.Controls(Parameters(0).Value).Object.List="测试一下|0开机启动|1自动截图|0自动重启|0自动滑块|0飞车路径"
        Case "异常设置"
            With Form.Controls(Parameters(0).Value).object
                .Tips = "|在游戏中超时没有结束|定时终止辅助"
            End With
        Case "其他设置"
        End Select
    End Sub
    Public Sub ComboBox_ItemCheck(byEvent, Parameters)
        Dim s
        With Form.Controls(Parameters(0).Value).object
            Select Case Parameters(0).Value
            Case "其他设置"
                Select Case .ComboBox.List(Parameters(1).Value)
                Case "飞车路径"
                    If .ComboBox.Selected(Parameters(1).Value) Then
                        s = Angel.SelectFile(, "请选择QQ飞车路径", ".", "支持文件(*.exe)|*.exe")
                        If Len(s) Then
                            File.WriteINI AppName, .ComboBox.List(Parameters(1).Value), s, config
                        Else
                            .ComboBox.Selected(Parameters(1).Value) = False
                            Exit Sub
                        End If
                    End If
                End Select
            End Select
            File.WriteINI AppName, Parameters(0).Value, .List, config
        End With
    End Sub

    Public Sub ComboBox_MouseMove(byEvent, Parameters)
        Dim v, s
        On Error Resume Next
        Select Case Parameters(0).Value
        Case "定时功能"

        Case "异常设置"

        Case "其他设置"
            v = Array("开机自动启动辅助", "开机自动启动辅助并开始上号刷", "出好东西自动截图", "登录飞车自动过滑块", "如果启动不了飞车。可以尝试填写安装飞车的路径")
        End Select
        With Form.Controls(Parameters(0).Value).object.ComboBox
            If .Selected(Parameters(1).Value) Then
                s = File.ReadINI(AppName, .List(Parameters(1).Value), config)
                If Len(s) Then s = .List(Parameters(1).Value) & ":" & s
            End If
            If Len(s) = 0 Then s = v(Parameters(1).Value)
            .ToolTipText = s
        End With
    End Sub
    Private Sub SetListView1(ByVal i)
        Dim v
        v = Array("序号", 50, "账号", 100, IIf(i = 0, "飞车名字", "密码"), 100, "大区", 100, "操作", 100, "提示", 100)
        With Form.Controls("ListView1").object.ListView
            Call ListView1_Clear
            .ColumnHeaders.Clear
            For i = 0 To UBound(v) Step 2
                .ColumnHeaders.Add , , v(i), v(i + 1)
            Next
            .OLEDropMode = Form.Controls("启动方式").ListIndex
            .ColumnHeaders(3).Tag = File.ReadINI(AppName, "隐藏密码.Value", config, "0")
        End With
    End Sub
    Private Function CreateMenu(hwnd, Menus)
        Dim i, hMenu, hSubMenu
        Const MF_STRING = &H0&
        Const MF_POPUP = &H10&
        Const MF_BYPOSITION = &H400&
        Const MF_SEPARATOR = &H800&
        hMenu = Api.ECall("user32.dll", "GetMenu", hwnd)
        If hMenu = 0 Then
            hMenu = Api.ECall("user32.dll", "CreateMenu")
        End If
        hSubMenu = Api.ECall("user32.dll", "CreatePopupMenu")
        Call Api.ECall("user32.dll", "AppendMenuW", hMenu, MF_STRING Or MF_BYPOSITION Or MF_POPUP, hSubMenu, Menus(0))
        For i = 0 To UBound(Menus)
            Call Api.ECall("user32.dll", "AppendMenuW", hSubMenu, MF_STRING Or MF_BYPOSITION Or IIf(Menus(i) = "-", MF_SEPARATOR, 0), i + 1, Menus(i))
        Next
        Call Api.ECall("user32.dll", "SetMenu", hwnd, hMenu)
        CreateMenu = hSubMenu
    End Function
    Private Function PopMenuClick(hwnd, Menu, x, y)
        Const TPM_RETURNCMD = &H100
        Dim Point
        Set Point = Api.Malloc(7)
        Point.SetVal x / Globals("Screen").TwipsPerPixelX, 0, 4
        Point.SetVal y / Globals("Screen").TwipsPerPixelY, 4, 8
        Call Api.ECall("user32.dll", "ClientToScreen", hwnd, Point.GetPtr(0))
        PopMenuClick = Api.ECall("user32.dll", "TrackPopupMenu", Menu, TPM_RETURNCMD, Point.ReadVal(0, 4), Point.ReadVal(4, 4), 0, hwnd, 0)
    End Function
    Private Sub CreateListView()
        Dim i, v, w, ListView
        v = Array("Licenses\ED4B87C4-9F76-11d1-8BF7-0000F8754DA1\", "knlggnmntgggrninthpgmnngrhqhnnjnslsh", "Licenses\4250E830-6AC2-11cf-8ADB-00AA00C00905\", "kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun")
        w = UBound(v)
        For i = 0 To w Step 2
            If Api.ECall("advapi32", "RegOpenKeyW", &H80000000, v(i), Api.VarPtr(w) + 8) Then
                Call Api.ECall("advapi32", "RegCreateKeyW", &H80000000, v(i), Api.VarPtr(w) + 8)
                Call Api.ECall("advapi32", "RegSetValueW", w, 0, 1, v(i + 1), Len(v(i + 1)))
            End If
            Call Api.ECall("advapi32", "RegCloseKey", w)
        Next
        If Api.CreateObject("MSComctlLib.ImageListCtrl") Is Nothing Then
            If MsgBox("系统缺少控件“mscomctl32.ocx”,是否安装?" & vbCrLf & "需要管理员权限运行!", 4096 + vbYesNo, "本电脑缺少控件") = vbYes Then
                Call Api.ECall(".\plugin\mscomctl32.ocx", "DllRegisterServer")
            End If
        End If
        Set Angel = Api.CreateObject("QQSpeed.Angel")
        If Angel Is Nothing Then
            Call Api.ECall("plugin\QQSpeed.ocx", "DllRegisterServer") '注册插件'
            Set Angel = CreateObject("QQSpeed.Angel")
        End If
        With Form.Controls.Add("QQSpeed.UI", "ListView1")
            .Visible = True
            .Width = 570
            .Height = 327
            Set ListView = .object.ListView
        End With
        Call Angel.Init(Array(jScript, Window))
        Set Tip = CreateObject("QQSpeed.Tray")
        Tip.TrayAddIcon ListView.hwnd, Globals("App").Title, Api.ECall("user32", "LoadIconW", Globals("App").hInstance, 0)
        hMenu1(0) = CreateMenu(ListView.hwnd, Array("启动选中", "中止选中", "清除进度", "-", "选择全部", "选择反向", "删除选中", "清空全部", "-", "提取名字"))
        With Form.Controls.Add("QQSpeed.UI", "ListView2")
            .Visible = True
            .Left = 570
            .Width = Form.ScaleWidth - 570
            .Height = 327
            Set ListView = .object.ListView
            ListView.MultiSelect = False
            .object.CanDrag = True
        End With
        v = Array("任务功能", 100, "局数", 50, "分钟", 50)
        For i = 0 To UBound(v) Step 2
            ListView.ColumnHeaders.Add , , v(i), v(i + 1)
        Next
        v = Split(File.ReadINI(AppName, "ListView2", config, "边境模式|50|0|1|绝命车王|2|0|1|秘境闯关|2|0|1|互助接力赛|2|0|1|酷币大作战|5|0|0|" & _
        "双人冲锋战|3|0|1|超能竞速赛|1|0|1|狂野追逐|5|0|1|变身派对|5|0|1|极速对决|4|0|1|浪漫邂逅|5|0|1|换车拉力赛|5|0|1|双人冲顶赛|5|0|1|" & _
        "全城通缉令|7|0|1|超时空巨人赛|5|0|1"), "|")
        w = 0
        hMenu2(0) = CreateMenu(ListView.hwnd, Array("选中全部", "取消全部", "反向选择"))
        For i = 0 To UBound(v) Step 4
            With ListView
                w = w + 1
                .ListItems.Add , , v(i)
                .ListItems(w).SubItems(1) = File.ReadINI(AppName, v(i) & ".局数", config, CStr(v(i + 1)))
                .ListItems(w).SubItems(2) = File.ReadINI(AppName, v(i) & ".分钟", config, CStr(v(i + 2)))
                .ListItems(w).Checked = File.ReadINI(AppName, v(i) & ".Value", config, CStr(v(i + 3)))
            End With
        Next
        Form.SetEvent Form.Controls("ListView1"), Me, "ActiveXEvent"
        Form.SetEvent Form.Controls("ListView2"), Me, "ActiveXEvent"
        '状态栏'
        v = Array("总数:", 0, "冻结:", 0, "错密:", 0, "停封:", 0, "完成:", 0)
        Form.GetLicenses.Add "MSComctlLib.SBarCtrl"
        With Form.Controls.Add("MSComctlLib.SBarCtrl", "StatusBar")
            .Visible = True
            .object.Panels.Clear
            w = UBound(v)
            w = (.Width - w) / (w + 1)
            For i = 0 To UBound(v)
                .object.Panels.Add , , v(i)
                .object.Panels(i + 1).Width = w
            Next
        End With
    End Sub
    Private Sub Import(TextFile)
        Dim i, j, zh, s
        With Form.Controls("ListView1").object.ListView
            Call ListView1_Clear
            s = Split(File.ReadTextEx(TextFile), vbCrLf)
            For i = 0 To UBound(s)
                zh = Split(s(i), "----")
                If UBound(zh) > 0 Then
                    j = j + 1
                    .ListItems.Add , , j
                    .ListItems(j).SubItems(1) = zh(0)
                    If .ColumnHeaders(3).Tag = "1" Then
                        .ListItems(j).SubItems(2) = String(Len(zh(1)), "*")
                        .ListItems(j).ListSubItems(2).Tag = zh(1)
                    Else
                        .ListItems(j).SubItems(2) = zh(1)
                    End If
                End If
            Next
            With Form.Controls("StatusBar").object
                .Panels(2).Text = j
            End With
        End With
    End Sub

    Public Sub ListView1_ColumnCheck(ColumnHeader)
        If ColumnHeader.Index = 3 And Form.Controls("启动方式").ListIndex = 1 Then
            Dim i, Index
            Index = IIf(ColumnHeader.Tag = "1", 0, 1)
            File.WriteINI AppName, "隐藏密码.Value", Index, config
            ColumnHeader.Tag = Index
            With Form.Controls("ListView1").object.ListView
                For i = 1 To .ListItems.Count
                    If Index = 1 Then
                        .ListItems(i).ListSubItems(2).Tag = .ListItems(i).SubItems(2)
                        .ListItems(i).SubItems(2) = String(Len(.ListItems(i).SubItems(2)), "*")
                    Else
                        .ListItems(i).SubItems(2) = .ListItems(i).ListSubItems(2).Tag
                    End If
                Next
            End With
        End If
    End Sub
    Public Sub ListView1_ItemEdit(x, y, Obj)
        If x = 3 Then
            Dim i, v
            v = Array(2, "电信", "联通", "电信2", "")
            For i = 0 To UBound(v)
                Obj(i) = v(i)
            Next
        End If
    End Sub
    Public Sub ListView1_DragDrop(Data, Effect, Button, Shift, x, y)
        If Data.GetFormat(15) Then Call Import(Data.Files(1))
    End Sub
    Public Sub ListView1_DragOver(Data, Effect, Button, Shift, x, y)
        Effect = Abs(Data.GetFormat(15))
    End Sub
    Public Sub ListView1_ItemClick(Item)

    End Sub
    Public Sub ListView1_ItemCheck(Item)
        If Item.Checked Then
            Dim b
            If Globals("QQSpeed").Exists(Item.Index - 1) Then
                If Globals("QQSpeed").Item(Item.Index - 1)(0)(C_WorkProgress + 3) And 1 Then
                    b = MsgBox("该账号已经完成!是否重新启动?", 4096 + 4, "账号:" & Item.Index) = 6
                End If
            Else     '没有进度
                b = True
            End If
            If b Then
                Dim i, j, c, v, arr
                With Form.Controls("ListView2").object.ListView
                    arr = Array(Array(Item.SubItems(1), IIf(Form.Controls("ListView1").object.ListView.ColumnHeaders(3).Tag = "1" And Form.Controls("启动方式").ListIndex = 1, Item.ListSubItems(2).Tag, Item.SubItems(2)), Item.SubItems(3), _
                    0, 0, 0, 0)) '进度, 句柄, 局数, 传递
                    c = .ColumnHeaders.Count
                    For i = 0 To .ListItems.Count - 1
                        If .ListItems(i + 1).Checked Then
                            ReDim v(c)
                            v(1) = .ListItems(i + 1).Text
                            For j = 1 To c - 1
                                v(j + 1) = .ListItems(i + 1).SubItems(j)
                            Next
                            ReDim Preserve arr(UBound(arr) + 1)
                            arr(UBound(arr)) = v
                        End If
                    Next
                End With
                Globals("QQSpeed").Item(Item.Index - 1) = arr
            End If
            Item.Tag = Api.CreateThread("ThreadStart " & Item.Index - 1)
        ElseIf Api.Val(Item.Tag) Then
            Api.StopThread Item.Tag
            Item.Tag = ""
        End If
    End Sub

    Public Sub ListView2_ItemChange(x, y, Obj)
        Obj.Text = Api.Val(Obj.Text)
        If Obj.Text < 0 Then Obj.Text = 0
        With Form.Controls("ListView2").object.ListView.ListItems(y)
            .Checked = (Obj.Text > 0) Or (.SubItems(IIf(x = 1, 2, 1)) > 0)
            File.WriteINI AppName, .Text & IIf(x = 1, ".局数", ".分钟"), Obj.Text, config
        End With
    End Sub
    Public Sub ListView2_ItemEdit(x, y, Obj)
        Obj(0) = 1
    End Sub
    Public Sub ListView2_DragDrop(Data, Effect, Button, Shift, x, y)
        Dim i, j, c, arr
        With Form.Controls("ListView2").object.ListView
            c = .ColumnHeaders.Count + 1
            ReDim arr(.ListItems.Count * c - 1)
            For i = 0 To .ListItems.Count - 1
                arr(i * c) = .ListItems(i + 1).Text
                For j = 1 To c - 2
                    arr(i * c + j) = .ListItems(i + 1).SubItems(j)
                Next
                arr(i * c + j) = IIf(.ListItems(i + 1).Checked, 1, 0)
            Next
        End With
        File.WriteINI AppName, "ListView2", Join(arr, "|"), config
    End Sub
    Public Sub ListView2_ItemCheck(Item)
        File.WriteINI AppName, Item.Text & ".Value", Item.Checked, config
    End Sub
    Public Sub ListView2_MouseUp(Button, Shift, x, y)
        Dim i, Index
        If Button = 2 Then
            With Form.Controls("ListView2").object.ListView
                Index = PopMenuClick(.hwnd, hMenu2(0), x, y)
                If Index = 0 Then Exit Sub
                For i = 1 To .ListItems.Count
                    If Index = 3 Then
                        .ListItems(i).Checked = Not .ListItems(i).Checked
                    Else
                        .ListItems(i).Checked = (Index = 1)
                    End If
                    ListView2_ItemCheck .ListItems(i)
                Next
            End With
        End If
    End Sub

    Private Function SetMenu(Menu, Index, Mode, Val)
        Dim pszText, MENUITEMINFO, fState
        Const MIIM_TYPE = &H10
        Const MIIM_STATE = &H1
        Const MIIM_CHECKMARKS = &H8

        Const MFT_STRING = &H0

        Const MF_CHECKED = &H8&
        Const MFS_GRAYED = &H3&
        pszText = Space(255)
    '   Private Type MENUITEMINFO
        '   cbSize As Long          0
        '   fMask As Long           4
        '   fType As Long           8
        '   fState As Long          12
        '   wID As Long             16
        '   hSubMenu As Long        20
        '   hbmpChecked As Long     24
        '   hbmpUnchecked As Long   28
        '   dwItemData As Long      32
        '   dwTypeData As String    36
        '   cch As Long             40
    '   End Type
        Set MENUITEMINFO = Api.Malloc(43)
        MENUITEMINFO.SetVal 44, 0, 4
        MENUITEMINFO.SetVal MIIM_TYPE Or MIIM_STATE, 4, 4
        MENUITEMINFO.SetVal Api.StrPtr(pszText), 36, 4
        MENUITEMINFO.SetVal Len(pszText), 40, 4
        If Api.ECall("user32", "GetMenuItemInfoW", Menu, Index, True, MENUITEMINFO.GetPtr(0)) Then
            If Mode And 1 Then
                pszText = Val
                MENUITEMINFO.SetVal Api.StrPtr(pszText), 36, 4
                MENUITEMINFO.SetVal Len(pszText), 40, 4
            End If
            fState = MENUITEMINFO.ReadVal(12, 4)
            If Mode And 2 Then
                fState = fState And Not MF_CHECKED
            ElseIf Mode And 4 Then
                fState = fState Or MF_CHECKED
            End If
            If Mode And 8 Then
                fState = fState And Not MFS_GRAYED
            ElseIf Mode And 16 Then
                fState = fState Or MFS_GRAYED
            End If
            MENUITEMINFO.SetVal fState, 12, 4
            SetMenu = Api.ECall("user32", "SetMenuItemInfoW", Menu, Index, True, MENUITEMINFO.GetPtr(0))
        End If
    End Function

    Public Sub ListView1_MouseUp(Button, Shift, x, y)
        Dim i, Index
        If Button = 2 Then
            With Form.Controls("ListView1").object.ListView
                Call SetMenu(hMenu1(0), 10 - 1, 1, IIf(Form.Controls("启动方式").ListIndex = 0, "提取名字", "导入文本"))
                Index = Globals("InGame")
                For i = 5 To Api.ECall("user32", "GetMenuItemCount", hMenu1(0))
                    Call SetMenu(hMenu1(0), i - 1, IIf(Index > 0, 16, 8), "")
                Next
                Index = PopMenuClick(.hwnd, hMenu1(0), x, y)
                ' Call SetMenu(hMenu1(0), Index - 1, 1 + 4 + 16, "测试")
                ' Dim pszText
                ' pszText = Space(255)
                'MsgBox Left(pszText, Api.ECall("user32", "GetMenuStringW", hMenu1(0), Index, pszText, Len(pszText), 0)), , Index
                Select Case Index
                Case 8
                    Call ListView1_Clear
                Case 10
                    Dim Names
                    If Form.Controls("启动方式").ListIndex = 0 Then
                        Names = GetGameNames("QQ飞车*【*区】*")
                        If UBound(Names) >= 0 Then
                            Call ListView1_Clear
                        End If
                        For i = 0 To UBound(Names)
                            .ListItems.Add , , i + 1
                            .ListItems(i + 1).SubItems(2) = Names(i)
                        Next
                    Else
                        Names = Angel.SelectFile(True, "请选择QQ账号", ".", "支持文件(*.txt)|*.txt")
                        If Len(Names) Then Call Import(Names)
                    End If
                Case Else
                    y = .ListItems.Count
                    For i = 1 To .ListItems.Count
                        Select Case Index
                        Case 1, 2
                            If .ListItems(i).Selected Then
                                .ListItems(i).Checked = (Index = 1)
                                ListView1_ItemCheck .ListItems(i)
                            End If
                        Case 3
                            If .ListItems(i).Selected Then
                                If Globals("QQSpeed").Exists(i - 1) Then Globals("QQSpeed").Remove i - 1
                            End If
                        Case 5  '选择全部'
                            .ListItems(i).Selected = True
                        Case 6  '选择反向
                            .ListItems(i).Selected = Not .ListItems(i).Selected
                        Case 7
                            x = y - i + 1
                            If .ListItems(x).Selected Then .ListItems.Remove x
                        End Select
                    Next
                End Select
            End With
        End If
    End Sub
    Public Sub ListView1_MouseMove(Button, Shift, x, y)
        Select Case CLng(x / Globals("Screen").TwipsPerPixelX)
        Case &H202 '单击左键,显示窗体
            If Button = 1 Then
                With Form
                    If .WindowState = 1 Then
                        .WindowState = 0
                        .Visible = True
                    End If
                    Call Api.ECall("user32", "SetForegroundWindow", .hwnd)
                End With
            End If
        End Select
    End Sub
    Private Sub ListView1_Clear()
        With Form.Controls("ListView1").object.ListView
            .ListItems.Clear
            Globals("QQSpeed").RemoveAll
        End With
    End Sub
    Private Function GetGameNames(Name)
        Dim hWnds, i, v, ret()
        hWnds = Window.EnumWindows(0, "GAMEAPP", Name, 2)
        If UBound(hWnds) = -1 Then
            GetGameNames = Array()
            Exit Function
        End If
        ReDim ret(UBound(hWnds))
        For i = 0 To UBound(hWnds)
            v = Split(Window.GetText(hWnds(i)), "【")
            ret(i) = Left(v(3), InStr(v(3), "】") - 1)
        Next
        GetGameNames = ret
    End Function

    Private Function ComboBoxStyle(Control, List, ListIndex)
        Dim v, i, ChildHwnd
        Const GWL_STYLE = (-16)
        Const GW_CHILD = 5
        v = Split(List, "|")
        With Control
            For i = 0 To UBound(v)
                .AddItem v(i)
            Next
            .ListIndex = ListIndex
            ChildHwnd = Api.ECall("user32.dll", "GetWindow", .hwnd, GW_CHILD)
            Call Api.ECall("user32.dll", "DestroyWindow", ChildHwnd)
            Call Api.ECall("user32.dll", "SetWindowLongA", .hwnd, GWL_STYLE, Api.ECall("user32.dll", "GetWindowLongA", .hwnd, GWL_STYLE) + 1)
        End With
    End Function
    Public Sub Form_LoadOver()  '防止杀毒 挂起卡住界面'
        Dim v, i
        v = Array("http://www.bccn.net/paste/4331", "QQSpeed", 128, _
        "ivmowo310ib", "", ".\plugin\dmsoft\dm.dll")
        i = (UBound(v) + 1) \ 3
        Form.Tag = "0/" & i
        Me.Caption = "QQ群:123066586     正在加载数据(0/" & i & ")..."
        Form.MousePointer = 13
        Form.Tag = HttpLoaderEx(v, Me, "HttpOver") & "/" & i
         Api.NewHttp().GetHttpEx "https://www.yuque" & Chr(46) & "com/api/docs/khco1a?book_id=19888673", Array(Me, "ReadMe", ".\使用说明.txt")
    End Sub
    Public Sub ReadMe(xmlhttp, Args)
        If xmlhttp.ReadyState = 4 Then
            Dim html
            Set html = CreateObject("htmlfile")
            With html
                .parentWindow.execScript "iData ='" & CString.GetMid(xmlhttp.responseText, """content"":""", """,""selected_at""", , 2) & "'"
                .Write .parentWindow.iData
                File.WriteText Args, .body.innerText
            End With
        End If
    End Sub
    Public Sub HttpOver(xmlhttp, Args)
        If HttpClass(xmlhttp, Args) Then
            Dim v, i
            v = Split(Form.Tag, "/")
            v(0) = v(0) + 1
            Form.Tag = v(0) & "/" & v(1)
            Me.Caption = "QQ群:123066586     正在加载数据(" & Form.Tag & ")..."
            If v(0) = Int(v(1)) Then
                Me.Caption = "QQ飞车白嫖辅助-云脚本开发版:软件定制337855632" & Space(5) & "QQ群:123066586"
                Form.MousePointer = 0
                Call Form_Event(Form.Controls("启动方式"), &H100 * &H100, 0)
                v = Array("dmsoft\dm.dll", "QQSpeed.ocx")
                On Error Resume Next
                For i = 0 To UBound(v)
                    Call Api.ECall(".\plugin\" & v(i), "DllRegisterServer") '注册插件'
                Next
            End If
        End If
    End Sub
    Public Property Let Caption(Text)
        Call Api.ECall("user32.dll", "SetWindowTextW", Form.hwnd, Text)
    End Property
    Public Property Get Caption()
        Caption = Form.Caption
    End Property
    Private Function IIf(p, a, b)
        If p Then
            IIf = a
        Else
            IIf = b
        End If
    End Function
    Public Sub UnLoad()
        Class_Terminate
    End Sub
    Public Sub Form_Unload(Cancel)
        If Globals("InGame") Then Cancel = MsgBox("游戏进行中,确定了要退出?", 4096 + 1, "关闭窗口") - 1
        If Cancel = 0 Then '关闭'
        End If
    End Sub
    Private Sub Class_Initialize()
        'Call Api.ECall("comctl32.dll", "InitCommonControls")
        Set Globals("QQSpeed") = CreateObject("Scripting.Dictionary")
        Call Create
    End Sub
    Private Sub Class_Terminate()
        Tip.TrayRemoveIcon
        'Api.UnloadFrom Form
        Call Api.ECall("kernel32", "TerminateProcess", -1, 0)
    End Sub
End Class