找回密码
 加入
搜索
查看: 3708|回复: 7

[图形处理] _WinAPI_BitBlt的问题[已解决]

  [复制链接]
发表于 2011-11-9 16:13:17 | 显示全部楼层 |阅读模式
本帖最后由 kyniel 于 2011-11-10 16:52 编辑
#Include <WinAPI.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 401, 401, 381, 287)
$Pic1 = GUICtrlCreatePic(@ScriptDir&"\1.JPG", 24, 24, 193, 161)
$Pic2 = GUICtrlCreatePic(@ScriptDir&"\2.JPG", 248, 24, 129, 113)
$Pic3 = GUICtrlCreatePic("", 24, 208, 193, 161)
$List1 = GUICtrlCreateList("", 240, 168, 145, 201)
GUICtrlSetData(-1, "$BLACKNESS |$CAPTUREBLT|$DSTINVERT|$MERGECOPY|$MERGEPAINT|$NOMIRRORBITMAP|$NOTSRCCOPY|$NOTSRCERASE|$PATCOPY |$PATINVERT|$PATPAINT|$SRCAND|$SRCCOPY|$SRCERASE|$SRCINVERT|$SRCPAINT|$WHITENESS")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


$hwnd3=ControlGetHandle("Form1","","Static3")
$hwnd2=ControlGetHandle("Form1","","Static2")
$p3pos=ControlGetPos("Form1","","Static3")
$p2pos=ControlGetPos("Form1","","Static2")

While 1
        
        $nMsg = GUIGetMsg()
        GUICtrlSetImage($pic3,"shell32.dll", 22)

        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $List1
                        $rop=GUICtrlRead($List1)
                        GUICtrlSetImage($pic3,@ScriptDir&"\1.JPG")
                        _WinAPI_BitBlt($hwnd3,($p3pos[2]-$p2pos[2])/2,($p3pos[3]-$p2pos[3])/2,$p2pos[2],$p2pos[3],$hwnd2,0,0,$rop)
EndSwitch
WEnd

为什么我做不出http://www.cnblogs.com/del/archive/2008/06/25/1229469.html的效果,是不是控件的样式问题,应该怎么弄,难道要用gdi+?

本帖子中包含更多资源

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

×
发表于 2011-11-9 17:37:30 | 显示全部楼层
这个恐怕要用 WinAPIEx 类函数吧。。。
 楼主| 发表于 2011-11-10 14:36:53 | 显示全部楼层
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

_GDIPlus_Startup()


$himage1=_GDIPlus_BitmapCreateFromFile(@ScriptDir&"\1.jpg")

$himage2=_GDIPlus_BitmapCreateFromFile(@ScriptDir&"\2.jpg")

$hwidth=_GDIPlus_ImageGetWidth($himage1)

$hheight=_GDIPlus_ImageGetHeight($himage1)

$hGUI=GUICreate("",$hwidth,$hheight)

GUISetState(@SW_SHOW)

$hgraphic=_GDIPlus_ImageGetGraphicsContext($himage1)

$hGraphic2 = _GDIPlus_GraphicsCreateFromHWND($hGUI)

_GDIPlus_GraphicsDrawImage($hgraphic,$himage2,32,24)


Do

_GDIPlus_GraphicsDrawImage($hGraphic2, $hImage1, 0, 0)

_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)

Until  GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_ImageDispose($himage1)

_GDIPlus_ImageDispose($himage1)

_GDIPlus_Shutdown()
使用gdi+ 我把两张图片叠加显示在gui上了,发现要_WinAPI_RedrawWindow否者gui上的东西不会刷新,但我用_WinAPI_BitBlt的时候返回值为0,也就没有成功,和_WinAPI_RedrawWindow也就没关系了,谁知道_WinAPI_BitBlt到底怎么用地啊?
 楼主| 发表于 2011-11-10 16:06:03 | 显示全部楼层
本帖最后由 kyniel 于 2011-11-10 16:50 编辑

又仔细研究了下发现_WinAPI_BitBlt函数发现它需要的环境句柄(谁能解释下有什么区别),所以加了如下代码:
$hGraphic2 = _GDIPlus_GraphicsCreateFromHWND($hwnd2)
$hdc2=_GDIPlus_GraphicsGetDC($hGraphic2)
神奇的发现可以实现了。
然而,接着又有新的问题,我使用
$rop=GUICtrlRead($List1)
来获取列表的值
GUICtrlSetData(-1, "$BLACKNESS |$CAPTUREBLT|$DSTINVERT|$MERGECOPY|$MERGEPAINT|$NOMIRRORBITMAP|$NOTSRCCOPY|$NOTSRCERASE|$PATCOPY |$PATINVERT|$PATPAINT|$SRCAND|$SRCCOPY|$SRCERASE|$SRCINVERT|$SRCPAINT|$WHITENESS")
这些值不知道是不是带有“$”,结果显示的不对,估计是变量引用变量的字符串,结果不能获取变量值。有什么函数可以直接解决呢?

