回复 25# xiezhang6263
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlusEx.au3>
#include <Array.au3>
#include <icons.au3>
Opt("GUIOnEventMode", 1)
Global Const $SC_DRAGMOVE = 0xF012
Global $hImage, $hGraphics, $backbuffer, $ffamily, $arial, $sformat, $rectf, $arr, $blackbrush, $iX, $iY
Global $ini, $start = 0, $flag = 0
$pic = @ScriptDir & "\map.jpg"
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($pic)
$iY = _GDIPlus_ImageGetHeight($hImage)
$iX = _GDIPlus_ImageGetWidth($hImage)
$ini = IniReadSectionNames("map.ini")
Global $Point[$ini[0]][4]
Local $Label[$ini[0]], $icon[$ini[0]]
Global $k = 1
Global $png[3] = ["a.png", "b.png", "c.png"]
$gui = GUICreate("My GUI picture", $iX, $iY, -1, -1, $WS_POPUP + $WS_SYSMENU)
GUISetOnEvent(-3, "_exit")
GUISetState()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($gui)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($hImage)
$ffamily = _GDIPlus_FontFamilyCreate("微软雅黑")
$arial = _GDIPlus_FontCreate($ffamily, 25, 1)
$sformat = _GDIPlus_StringFormatCreate();创建字符串格式对象,0x1000禁止该文本换行到下一行
$rectf = _GDIPlus_RectFCreate(0);创建 $tagGDIPRECTF 结构,左上宽高
$arr = _GDIPlus_GraphicsMeasureString($backbuffer, "3mile制作", $arial, $rectf, $sformat);测量字符串尺寸
DllStructSetData($arr[0], 1, $iX - DllStructGetData($arr[0], 3))
DllStructSetData($arr[0], 2, $iY - DllStructGetData($arr[0], 4))
$blackbrush = _GDIPlus_LineBrushCreateFromRect($arr[0], 0xFFFFFF00, 0xFFFF0000, 1)
_GDIPlus_GraphicsDrawStringEx($backbuffer, "3mile制作", $arial, $arr[0], $sformat, $blackbrush)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iX, $iY);copy bitmap to GUI
For $i = 1 To $ini[0]
$ini_set = IniReadSection("map.ini", $ini[$i])
$temp = StringSplit($ini_set[1][1], ",", 3)
$icon[$i - 1] = GUICtrlCreatepic('', $temp[0], $temp[1] ,32, 32)
;~ SetBitmap(GUICtrlGetHandle($icon[$i-1]),"a.png",1)
GUICtrlSetState($icon[$i-1],$gui_disable)
$hBitmap = _Icons_Bitmap_Load("a.png")
$hArea = _Icons_Bitmap_Resize($hBitmap, 32,32)
_SetHImage($icon[$i-1], $hArea)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteObject($hArea)
;~ _SetImage($icon[$i-1],"a.png")
$Point[$i - 1][0] = $temp[0]
$Point[$i - 1][1] = $temp[1]
$Point[$i - 1][2] = $temp[0] + $temp[2]
$Point[$i - 1][3] = $temp[1] + $temp[3]
Next
;~ AdlibRegister("Set_Icon",1000)
Global Const $idPic = GUICtrlCreatePic("", $iX - 85, 10, 85, 60)
Global $hBitmap = _GDIPlus_BitmapCreateFromScan0(85, 60,$GDIP_PXF32ARGB);DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", 120, "int", 200, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
Global Const $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
Global Const $hBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00)
Global Const $hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("DS-Digital")
Global Const $hFont = _GDIPlus_FontCreate($hFamily, 16, 0)
Global Const $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
_GDIPlus_GraphicsSetTextRenderingHint($hContext, 4)
_GDIPlus_GraphicsClear($hContext, "0xFFFFFFFF")
GUIRegisterMsg($WM_MOUSEMOVE, "WM_MOUSEMOVE")
GUIRegisterMsg($WM_LBUTTONUP, "_WM_LBUTTONUP")
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")
GUIRegisterMsg(0x0014, "WM_ERASEBKGND")
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState()
; Run the GUI until the dialog is closed
While 1
Sleep(100)
WEnd
Func _exit()
_GDIPlus_BrushDispose($blackbrush)
_GDIPlus_StringFormatDispose($sformat)
_GDIPlus_FontDispose($arial)
_GDIPlus_FontFamilyDispose($ffamily)
_GDIPlus_GraphicsDispose($backbuffer)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hContext)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>_exit
;~ Func _Click()
;~ MsgBox(0, $ini[@GUI_CtrlId - 3], IniRead("map.ini", $ini[@GUI_CtrlId - 3], "str", "ok"))
;~ EndFunc ;==>_Click
Func WM_ERASEBKGND($hWnd, $uMsgm, $wParam, $lParam)
_GDIPlus_GraphicsDrawStringEx($backbuffer, "3mile制作", $arial, $arr[0], $sformat, $blackbrush)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iX, $iY);copy bitmap to GUI
Return True
EndFunc ;==>WM_ERASEBKGND
Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
Local $x = BitAND($lParam, 0xFFFF)
Local $y = BitShift($lParam, 16)
For $i = 0 To UBound($Point) - 1
If _WinAPI_PtInRectEx($x, $y, $Point[$i][0], $Point[$i][1], $Point[$i][2], $Point[$i][3]) And $start = 0 Then
;~ msgbox(0,0,IniRead("map.ini",$ini[$i+1],"str","error"))
$start = 1
Return
EndIf
Next
_SendMessage($gui, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc ;==>_WM_LBUTTONDOWN
Func _WM_LBUTTONUP($hWnd, $Msg, $wParam, $lParam)
Local $x = BitAND($lParam, 0xFFFF)
Local $y = BitShift($lParam, 16)
For $i = 0 To UBound($Point) - 1
If _WinAPI_PtInRectEx($x, $y, $Point[$i][0], $Point[$i][1], $Point[$i][2], $Point[$i][3]) And $start = 1 Then
MsgBox(0, 0, IniRead("map.ini", $ini[$i + 1], "str", "error"))
$start = 0
Return
EndIf
Next
EndFunc ;==>_WM_LBUTTONUP
Func WM_MOUSEMOVE($hWndGUI, $MsgID, $wParam, $lParam)
Local $XX, $YY
Local $x = BitAND($lParam, 0xFFFF)
Local $y = BitShift($lParam, 16)
Local $mes = _GDIPlus_GraphicsMeasureString($backbuffer, "3mile制作", $arial, $rectf, $sformat)
$hBrush_bk = _GDIPlus_LineBrushCreateFromRect($mes[0], 0xFFFF00FF, 0xFFFFFF00)
_GDIPlus_GraphicsDrawStringEx($hContext, "X=" & $x & @CRLF & "Y=" & $y, $hFont, $tLayout, $hFormat, $hBrush_bk)
Local $hHBITAMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
_GDIPlus_BrushDispose($hBrush_bk)
_WinAPI_DeleteObject(GUICtrlSendMsg($idPic, 0x0172, 0, $hHBITAMP))
_WinAPI_DeleteObject($hHBITAMP)
_GDIPlus_GraphicsClear($hContext, "0xFFFFFFFF")
If $flag = 0 Then
For $i = 0 To UBound($Point) - 1
If _WinAPI_PtInRectEx($x, $y, $Point[$i][0], $Point[$i][1], $Point[$i][2], $Point[$i][3]) Then
ToolTip("X=" & $x & @CRLF & "Y=" & $y)
$flag=$i+1
ExitLoop
EndIf
Next
Else
If _WinAPI_PtInRectEx($x, $y, $Point[$flag-1][0], $Point[$flag-1][1], $Point[$flag-1][2], $Point[$flag-1][3])<>1 Then
ToolTip("")
$flag=0
EndIf
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_MOUSEMOVE
Func Set_Icon()
If $k > 2 Then $k = 0
For $i = 0 To UBound($icon) - 1
_SetImage($icon[$i], $png[$k])
GUICtrlSetState(-1, $GUI_SHOW)
Next
$k += 1
EndFunc ;==>Set_Icon
Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
_WinAPI_RedrawWindow($gui, 0, 0, $RDW_UPDATENOW)
_GDIPlus_GraphicsDrawStringEx($backbuffer, "3mile制作", $arial, $arr[0], $sformat, $blackbrush)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iX, $iY);copy bitmap to GUI
_WinAPI_RedrawWindow($gui, 0, 0, $RDW_VALIDATE)
Return $GUI_RUNDEFMSG
EndFunc ;==>MY_WM_PAINT
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local Const $AC_SRC_ALPHA = 1
Local Const $ULW_ALPHA = 2
Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
$hScrDC = _WinAPI_GetDC(0)
$hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hMemDC)
EndFunc ;==>SetBitmap
|