⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appactivate.bas

📁 机房管理
💻 BAS
字号:
Attribute VB_Name = "MAppActivate"
  Option Explicit
  
  Public Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
  End Type

  Public Const SW_RESTORE As Long = 9&

  Public Const GW_CHILD As Long = 5&
  Public Const GW_HWNDNEXT As Long = 2&

  Public Declare Function GetDesktopWindow& Lib "user32" ()
  
  Public Declare Function GetWindow& Lib "user32" (ByVal hwnd&, ByVal wCmd&)

  Public Declare Function GetWindowText& Lib "user32" Alias "GetWindowTextA" _
                                    (ByVal hwnd&, ByVal lpString$, ByVal cch&)
  
  Public Declare Function ShowWindow& Lib "user32" (ByVal hwnd&, ByVal nCmdShow&)

  Public Declare Function GetWindowRect& Lib "user32" (ByVal hwnd&, lpRect As RECT)

  Public Declare Function MoveWindow& Lib "user32" (ByVal hwnd&, ByVal x&, _
                          ByVal y&, ByVal nWidth&, ByVal nHeight&, ByVal bRepaint&)

  Public Declare Function SetForegroundWindow& Lib "user32" (ByVal hwnd&)
  
  Public Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
                                          (ByVal lpClassName$, ByVal lpWindowName$)

Private Sub Main()

  Const sBaseCaption As String = "ChatClient"
  
  If UCase(Command) = "CRACK" Then
     Load frmClient
     Exit Sub
  End If
  
  If App.PrevInstance = True Then
      
      Dim hAppWindow&, sTemp$
      hAppWindow = GetWindow(GetDesktopWindow(), GW_CHILD)
      
      Do
        sTemp = String$(180, False)
        Call GetWindowText(hAppWindow, sTemp, 179)
  
        If InStr(sTemp, sBaseCaption) Then
        
           ActivatePrevInstance (hAppWindow) '使以前的窗口活动

          Exit Do
        End If
  
        ' 获得下一个子窗体
        hAppWindow = GetWindow(hAppWindow, GW_HWNDNEXT)
      Loop
  Else
    
    '第一次运行时
    frmClient.Show
  End If

End Sub

Private Sub ActivatePrevInstance(ByVal hAppWindow&)

  Call ShowWindow(hAppWindow, SW_RESTORE)

  '使窗口活动
  Call SetForegroundWindow(hAppWindow)
  
  
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -