#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_File_Add=flag1.png, PNG, 200
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;~ AutoIt Version: 3.3.8.1+
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
Opt('MustDeclareVars', 1)
Global Const $a__TableFlags[2][2] = [[@ScriptDir & '\flag1.png'],['PNG', 200]]
If Not @Compiled Then
If Not FileExists($a__TableFlags[0][0]) Then Exit 13
EndIf
_Example_1('NR')
_Example_2()
_Example_3()
Func _Example_3()
Local $a_Country[26 ^ 2], $i_Ind, $s_Chr, $h_Gui, $h_IL, $ah_HBitmap, $h_ListView, $s_TD
For $i = 0 To 25
$s_Chr = Chr($i + 65)
For $j = 0 To 25
$a_Country[$i_Ind] = $s_Chr & Chr($j + 65)
$i_Ind += 1
Next
Next
$s_Chr = ''
$i_Ind = 0
$h_IL = _GUIImageList_Create(16, 11, 5)
;~ ---
Local $i_Timer = TimerInit()
;~ ---
$ah_HBitmap = _GetCountryFlagHBitmapArrayEx($a_Country)
If @error Then
If @Compiled Then
Return MsgBox(16, 'Error', 'Error _Example_3 _GetCountryFlagHBitmapArrayEx')
Else
Return ConsoleWrite('! Error' & @LF)
EndIf
EndIf
For $i = 0 To UBound($ah_HBitmap) - 1
_GUIImageList_Add($h_IL, $ah_HBitmap[$i])
_WinAPI_DeleteObject($ah_HBitmap[$i])
Next
$ah_HBitmap = 0
$s_TD = StringFormat('TimerDiff: %d msec', Round(TimerDiff($i_Timer)))
$h_Gui = GUICreate('Example_3', 250, 270)
GUICtrlCreateLabel($s_TD, 5, 5, 240, 20, BitOR($GUI_SS_DEFAULT_LABEL, $SS_CENTER, $SS_CENTERIMAGE))
$h_ListView = GUICtrlCreateListView('', 10, 30, 230, 230)
_GUICtrlListView_SetImageList($h_ListView, $h_IL, 1)
_GUICtrlListView_AddColumn($h_ListView, 'Country', 200)
For $i = 0 To UBound($a_Country) - 1
_GUICtrlListView_AddItem($h_ListView, $a_Country[$i], $i)
Next
$a_Country = 0
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
_GUIImageList_Destroy($h_IL)
GUIDelete()
EndFunc ;==>_Example_3
Func _Example_2()
Local $a_Country[11] = ['BA', 'MA', 'GB', 'IL', 'FO', 'PY', 'MO', 'NL', 'RU', 'KZ', 'ZZ'], $h_Gui, $h_IL, $ah_HBitmap, $h_ListView, $s_TD
$h_IL = _GUIImageList_Create(16, 11, 5)
;~ ---
Local $i_Timer = TimerInit()
;~ ---
$ah_HBitmap = _GetCountryFlagHBitmapArrayEx($a_Country)
If @error Then
If @Compiled Then
Return MsgBox(16, 'Error', 'Error _Example_2 _GetCountryFlagHBitmapArrayEx')
Else
Return ConsoleWrite('! Error' & @LF)
EndIf
EndIf
For $i = 0 To UBound($ah_HBitmap) - 1
_GUIImageList_Add($h_IL, $ah_HBitmap[$i])
_WinAPI_DeleteObject($ah_HBitmap[$i])
Next
$ah_HBitmap = 0
$s_TD = StringFormat('TimerDiff: %d msec', Round(TimerDiff($i_Timer)))
$h_Gui = GUICreate('Example_2', 250, 270)
GUICtrlCreateLabel($s_TD, 5, 5, 240, 20, BitOR($GUI_SS_DEFAULT_LABEL, $SS_CENTER, $SS_CENTERIMAGE))
$h_ListView = GUICtrlCreateListView('', 10, 30, 230, 230)
_GUICtrlListView_SetImageList($h_ListView, $h_IL, 1)
_GUICtrlListView_AddColumn($h_ListView, 'Country', 200)
For $i = 0 To UBound($a_Country) - 1
_GUICtrlListView_AddItem($h_ListView, $a_Country[$i], $i)
Next
$a_Country = 0
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
_GUIImageList_Destroy($h_IL)
GUIDelete()
EndFunc ;==>_Example_2
Func _Example_1($s_Country)
Local Const $__STM_SETIMAGE = 0x0172
Local $h_Gui, $i_Pic, $ah_HBitmap, $s_TD
;~ ---
Local $i_Timer = TimerInit()
;~ ---
$ah_HBitmap = _GetCountryFlagHBitmapArrayEx($s_Country)
If @error Then
If @Compiled Then
Return MsgBox(16, 'Error', 'Error _Example_1 _GetCountryFlagHBitmapArrayEx')
Else
Return ConsoleWrite('! Error' & @LF)
EndIf
EndIf
$s_TD = StringFormat('TimerDiff: %d msec', Round(TimerDiff($i_Timer)))
$h_Gui = GUICreate('1', 150, 76)
GUICtrlCreateLabel($s_TD, 5, 5, 140, 20, BitOR($GUI_SS_DEFAULT_LABEL, $SS_CENTER, $SS_CENTERIMAGE))
$i_Pic = GUICtrlCreatePic('', 67, 45, 16, 11)
GUICtrlSendMsg($i_Pic, $__STM_SETIMAGE, 0, $ah_HBitmap[0])
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
_WinAPI_DeleteObject($ah_HBitmap[0])
GUIDelete()
EndFunc ;==>_Example_1
Func _GetCountryFlagHBitmapArrayEx($v_Country)
Local Const $ai_Size[2] = [16, 11], $a_StartOffSet[2] = [20, 12]
Local $i_Ub, $a_Tmp, $h_Image, $h_Frame, $i_Err = 1
$i_Ub = UBound($v_Country)
If $i_Ub Then
Local $a_OffSet[$i_Ub][2]
Local $ah_HBitmap[$i_Ub]
For $i = 0 To $i_Ub - 1
If StringRegExp($v_Country[$i], '[^A-Z]') Or StringLen($v_Country[$i]) <> 2 Then Return SetError(-1, 0, 0)
$a_Tmp = StringSplit($v_Country[$i], '', 2)
For $j = 0 To 1
$a_OffSet[$i][$j] = $a_StartOffSet[$j] + (Asc($a_Tmp[$j]) - 65) * $ai_Size[$j]
Next
Next
Else
If StringRegExp($v_Country, '[^A-Z]') Or StringLen($v_Country) <> 2 Then Return SetError(-1, 0, 0)
Local $a_OffSet[1][2]
Local $ah_HBitmap[1]
$a_Tmp = StringSplit($v_Country, '', 2)
For $j = 0 To 1
$a_OffSet[0][$j] = $a_StartOffSet[$j] + (Asc($a_Tmp[$j]) - 65) * $ai_Size[$j]
Next
EndIf
_GDIPlus_Startup()
Do
$h_Image = __Load_Image()
If @error Then ExitLoop
For $i = 0 To UBound($ah_HBitmap) - 1
$h_Frame = _GDIPlus_BitmapCloneArea($h_Image, $a_OffSet[$i][0], $a_OffSet[$i][1], $ai_Size[0], $ai_Size[1], $GDIP_PXF32ARGB)
If Not $h_Frame Then ExitLoop 2
$ah_HBitmap[$i] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($h_Frame)
_GDIPlus_ImageDispose($h_Frame)
$h_Frame = 0
If Not $ah_HBitmap[$i] Then ExitLoop 2
Next
$i_Err = 0
Until 1
If ($h_Image) And ($h_Image <> -1) Then _GDIPlus_ImageDispose($h_Image)
If $h_Frame Then _GDIPlus_ImageDispose($h_Frame)
_GDIPlus_Shutdown()
If $i_Err Then Return SetError(1, 0, 0)
Return $ah_HBitmap
EndFunc ;==>_GetCountryFlagHBitmapArrayEx
Func __Load_Image()
Local $h_Image, $a_Res
If @Compiled Then
Do
Local $i_Err = 1, $h_SelfModule, $h_Inf, $h_Res, $ai_Size, $p_Res, $h_Mem, $p_Mem, $h_Stream, $h_Image
$a_Res = DllCall('kernel32.dll', 'handle', 'GetModuleHandleW', 'ptr', 0)
If (@error) Or (Not $a_Res[0]) Then ExitLoop
$h_SelfModule = $a_Res[0]
$a_Res = DllCall('kernel32.dll', 'ptr', 'FindResourceW', 'handle', $h_SelfModule, 'int', $a__TableFlags[@Compiled][1], 'wstr', $a__TableFlags[@Compiled][0])
If (@error) Or (Not $a_Res[0]) Then ExitLoop
$h_Inf = $a_Res[0]
$a_Res = DllCall('kernel32.dll', 'ptr', 'LoadResource', 'handle', $h_SelfModule, 'ptr', $h_Inf)
If (@error) Or (Not $a_Res[0]) Then ExitLoop
$h_Res = $a_Res[0]
$a_Res = DllCall('kernel32.dll', 'dword', 'SizeofResource', 'handle', $h_SelfModule, 'ptr', $h_Inf)
If (@error) Or (Not $a_Res[0]) Then ExitLoop
$ai_Size = $a_Res[0]
$a_Res = DllCall('kernel32.dll', 'ptr', 'LockResource', 'ptr', $h_Res)
If (@error) Or (Not $a_Res[0]) Then ExitLoop
$p_Res = $a_Res[0]
$a_Res = DllCall('kernel32.dll', 'handle', 'GlobalAlloc', 'uint', 0x0002, 'ulong_ptr', $ai_Size);$GMEM_MOVEABLE = 0x0002
If (@error) Or (Not $a_Res[0]) Then ExitLoop
$h_Mem = $a_Res[0]
$a_Res = DllCall('kernel32.dll', 'ptr', 'GlobalLock', 'ptr', $h_Mem)
If (@error) Or (Not $a_Res[0]) Then ExitLoop
$p_Mem = $a_Res[0]
DllCall('kernel32.dll', 'none', 'RtlMoveMemory', 'ptr', $p_Mem, 'ptr', $p_Res, 'ulong_ptr', $ai_Size)
If @error Then ExitLoop
$a_Res = DllCall('kernel32.dll', 'int', 'GlobalUnlock', 'ptr', $h_Mem)
If (@error) Or ($a_Res[0]) Then ExitLoop
$a_Res = DllCall('ole32.dll', 'uint', 'CreateStreamOnHGlobal', 'ptr', $h_Mem, 'int', 1, 'ptr*', 0)
If (@error) Or ($a_Res[0]) Then ExitLoop
$h_Stream = $a_Res[3]
$a_Res = DllCall('gdiplus.dll', 'uint', 'GdipCreateBitmapFromStream', 'ptr', $h_Stream, 'ptr*', 0)
If (@error) Or ($a_Res[0]) Or (Not $a_Res[2]) Then ExitLoop
$h_Image = $a_Res[2]
$a_Res = DllCall('oleaut32.dll', 'uint', 'DispCallFunc', 'ptr', $h_Stream, 'uint', 8 * (1 + @AutoItX64), 'uint', 4, _
'uint', 23, 'uint', 0, 'ptr', 0, 'ptr', 0, 'str', '')
If (@error) Or ($a_Res[0]) Then ExitLoop
$h_Stream = 0
$a_Res = DllCall('kernel32.dll', 'ptr', 'GlobalFree', 'ptr', $h_Mem)
If (@error) Or ($a_Res[0]) Then ExitLoop
$h_Mem = 0
$i_Err = 0
Until 1
If $i_Err Then
If $h_Stream Then DllCall('oleaut32.dll', 'uint', 'DispCallFunc', 'ptr', $h_Stream, 'uint', 8 * (1 + @AutoItX64), 'uint', 4, _
'uint', 23, 'uint', 0, 'ptr', 0, 'ptr', 0, 'str', '')
If $h_Mem Then DllCall('kernel32.dll', 'ptr', 'GlobalFree', 'ptr', $h_Mem)
If ($h_Image) And ($h_Image <> -1) Then _GDIPlus_ImageDispose($h_Image)
Return SetError(1, 0, 0)
EndIf
Else
$h_Image = _GDIPlus_ImageLoadFromFile($a__TableFlags[@Compiled][0])
If @error Then Return SetError(1, 0, 0)
EndIf
Return $h_Image
EndFunc ;==>__Load_Image