附上最后的代码
#Include <WinAPI.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 401, 401, 381, 287)
$Pic1 = GUICtrlCreatePic(@ScriptDir&"\1.JPG", 24, 24, 193, 161)
$Pic2 = GUICtrlCreatePic(@ScriptDir&"\2.JPG", 248, 24, 129, 113)
$Pic3 = GUICtrlCreatePic(@ScriptDir&"\1.JPG", 24, 208, 193, 161)
$List1 = GUICtrlCreateList("", 240, 168, 145, 201)
GUICtrlSetData(-1, "BLACKNESS |CAPTUREBLT|DSTINVERT|MERGECOPY|MERGEPAINT|$NOMIRRORBITMAP|$NOTSRCCOPY|$NOTSRCERASE|$PATCOPY |$PATINVERT|$PATPAINT|$SRCAND|$SRCCOPY|$SRCERASE|$SRCINVERT|$SRCPAINT|$WHITENESS")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


$hwnd3=ControlGetHandle("Form1","","Static3")
$hwnd2=ControlGetHandle("Form1","","Static2")
$p3pos=ControlGetPos("Form1","","Static3")
$p2pos=ControlGetPos("Form1","","Static2")

_GDIPlus_Startup()

$hGraphic3 = _GDIPlus_GraphicsCreateFromHWND($hwnd3)
$hdc3=_GDIPlus_GraphicsGetDC($hGraphic3)

$hGraphic2 = _GDIPlus_GraphicsCreateFromHWND($hwnd2)
$hdc2=_GDIPlus_GraphicsGetDC($hGraphic2)




While 1
        
        $nMsg = GUIGetMsg()

        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $List1
                        $rop=GUICtrlRead($List1)
                        _WinAPI_RedrawWindow($hwnd3)
                        _WinAPI_BitBlt($hdc3,($p3pos[2]-$p2pos[2])/2,($p3pos[3]-$p2pos[3])/2,$p2pos[2],$p2pos[3],$hdc2,0,0,$rop)

EndSwitch
WEnd

_GDIPlus_Shutdown()

本帖子中包含更多资源

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

×
 楼主| 发表于 2011-11-10 16:42:12 | 显示全部楼层
本帖最后由 kyniel 于 2011-11-10 16:48 编辑

学到两个函数getvartype和eval,eval可以获取字符串变量的值。我发现api帮助部分例子太少了,很难搞清楚。最后终于搞好了,自己做个标记吧!
#Include <WinAPI.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 401, 401, 381, 287)
$Pic1 = GUICtrlCreatePic(@ScriptDir&"\1.JPG", 24, 24, 193, 161)
$Pic2 = GUICtrlCreatePic(@ScriptDir&"\2.JPG", 248, 24, 129, 113)
$Pic3 = GUICtrlCreatePic(@ScriptDir&"\1.JPG", 24, 208, 193, 161)
$List1 = GUICtrlCreateList("", 240, 168, 145, 201)

GUICtrlSetData(-1, "BLACKNESS|CAPTUREBLT|DSTINVERT|MERGECOPY|MERGEPAINT|NOMIRRORBITMAP|NOTSRCCOPY|NOTSRCERASE|PATCOPY|PATINVERT|PATPAINT|SRCAND|SRCCOPY|SRCERASE|SRCINVERT|SRCPAINT|WHITENESS")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


$hwnd3=ControlGetHandle("Form1","","Static3")
$hwnd2=ControlGetHandle("Form1","","Static2")
$p3pos=ControlGetPos("Form1","","Static3")
$p2pos=ControlGetPos("Form1","","Static2")

_GDIPlus_Startup()

$hGraphic3 = _GDIPlus_GraphicsCreateFromHWND($hwnd3)
$hdc3=_GDIPlus_GraphicsGetDC($hGraphic3)

$hGraphic2 = _GDIPlus_GraphicsCreateFromHWND($hwnd2)
$hdc2=_GDIPlus_GraphicsGetDC($hGraphic2)


While 1
        
        $nMsg = GUIGetMsg()

        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $List1
                        $rop=Eval(GUICtrlRead($List1))
                        _WinAPI_RedrawWindow($hwnd3)
                        _WinAPI_BitBlt($hdc3,($p3pos[2]-$p2pos[2])/2,($p3pos[3]-$p2pos[3])/2,$p2pos[2],$p2pos[3],$hdc2,0,0,$rop)

EndSwitch
WEnd

_GDIPlus_Shutdown()
效果图:

本帖子中包含更多资源

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

×
发表于 2011-11-10 22:37:40 | 显示全部楼层
发表于 2011-11-11 09:03:52 | 显示全部楼层
希望版主多关注一下api帮助部分例子的哈。。
发表于 2012-7-1 22:06:16 | 显示全部楼层
wo lu guo w zhan qian
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-18 23:48 , Processed in 0.081818 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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