#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
Opt ("MustDeclareVars", 1)
_Main ( )
_Main (True)
Func _Main ($mixed=False)
Local $a_hBMP[52][3], $a_hBitmap[52], $hGraphic, $hGUI, $hInstance
Local $ressource = "cards.dll"
; 加载资源DLL到数据文件
$hInstance = _WinAPI_LoadLibraryEx ($ressource, $LOAD_LIBRARY_AS_DATAFILE)
; 从库加载位图
; 数组中的[0]=DLL索引, [1]=真实次序, [2]=BMP句柄
Local $j = 15
For $i = 0 To 38
If $i = 12 Or $i = 25 Or $i =38 Then
$a_hBMP[$i][0] = $j -13
$a_hBMP[$i][1] = $i +1
$a_hBMP[$i][2] = _WinAPI_LoadBitmap ($hInstance, $a_hBMP[$i][0])
Else
$a_hBMP[$i][0] = $j
$a_hBMP[$i][1] = $i +1
$a_hBMP[$i][2] = _WinAPI_LoadBitmap ($hInstance, $a_hBMP[$i][0])
EndIf
$j += 1
Next
$j = 2
For $i = 39 To 50
$a_hBMP[$i][0] = $j
$a_hBMP[$i][1] = $i +1
$a_hBMP[$i][2] = _WinAPI_LoadBitmap ($hInstance, $a_hBMP[$i][0])
$j += 1
Next
$a_hBMP[51][0] = 1
$a_hBMP[51][1] = 52
$a_hBMP[51][2] = _WinAPI_LoadBitmap ($hInstance, $a_hBMP[51][0])
If $mixed Then
; 获取随机顺序
Local $aImagesIndex[52], $RandomIndex
For $i = 0 To 51
Do
$RandomIndex = Random(0, 51, 1)
_ArraySearch($aImagesIndex, String($RandomIndex))
If @error Then $aImagesIndex[$i] = String($RandomIndex)
Until $aImagesIndex[$i]
Next
;设置BMP处理随机顺序
Local $aTmp[52][3]
For $i = 0 To UBound($aTmp) -1
$aTmp[$i][0] = $a_hBMP[$aImagesIndex[$i]][0]
$aTmp[$i][1] = $a_hBMP[$aImagesIndex[$i]][1]
$aTmp[$i][2] = $a_hBMP[$aImagesIndex[$i]][2]
Next
; 内部排序
_ArraySort($aTmp, 0, 0, 12, 1)
_ArraySort($aTmp, 0, 13, 25, 1)
_ArraySort($aTmp, 0, 26, 38, 1)
_ArraySort($aTmp, 0, 39, 51, 1)
$a_hBMP = $aTmp
$aTmp = 0
EndIf
; 创建GUI
Local $title='清一色纸牌'
If $mixed Then $title = '随机纸牌'
$hGUI = GUICreate ($title, 710, 350)
GUISetBkColor(0x008000)
GUISetState ()
; 初始化GDI+库
_GDIPlus_Startup ()
; 通过位图句柄创建对象
For $i = 0 To UBound($a_hBitmap) -1
$a_hBitmap[$i] = _GDIPlus_BitmapCreateFromHBITMAP ($a_hBMP[$i][2])
Next
; 通过窗口句柄创建一个图形对象
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
; 绘制所有的位图对象
Local $x = 20, $y = 20, $count
For $i = 0 To UBound($a_hBitmap) -1
$count = $i +1
_GDIPlus_GraphicsDrawImage ($hGraphic, $a_hBitmap[$i], $x, $y)
If $i > 1 And Mod($count, 13) = 0 Then
$x += 100
Else
$x += 20
EndIf
If $i = 25 Then
$x = 20
$y += 140
EndIf
Next
;循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; 清理资源
For $i = 0 To UBound($a_hBitmap) -1
_GDIPlus_ImageDispose ($a_hBitmap[$i])
_WinAPI_DeleteObject ($a_hBMP[$i][2])
Next
_WinAPI_FreeLibrary ($hInstance)
; 关闭GDI+库
_GDIPlus_ShutDown ()
GUIDelete()
EndFunc ;==>_Main
winxp+autoit3.3.6.1下测试通过
|