Показать полную графическую версию : [решено] Открытие dll библиотеки иконок
eus_deus
12-10-2013, 21:38
Привет! Нужно открывать библиотеку, выбирать иконку, и писать в переменные имя и номер иконки.
Пробовал DllCall - количество иконок ограничено 500, не хватает.
Смотрел на IconChoser.au3 - открыть файл получилось нормально, но выбора настроить не смог и не нашел правильного. Хотя этот вариант открыл все иконки с библиотеки.
Кто что может предложить?
Нужно открывать библиотеку, выбирать иконку, и писать в переменные имя и номер иконки. »
Для чего?
eus_deus
13-10-2013, 15:05
для выбора иконки с файла и получения строки вида - имя файла, иконка. Для использования потом в коде
для выбора иконки с файла и получения строки вида - имя файла, иконка. Для использования потом в коде »
#include (http://autoit-script.ru/autoit3_docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://autoit-script.ru/autoit3_docs/keywords.htm##include) <WindowsConstants.au3>
#include (http://autoit-script.ru/autoit3_docs/keywords.htm##include) <Array.au3>
#include (http://autoit-script.ru/autoit3_docs/keywords.htm##include) <WinAPI.au3>
$hGUI = GUICreate (http://autoit-script.ru/autoit3_docs/functions/GUICreate.htm)('Icons', 150, 150, -1, -1, BitOR (http://autoit-script.ru/autoit3_docs/functions/BitOR.htm)($WS_POPUP, $WS_BORDER))
GUISetState (http://autoit-script.ru/autoit3_docs/functions/GUISetState.htm)(@SW_SHOW (http://autoit-script.ru/autoit3_docs/macros.htm#@sw_show), $hGUI)
$iLoading_Lbl = GUICtrlCreateLabel (http://autoit-script.ru/autoit3_docs/functions/GUICtrlCreateLabel.htm)('Loading...', 10, 10)
$aIcons = _LoadIcons('shell32.dll')
$iRandom = Random (http://autoit-script.ru/autoit3_docs/functions/Random.htm)(1, $aIcons[0][0], 1)
$iCenter = (150 / 2) - (32 / 2)
GUICtrlDelete (http://autoit-script.ru/autoit3_docs/functions/GUICtrlDelete.htm)($iLoading_Lbl)
GUICtrlCreateIcon (http://autoit-script.ru/autoit3_docs/functions/GUICtrlCreateIcon.htm)($aIcons[$iRandom][0], $aIcons[$iRandom][1], $iCenter, $iCenter, 32, 32)
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$iMsg = GUIGetMsg (http://autoit-script.ru/autoit3_docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $iMsg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _LoadIcons($sFile)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iIcons = _WinAPI_ExtractIconEx (http://autoit-script.ru/autoit3_docs/libfunctions/_winapi_extracticonex.htm)($sFile, -1, 0, 0, -1)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aIcons[$iIcons + 1][2] = [[$iIcons]]
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $iIcons
$aIcons[$i][0] = $sFile
$aIcons[$i][1] = -$i
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $aIcons
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
eus_deus
14-10-2013, 16:12
Creat0R, ладно, понял - фигню. сморозил, фигню и получил.
Код нужен вот такого назначения, чтобы
выбора иконки с файла и получения строки вида - имя файла, иконка »
Func _iconselect()
$stIcon = DllStructCreate('int') ;Структура для номера иконки
;преобразование строки имени файла в Unicode
$nBuffersize = DllCall('KERNEL32.DLL', _
'int', 'MultiByteToWideChar', _
'int', 0, _
'int', 0x00000001, _
'str', $sFileName, _
'int', -1, _
'ptr', 0, _
'int', 0)
$stString = DLLStructCreate("byte[" & 2 * $nBuffersize[0] & "]")
DllCall('KERNEL32.DLL', _
'int', 'MultiByteToWideChar', _
'int', 0, _
'int', 0x00000001, _
'str', $sFileName, _
'int', -1, _
'ptr', DllStructGetPtr($stString), _
'int', $nBuffersize[0])
;Вызов функции диалога выбора значков
DllCall('shell32.dll', _
'none', 62, _
'hwnd', 0, _
'ptr', DllStructGetPtr($stString), _
'int', DllStructGetSize($stString), _
'ptr', DllStructGetPtr($stIcon))
;обратное преобразование строки имени файла в однобайтную кодировку
$nBuffersize = DllCall('KERNEL32.DLL', _
'int', 'WideCharToMultiByte', _
'int', 0, _
'int', 0x00000200, _
'ptr', DllStructGetPtr($stString), _
'int', -1, _
'ptr', 0, _
'int', 0, _
'ptr', 0, _
'ptr', 0)
$stFile = DLLStructCreate('char[' & $nBuffersize[0] & ']')
DllCall('KERNEL32.DLL', _
'int', 'WideCharToMultiByte', _
'int', 0, _
'int', 0x00000200, _
'ptr', DllStructGetPtr($stString), _
'int', -1, _
'ptr', DllStructGetPtr($stFile), _
'int', $nBuffersize[0], _
'ptr', 0, _
'ptr', 0)
$sFileName = DllStructGetData($stFile, 1)
$nIconIndex = DllStructGetData($stIcon, 1) ;Получение номера иконки
;Контрольное сообщение
; Msgbox(262192, 'Info', _
; 'Выбран файл: ' & $sFileName & @CR & _
; 'Иконка: ' & $nIconIndex)
GUICtrlSetData($sInput4, $nIconIndex)
$stBuffer = 0
$stFile = 0
$stIcon = 0
EndFunc
Но этот открывает только не более 500 иконок с библиотеки
Код нужен вот такого назначения »
Т.е нужно просто вывести на экран диалог выбора иконки, и получить выбранную в нём иконку?
А так:
$aRet = _PickIconDlg('shell32.dll', 2, WinGetHandle (http://autoit-script.ru/autoit3_docs/functions/WinGetHandle.htm)(''))
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) @error (http://autoit-script.ru/autoit3_docs/macros.htm#@error) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
ConsoleWrite (http://autoit-script.ru/autoit3_docs/functions/ConsoleWrite.htm)('Icon: ' & $aRet[0] & @LF (http://autoit-script.ru/autoit3_docs/macros.htm#@lf))
ConsoleWrite (http://autoit-script.ru/autoit3_docs/functions/ConsoleWrite.htm)('ID: ' & $aRet[1] & @LF (http://autoit-script.ru/autoit3_docs/macros.htm#@lf))
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
;Open Dialog to pick an icon of certain file.
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _PickIconDlg($sFileName, $nIconIndex = 0, $hWnd = 0)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $nRet, $aRetArr[2]
$nRet = DllCall (http://autoit-script.ru/autoit3_docs/functions/DllCall.htm)("shell32.dll", "int", "PickIconDlg", "hwnd", $hWnd, "wstr", $sFileName, "int", 1000, "int*", $nIconIndex)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @error (http://autoit-script.ru/autoit3_docs/macros.htm#@error) Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) $nRet[0] Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) SetError (http://autoit-script.ru/autoit3_docs/functions/SetError.htm)(1, 0, -1)
$aRetArr[0] = $nRet[2]
$aRetArr[1] = $nRet[4]
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $aRetArr
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
eus_deus
14-10-2013, 21:27
Т.е нужно просто вывести на экран диалог выбора иконки, и получить выбранную в нём иконку? »
да, вот только
открывает только не более 500 иконок с библиотеки »
а нужна вся библиотека
eus_deus,
1. Известно что иконку можно вытащить по номеру
2. Известно что ListView может отобразить иконки в соотвествующем стиле
От вас требуется запустить цикл запроса иконок и тупо вставить их в ListView. Когда цикл перестанет возвращать иконки, значит они закончились и сделать выход из цикла.
eus_deus
16-10-2013, 15:11
AZJIO, все так просто? Вечером обязательно попробую))
eus_deus
16-10-2013, 20:45
не все просто)) ладно, фиг с ним, другим займусь
Есть ещё "C:\Program Files\AutoIt3\Examples\GUI\Advanced\enumicons.au3"
Маленькие иконки 16х16
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
_Main()
Func _Main()
Local $hImgLst, $hGui, $hLV, $n, $sPath
; Создаёт GUI и элементы
$hGui = GUICreate("Иконки", 200, 560, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_POPUP)
$hLV = GUICtrlCreateListView('Иконки', 3, 3, 200 - 10, 560 - 10)
$sPath = @SystemDir & '\shell32.dll'
; $sPath = @SystemDir & '\wmploc.dll'
; Загружает изображения
$hImgLst = _GUIImageList_Create(16, 16, 5, 1 + 4, 0, 1)
$n = 0
Do
_GUIImageList_AddIcon($hImgLst, $sPath, $n)
$n += 1
Until @error
_GUICtrlListView_SetImageList($hLV, $hImgLst, 1)
$n -= 2
WinSetTitle($hGui, '', $n + 1 & ' иконок')
For $i = 0 To $n
_GUICtrlListView_AddItem($hLV, $i, $i)
Next
GUISetState()
While 1
Switch GUIGetMsg()
Case -3
Exit
EndSwitch
WEnd
EndFunc ;==>_Main
Большие иконки 32х32
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
_Main()
Func _Main()
Local $hImgLst, $hGui, $hLV, $n, $sPath
; Создаёт GUI и элементы
$hGui = GUICreate("Иконки", 700, 560, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_POPUP)
$hLV = GUICtrlCreateListView('Иконки', 3, 3, 700 - 10, 560 - 10, $LVS_LIST + $LVS_ICON)
$sPath = @SystemDir & '\shell32.dll'
; $sPath = @SystemDir & '\wmploc.dll'
; Загружает изображения
$hImgLst = _GUIImageList_Create(32, 32, 5, 1 + 4, 0, 1)
$n = 0
Do
_GUIImageList_AddIcon($hImgLst, $sPath, $n, True)
$n += 1
Until @error
_GUICtrlListView_SetImageList($hLV, $hImgLst, 1)
$n -= 2
WinSetTitle($hGui, '', $n + 1 & ' иконок')
For $i = 0 To $n
_GUICtrlListView_AddItem($hLV, $i, $i)
Next
; _GUICtrlListView_SetView($hLV, 3)
GUISetState()
While 1
Switch GUIGetMsg()
Case -3
Exit
EndSwitch
WEnd
EndFunc ;==>_Main
eus_deus
20-10-2013, 17:00
спасибо, буду пробовать подстроить под себя
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.