| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2002 人关注过本帖
标题:帮看下控件坐标是缺什么,总得不到正确截图
只看楼主 加入收藏
zhken
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:283
专家分:616
注 册:2012-9-21
结帖率:96.67%
收藏
已结贴  问题点数:10 回复次数:7 
帮看下控件坐标是缺什么,总得不到正确截图
lnTop=_screen.Top+SYSMETRIC(9)+SYSMETRIC(11)+thisform.image4.top &&控件行坐标
&&主窗口TOP + 表单头 + 不可调边框 + 控件TOP

lnleft=_screen.left+SYSMETRIC(10)+thisform.image4.left &&控件纵坐标
&&主窗口LEFT + 不可调边框 + 控件LEFT

lnRight=lnTop+thisform.image4.width  &&图片高

lnBottom=lnleft+thisform.image4.height &&图片宽

图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: thisform 控件 Top left 坐标 
2019-08-31 12:35
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43182
注 册:2014-5-20
收藏
得分:0 
窗口内截图,不用换算为屏幕座标,截图设备句柄取这个窗口就可以。
    hDC = GetDC(thisform.hWnd)
    nX = thisform.image4.left
    nY = thisform.image4.top
    nWidth = thisform.image4.width
    nHeight = thisform.image4.height


[此贴子已经被作者于2019-8-31 15:31编辑过]

2019-08-31 15:30
zhken
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:283
专家分:616
注 册:2012-9-21
收藏
得分:0 
按钮的CLICK事件,提示出错, 就是截取这个图片控件截不准

Lparameters  lnLeft, lnTop, lnRight, lnBottom

lnTop=thisform.image4.top          &&  此行用_SCREEN.TOP+THISFORM.IMAGE4.TOP  就不出错
lnleft=thisform.image4.left       &&
lnRight=thisform.image4.width    &&
lnBottom=thisform.image4.height  &&

    #Define CF_BITMAP   2  
    #Define SRCCOPY     13369376  
    Declare INTEGER GetLastError IN kernel32
    Declare INTEGER GetActiveWindow IN user32
    Declare INTEGER GetWindowDC IN user32 INTEGER hwnd
    Declare INTEGER GetDC IN user32 INTEGER hwnd
    Declare INTEGER CreateCompatibleDC IN gdi32 INTEGER hdc
    Declare INTEGER DeleteDC IN gdi32 INTEGER hdc
    Declare INTEGER CreateCompatibleBitmap IN gdi32 INTEGER hdc,INTEGER nWidth,INTEGER nHeight
    Declare INTEGER ReleaseDC IN user32 INTEGER hwnd, INTEGER hdc
    Declare INTEGER SelectObject IN gdi32 INTEGER hdc, INTEGER hObject
    Declare INTEGER DeleteObject IN gdi32 INTEGER hObject
    Declare INTEGER BitBlt IN gdi32 INTEGER hDestDC,INTEGER x, INTEGER y,INTEGER nWidth,;
            INTEGER nHeight,INTEGER hSrcDC,INTEGER xSrc, INTEGER ySrc,INTEGER dwRop
    Declare INTEGER OpenClipboard IN user32 INTEGER hwnd
    Declare INTEGER CloseClipboard IN user32
    Declare INTEGER EmptyClipboard  IN user32
    Declare INTEGER SetClipboardData IN user32 INTEGER wFormat, INTEGER hMem
    lnWidth = lnRight - lnLeft + 1
    lnHeight = lnBottom - lnTop + 1
    HWnd = GetActiveWindow()
    *hdc = GetWindowDC (hwnd)         &&改这句会出错
    hdc = GetDC (thisform.hwnd)   
    hVdc = CreateCompatibleDC (hdc)
    hBitmap = CreateCompatibleBitmap (hdc, lnWidth, lnHeight)
    = SelectObject (hVdc, hBitmap)
    = BitBlt (hVdc, 0,0, lnWidth,lnHeight,;
        hdc, lnLeft,lnTop, SRCCOPY)
    = OpenClipboard (hwnd)
    = EmptyClipboard()

    lnResult = SetClipboardData (CF_BITMAP, hBitmap)
    If lnResult = 0
    =MESSAGEBOX('出错了!!!',0,'')
    Endif
    = CloseClipboard()
    = DeleteObject (hBitmap)
    = DeleteDC (hVdc)
    = ReleaseDC (hwnd, hdc)

    retu
2019-08-31 16:54
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43182
注 册:2014-5-20
收藏
得分:0 
参考示例
图片附件: 游客没有浏览图片的权限,请 登录注册

图片附件: 游客没有浏览图片的权限,请 登录注册

*** test.prg ***
DECLARE LONG GetDC IN user32 LONG
DECLARE LONG ReleaseDC IN user32 LONG, LONG

DECLARE LONG CreateCompatibleDC IN gdi32 LONG
DECLARE LONG DeleteDC IN gdi32 LONG
DECLARE LONG CreateCompatibleBitmap IN gdi32 LONG, LONG, LONG
DECLARE LONG SelectObject IN gdi32 LONG, LONG
DECLARE LONG DeleteObject IN gdi32 LONG
DECLARE LONG BitBlt IN gdi32 LONG, LONG, LONG, LONG, LONG, LONG, LONG, LONG, LONG

DECLARE LONG GdiplusStartup IN gdiplus LONG@, STRING@, LONG
DECLARE LONG GdiplusShutdown IN gdiplus LONG
DECLARE LONG GdipCreateBitmapFromHBITMAP IN gdiplus LONG, LONG, LONG@
DECLARE LONG GdipDisposeImage IN gdiplus LONG
DECLARE LONG GdipSaveImageToFile IN gdiplus LONG, STRING@, STRING@, LONG

