VB 如何模拟键盘按下ALT+print screen

 我来答
cjsaohan
推荐于2016-11-20 · TA获得超过204个赞
知道小有建树答主
回答量:290
采纳率:0%
帮助的人:236万
展开全部
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Const SRCCOPY = &HCC0020

'在 Form 中加入二个 CommandButton,及一个 PictureBox,不必更改属性,加入以下程序码:

Private Sub Form_Load()
'将 Picture1 之长宽设定成和屏幕一样大小
Picture1.Width = Screen.Width
Picture1.Height = Screen.Height

End Sub

Private Sub Command1_Click()

'将屏幕画面抓下后放到 Picture1 中
Dim lngDesktopHwnd As Long

Dim lngDesktopDC As Long

Picture1.AutoRedraw = True
Picture1.ScaleMode = vbPixels
lngDesktopHwnd = GetDesktopWindow
lngDesktopDC = GetDC(lngDesktopHwnd)

Call BitBlt(Picture1.hdc, 0, 0, Screen.Width, Screen.Height, lngDesktopDC, 0, 0, SRCCOPY)
Picture1.Picture = Picture1.Image
Call ReleaseDC(lngDesktopHwnd, lngDesktopDC)

End Sub
追问
这样写是全屏截取
而我只想截取form1这个窗体
谢谢
追答
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, theForm, 0, 0)
    DoEvents
    Picture1.Picture = Clipboard.GetData(vbCFBitmap)
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式