在模块中 Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
在窗体中
Option Explicit Private Declare Function PrintWindow Lib "User32" (ByVal SrcHwnd As Long, ByVal DesHDC As Long, ByVal uFlag As Long) As Long Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Type RECT'窗口的四个点的位置数据 Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function GetWindowRect Lib "User32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Sub Command1_Click() Dim hw As Long hw = FindWindow(vbNullString, "MapleStory")'获取句柄 If hw = 0 Then Label1.Caption = "Maplestory未运行" '显示运行状况 Exit Sub End If If hw <> 0 Then Label1.Caption = "Maplestory已运行" '显示运行状况 End If Dim rc As RECT If GetWindowRect(hw, rc) Then Picture1.Width = (rc.Right - rc.Left): Picture1.Height = (rc.Bottom - rc.Top)'按照窗口大小调整picture1的长度和宽度 End If Call PrintWindow(hw, Picture1.hDC, 0) Picture1.Refresh End Sub
Private Sub Form_Load() Picture1.AutoRedraw = True Picture1.BorderStyle = 0 Picture1.Appearance = 0 End Sub
于是我又用了下面的代码 (这个不是我自己写的)
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) Const theScreen = 0 Const theForm = 1
Private Sub Command1_Click() Call keybd_event(vbKeySnapshot, theScreen, 0, 0) DoEvents Picture1.Picture = Clipboard.GetData(vbCFBitmap) End Sub