of  = CREATEOBJECT("form1")
of.show(1)
RETURN

DEFINE CLASS form1 As Form
    backcolor = 0xFF
    ADD OBJECT cmd1 as commandbutton WITH top=10,left=10,height=22,caption="截图"
    ADD OBJECT image1 as image WITH top=40,left=10,height=100,;
        stretch=2,picture="C:\temp\白眼圈鸟.jpg"
    ADD OBJECT image2 as image WITH top=145,left=10,height=100,stretch=1
   
    PROCEDURE cmd1.click
        LOCAL cOutFile, nX, nY, nWidth, nHeight,;
              stGSI, pGDI, hDC, pDC, hBitmap, pBitmap, cGUID

        cOutFile = "C:\temp\tmp.jpg"

        nX = thisform.image1.left
        nY = thisform.image1.top
        nWidth  = thisform.image1.width
        nHeight = thisform.image1.height

        stGSI = 0h01000000000000000000000000000000
        pGDI = 0
        GdiplusStartup(@pGDI, @stGSI, 0)
        
        hDC = GetDC(thisform.hWnd)
        pDC = CreateCompatibleDC(hDC)
        hBitmap = CreateCompatibleBitmap(hDC, nWidth, nHeight)
        SelectObject(pDC, hBitmap)
        BitBlt(pDC, 0, 0, nWidth, nHeight, hDC, nX, nY, 0xCC0020)  && SRCCOPY
        cGUID = 0h01F47C55041AD3119A730000F81EF32E && jpg
        pBitmap = 0
        GdipCreateBitmapFromHBITMAP(hBitmap, 2, @pBitmap)
        GdipSaveImageToFile(pBitmap, STRCONV(cOutFile+0h00,5), @cGUID, 0)
        
        GdipDisposeImage(pBitmap)
        DeleteObject(hBitmap)
        DeleteDC(pDC)
        ReleaseDC(thisform.hWnd, hDC)
        GdiplusShutdown(pGDI)
        
        thisform.image2.picture = cOutFile
    ENDPROC
ENDDEFINE
2019-08-31 20:49
zhken
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:283
专家分:616
注 册:2012-9-21
收藏
得分:0 
再烦请教,直接存入剪贴板要怎样改? 不要用文件转到剪贴板,因为很多时侯并不需要保存到文件,而是截取一部分图到剪贴板就直接发QQ了,这样就少了一项将图片保存到磁盘,再读入剪贴板,然后再删除文件
2019-08-31 22:12
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43182
注 册:2014-5-20
收藏
得分:10 
回复 5楼 zhken
试试:
*** test.prg ***
DECLARE LONG GetDC IN user32 LONG
DECLARE LONG ReleaseDC IN user32 LONG, LONG

DECLARE LONG CreateCompatibleDC IN gdi32 LONG
DECLARE LONG DeleteDC IN gdi32 LONG
DECLARE LONG CreateCompatibleBitmap IN gdi32 LONG, LONG, LONG
DECLARE LONG SelectObject IN gdi32 LONG, LONG
DECLARE LONG DeleteObject IN gdi32 LONG
DECLARE LONG BitBlt IN gdi32 LONG, LONG, LONG, LONG, LONG, LONG, LONG, LONG, LONG

DECLARE LONG OpenClipboard IN user32 LONG
DECLARE LONG EmptyClipboard IN user32
DECLARE LONG CloseClipboard IN user32
DECLARE LONG SetClipboardData IN user32 LONG, LONG

of  = CREATEOBJECT("form1")
of.show(1)
RETURN

DEFINE CLASS form1 As Form
    backcolor = 0xFF
    ADD OBJECT cmd1 as commandbutton WITH top=10,left=10,height=22,caption="截图"
    ADD OBJECT image1 as image WITH top=40,left=10,height=100,;
        stretch=2,picture="C:\temp\白眼圈鸟.jpg"
   
    PROCEDURE cmd1.click
        LOCAL nX, nY, nWidth, nHeight, hDC, pDC, hBitmap
        nX = thisform.image1.left
        nY = thisform.image1.top
        nWidth  = thisform.image1.width
        nHeight = thisform.image1.height

        hDC = GetDC(thisform.hWnd)
        pDC = CreateCompatibleDC(hDC)
        hBitmap = CreateCompatibleBitmap(hDC, nWidth, nHeight)
        SelectObject(pDC, hBitmap)
        BitBlt(pDC, 0, 0, nWidth, nHeight, hDC, nX, nY, 0xCC0020)  && SRCCOPY
        
        IF OpenClipboard(0) == 0
            MESSAGEBOX("打开剪贴板失败")
            RETURN
        ENDIF
        EmptyClipboard()
        SetClipboardData(2, hBitmap) &&CF_BITMAP
        CloseClipboard()
        MESSAGEBOX("图像装入剪贴板")
        
        DeleteObject(hBitmap)
        DeleteDC(pDC)
        ReleaseDC(thisform.hWnd, hDC)
    ENDPROC
ENDDEFINE
2019-08-31 23:25
zhken
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:283
专家分:616
注 册:2012-9-21
收藏
得分:0 
完美
2019-09-01 10:26
金142857
Rank: 2
等 级:论坛游民
帖 子:35
专家分:61
注 册:2019-8-23
收藏
得分:0 
完美
2019-09-03 20:21
快速回复:帮看下控件坐标是缺什么,总得不到正确截图
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042275 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved