文号
t17710
阅读
6246
回复
4
收藏
3
懂vb懂api的来下 VB6对指定的游戏窗口截屏的问题
2009/07/23
IP:广东
我开始用了如下的语句,能够实现对任意标题的窗口进行选择性截屏,但是printwindow这个函数好像不能对directX的游戏截取..只能获得一块白色 (我要对冒险岛这个游戏进行截图)

在模块中
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


这个可以对游戏和视屏任意截图 但是却是全屏抓取 没有看到有使用句柄的迹象 应该不能选择抓取窗口

请教如何实现我想要的功能了 谢谢
17年6个月前IP:未同步
130122
3楼
帮帮忙吧 [s:258] 不要用DirectX  ..
引用
评论
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的