明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1175|回复: 1

vba截屏位置偏移,是什么地方有问题?(已解决)

[复制链接]
发表于 2013-7-21 12:20:05 | 显示全部楼层 |阅读模式
本帖最后由 jack093 于 2013-8-23 16:10 编辑

代码如下,用了 ClientToScreen 还是偏移,原因何在?

另外,如何改为jpg格式的?
Function Screen_pos(ByVal x As Double, ByVal y As Double) As Double()
Dim iPt As Variant
Dim h As Double
Dim wh As Variant
Dim w As Double
Dim minPt(0 To 2) As Double
Dim maxPt(0 To 2) As Double

Dim ret(0 To 1) As Double
iPt = ThisDrawing.GetVariable("VIEWCTR")
h = ThisDrawing.GetVariable("VIEWSIZE")
wh = ThisDrawing.GetVariable("SCREENSIZE")
w = wh(0) / wh(1) * h
minPt(0) = iPt(0) - w / 2: minPt(1) = iPt(1) - h / 2: minPt(2) = 0
maxPt(0) = iPt(0) + w / 2: maxPt(1) = iPt(1) + h / 2: maxPt(2) = 0
ret(0) = wh(0) * (x - minPt(0)) / w
ret(1) = wh(1) - wh(1) * (y - minPt(1)) / h
Screen_pos = ret
End Function


' 拷贝选定方框区域的屏幕图像到剪贴板
Sub ScrnCap()
Dim Left As Long
Dim Top As Long
Dim Right As Long
Dim Bottom As Long

Right = 800
Bottom = 900
    Dim rWidth As Long
    Dim rHeight As Long
    Dim SourceDC As Long
    Dim DestDC As Long
    Dim BHandle As Long
    Dim Wnd As Long
    Dim DHandle As Long
  Dim Pt1 As Variant, Pt2 As Variant
    On Error Resume Next
    Pt1 = ThisDrawing.Utility.GetPoint(, "Select First Point")
    Pt2 = ThisDrawing.Utility.GetCorner(Pt1, "Select Corner Point")
    'Wnd = Screen.ActiveForm.hwnd
    Wnd = GetActiveWindow
    Dim pt As POINTAPI
Dim aa() As Double
    aa = Screen_pos(Pt1(0), Pt1(1))
    pt.x = aa(0)
    pt.y = aa(1)


    Dim DispInfo As String
   DispInfo = "left " & ThisDrawing.Utility.RealToString(pt.x, acDefaultUnits, LuPrec) & " top " & ThisDrawing.Utility.RealToString(pt.y, acDefaultUnits, LuPrec)


   AutoCAD.Application.ActiveDocument.Utility.Prompt (DispInfo)

    ' 转换屏幕坐标
   ClientToScreen Wnd, pt
   DispInfo = " left " & ThisDrawing.Utility.RealToString(pt.x, acDefaultUnits, LuPrec) & " top " & ThisDrawing.Utility.RealToString(pt.y, acDefaultUnits, LuPrec)


   AutoCAD.Application.ActiveDocument.Utility.Prompt (DispInfo)

Left = pt.x
Top = pt.y


    aa = Screen_pos(Pt2(0), Pt2(1))
    pt.x = aa(0)
    pt.y = aa(1)

   DispInfo = " left " & ThisDrawing.Utility.RealToString(pt.x, acDefaultUnits, LuPrec) & " top " & ThisDrawing.Utility.RealToString(pt.y, acDefaultUnits, LuPrec)


   AutoCAD.Application.ActiveDocument.Utility.Prompt (DispInfo)
    ' 转换屏幕坐标
    ClientToScreen Wnd, pt
   DispInfo = " left " & ThisDrawing.Utility.RealToString(pt.x, acDefaultUnits, LuPrec) & " top " & ThisDrawing.Utility.RealToString(pt.y, acDefaultUnits, LuPrec)


   AutoCAD.Application.ActiveDocument.Utility.Prompt (DispInfo)

Right = pt.x
Bottom = pt.y


    rWidth = Right - Left
    rHeight = Bottom - Top
    SourceDC = CreateDC("DISPLAY", 0, 0, 0)
    DestDC = CreateCompatibleDC(SourceDC)
    BHandle = CreateCompatibleBitmap(SourceDC, rWidth, rHeight)
    SelectObject DestDC, BHandle
    BitBlt DestDC, 0, 0, rWidth, rHeight, SourceDC, Left, Top, &HCC0020
    Wnd = GetActiveWindow
    OpenClipboard Wnd
    EmptyClipboard
    SetClipboardData 2, BHandle
    CloseClipboard
    DeleteDC DestDC
    ReleaseDC DHandle, SourceDC

End Sub


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2013-7-26 12:39:04 | 显示全部楼层
自己搞定,直接用GetCursorPos,
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 12:23 , Processed in 0.164821 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表