永发信息网

vb 屏幕COPY

答案:1  悬赏:30  手机版
解决时间 2021-01-28 02:05
  • 提问者网友:相思似海深
  • 2021-01-27 01:53
具体代码没有带来,上网的时候忽然想起来了就上来问问,希望有高手帮我解决.VB复制整个屏幕到Clipboard有几个API涵数来实现,只要将对像的句柄传到某个涵数就行了,桌面对像的句柄永远是0.这个不是什么问题了,现在的问题是,我不想将整个屏幕画面COPY到Clipboard对像,而是想在内存中开辟一个"对像",允许写入读取BMP格式的数据,并且是将实现这个"对像"的能功写成CLS类模块. CopyMemory涵数并不是很了解.希望可以得到帮助.3Q...
最佳答案
  • 五星知识达人网友:往事隔山水
  • 2021-01-27 02:01
这个不是用CopyMemory应该是创建一个DC,用bitblt把屏幕指定部分复制到DC中再打开剪贴板,把图像复制进去一般不用自己创建DC,麻烦死,用个Picturebox就可以了1. 启动新 VisualBasic 常用 Exe 项目。 默认情况下创建 Form 1。
2. 在 项目 菜单上, 选择将一个新模块添加到现有项目 添加模块 。
3. 向窗体, 名称之一添加两 图片框 Pic_Edit (目标), 和其他名称 Pic_Dest (目标)。
4. 将是 Pic_Edit Picture 属性设置为要从中选择区域位图
5. 将是 Pic_Dest AutoRedraw 属性设置为 True
6. 以下代码添加到 Module 1:Public Const INVERSE = 6
Public Const DOT = 2
Public Const SOLID = 0

Public OrigX As Long
Public OrigY As Long
Public DestX As Long
Public DestY As Long

Public Sub Draw_Selection_Rectangle()

' Set drawing mode to INVERSE since this routine also used to erase
' the selection rectangle by simply drawing over the currently
' displayed rectangle

With Editor.Pic_Edit
.DrawMode = INVERSE
.DrawStyle = DOT
Editor.Pic_Edit.Line (OrigX, OrigY)-(DestX, DestY), , B
.DrawStyle = SOLID
End With

End Sub

Public Sub Copy_Rectangle()
With Editor.Pic_Dest
.Cls
.Visible = True
.Height = DestY - OrigY
.Width = DestX - OrigX
.PaintPicture Editor.Pic_Edit, 0, 0, (DestX - OrigX), _
(DestY - OrigY), OrigX, OrigY, (DestX - OrigX), _
(DestY - OrigY), vbSrcCopy
End With

' Make sure the clipboard is clear, then copy the image:
Clipboard.Clear
Clipboard.SetData Editor.Pic_Dest.Image
End Sub

7. 以下代码添加到 Form 1:Private Sub Pic_Edit_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Pic_Edit.Refresh
Pic_Dest.Visible = False
OrigX = X
OrigY = Y
DestX = OrigX
DestY = OrigY
Call Module1.Draw_Selection_Rectangle
End Sub

Private Sub Pic_Edit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = 1 Then
DestX = X
DestY = Y
Pic_Edit.Refresh
Call Module1.Draw_Selection_Rectangle
End If
End Sub

Private Sub Pic_Edit_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Check to see if mouse moved or goes the "wrong" way:
If DestX <= OrigX Or DestY <= OrigY Then
Pic_Edit.Refresh
Exit Sub
End If

If Button = 1 Then Call Copy_Rectangle
End Sub

8. 启动应用程序并选择用鼠标与位图的区域。 当您松开鼠标按钮, Pic_Dest 出现 备注 所选区域: 如果备份 MS 画图、 MSWord 或任何其他应用程序可能需要粘贴位图, 打开您就可以粘贴到该应用程序图像的选定部分。 也可以通过剪贴板查看程序查看剪贴板的内容。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