創(chuàng)建圖片(Picture)控件.
GUICtrlCreatePic ( 文件名, 左距, 頂距 [, 寬度 [, 高度 [,
樣式 [, 擴(kuò)展樣式]]]] )
文件名 | 圖片文件名稱: 支持類型為 BMP, JPG, GIF(非動畫效果的). |
左距 | 控件左側(cè)的位置. 若此值為 -1, 則根據(jù) GUICoordMode 的設(shè)置計算左側(cè)位置. |
頂距 | 控件上方的位置. 若此值為 -1, 則根據(jù) GUICoordMode 的設(shè)置計算頂部位置. |
寬度 | [可選參數(shù)] 控件的寬度(默認(rèn)使用先前的寬度). |
高度 | [可選參數(shù)] 控件的高度(默認(rèn)使用先前的高度). |
樣式 | [可選參數(shù)] 控件的樣式. 查看附錄 GUI 控件樣式表. 默認(rèn)樣式 (-1) : $SS_NOTIFY 強(qiáng)制樣式 : $SS_BITMAP |
擴(kuò)展樣式 | [可選參數(shù)] 控件的擴(kuò)展樣式. 查看附錄 擴(kuò)展樣式表. |
成功: | 返回控件標(biāo)識符(控件ID). |
失敗: | 返回 0, 不能創(chuàng)建圖片. |
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $gui, $guiPos, $pic, $picPos
Example1()
Example2()
;----- 示例 1 ----
Func Example1()
Local
$n, $msg
GUICreate("我的圖像 GUI", 350, 300, -1,
-1, $WS_SIZEBOX + $WS_SYSMENU) ; 創(chuàng)建居中顯示的 GUI 窗口
GUISetBkColor(0xE0FFFF)
$n
= GUICtrlCreatePic("..\GUI\mslogo.jpg",
50, 50, 200, 50);譯注: Win7
不支持這種路徑
GUISetState()
; 運(yùn)行 GUI, 直到
GUI 被關(guān)閉
While
1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
;
調(diào)整控件
$n
= GUICtrlSetPos($n, 50, 50, 200, 100)
; 運(yùn)行 GUI, 直到
GUI 被關(guān)閉
While
1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
EndFunc ;==>Example1
;----- 示例 2
Func Example2()
Local
$msg
$gui
= GUICreate("測試圖像透明", 200, 100)
$pic
= GUICreate("", 68, 71, 10, 20, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $gui)
GUICtrlCreatePic("..\GUI\merlin.gif",
0, 0, 0, 0);譯注: Win7
不支持這種路徑
GUISetState(@SW_SHOW, $pic)
GUISetState(@SW_SHOW, $gui)
HotKeySet("{ESC}", "main")
HotKeySet("{LEFT}", "left")
HotKeySet("{RIGHT}", "right")
HotKeySet("{DOWN}", "down")
HotKeySet("{UP}", "up")
$picPos = WinGetPos($pic)
$guiPos = WinGetPos($gui)
Do
$msg = GUIGetMsg()
Until
$msg = $GUI_EVENT_CLOSE
HotKeySet("{ESC}")
HotKeySet("{LEFT}")
HotKeySet("{RIGHT}")
HotKeySet("{DOWN}")
HotKeySet("{UP}")
EndFunc ;==>Example2
Func main()
$guiPos = WinGetPos($gui)
WinMove($gui, "", $guiPos[0] +
10, $guiPos[1] +
10)
EndFunc ;==>main
Func left()
$picPos = WinGetPos($pic)
WinMove($pic, "", $picPos[0] -
10, $picPos[1])
EndFunc ;==>left
Func right()
$picPos = WinGetPos($pic)
WinMove($pic, "", $picPos[0] +
10, $picPos[1])
EndFunc ;==>right
Func down()
$picPos = WinGetPos($pic)
WinMove($pic, "", $picPos[0], $picPos[1] +
10)
EndFunc ;==>down
Func up()
$picPos = WinGetPos($pic)
WinMove($pic, "", $picPos[0], $picPos[1] -
10)
EndFunc ;==>up
;----- 示例 3 使用 PNG 圖片
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
Global $hGUI, $hImage, $hGraphic, $hImage1
; 創(chuàng)建 GUI
$hGUI =
GUICreate("顯示 PNG 圖片", 250,
250)
; 加載 PNG 圖像
_GDIPlus_Startup()
$hImage =
_GDIPlus_ImageLoadFromFile("..\GUI\Torus.png");譯注: Win7 不支持這種路徑
$hGraphic =
_GDIPlus_GraphicsCreateFromHWND($hGUI)
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState()
; 循環(huán)到用戶退出
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
provider with jb51.net (unicode) |