本帖最后由 mbdnmt 于 2013-5-8 00:07 编辑
如何使用GDI画图? 有没有带源码的例子?
帮助文档里关于GDI画图有这么个例子(见代码1),但好像是还使用了一个GUIRegisterMsg, 不使用这个是否可以正常使用GDI来画图?
尝试[代码2]为何不成功?
========= [代码2] ========$hGUI = GUICreate("Toolbar", 400, 300)
_GDIPlus_Startup()
;---> Create an image object based on a file, Return Success - Handle to the new image object
$hImage = _GDIPlus_ImageLoadFromFile("authimg.png")
ConsoleWrite("$hImage is " & $hImage & @CRLF)
;---> Create a Graphics object from a window handle, Success - Handle to a Graphics object
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
ConsoleWrite("$hGraphic is " & $hGraphic & @CRLF)
;--->Draw an Image object, Success - True
$sRtn = _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 20, 20)
ConsoleWrite("$sRtn is " & $sRtn & @CRLF)
;---> Creates a Bitmap object based on a Graphics object, a width, and a height, Success - Handle to a Bitmap object
$sRtn = _GDIPlus_BitmapCreateFromGraphics(50, 50, $hGraphic)
ConsoleWrite("$sRtn is " & $sRtn & @CRLF)
GUISetState(@SW_SHOW, $hGUI)
Sleep(6000)
========= [代码1] ========#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
Global $hGUI, $hImage, $hGraphic, $hImage1
; 创建 GUI
$hGUI = GUICreate("显示 PNG 图片", 250, 250)
; 加载 PNG 图像
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile("authimg.png")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState()
; 循环到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; 清理资源
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
; 绘制 PNG 图像
Func MY_WM_PAINT($hWnd, $msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $wParam, $lParam
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
Return $GUI_RUNDEFMSG
EndFunc ;==>MY_WM_PAINT
|