直接调用系统shell32.dll获取图标,也可以自已选文件

;小古提取自compile ahk.ahk

	; icon fix for Win9x by Drugwash
	if A_OSType in WIN32_WINDOWS
		shell := A_WinDir . "systemshell32.dll"
	else
		shell := A_WinDir . "system32shell32.dll"
	VarSetCapacity(SourceFile , 260)
	SourceFile := shell
	nIndex := 0

	; WinGet , hWnd , ID , PickIconDlg
	WinGet , hWnd , ID , A
	
	; icon fix for Win9x by Drugwash
	if A_OSType in WIN32_WINDOWS
	{
		If !DllCall(DllCall("GetProcAddress", "Uint", DllCall("LoadLibrary", "str", "shell32.dll"), "Uint", 62), "Uint", hWnd, "Uint", &SourceFile, "Uint", 260, "intP", nIndex)
			Return ; cancel was clicked or something else failed
		DllCall("FreeLibrary", "str", "shell32.dll")
	}
	else
	{
		; VarSetCapacity(wSourceFile , 260 * 2)
		; DllCall("MultiByteToWideChar" , "Uint" , 0 , "Uint" , 0 , "str" , SourceFile , "int" , -1 , "str" , wSourceFile , "int" , 260)
		If !(A_IsUnicode) 
		{ 
			 VarSetCapacity(wSourceFile , 260 * 2) 
			 DllCall("MultiByteToWideChar" , "Uint" , 0 , "Uint" , 0 , "str" , SourceFile , "int" , -1 , "str" , wSourceFile , "int" , 260) 
		} 
		Else 
		{ 
			 wSourceFile := SourceFile 
		}  
	
		If !DllCall("shell32PickIconDlg" , "Uint" , hWnd , "str" , wSourceFile , "Uint" , 260 , "intP" , nIndex)
			Return ; cancel was clicked or something else failed
	
		; VarSetCapacity(SourceFile , 260)
		; DllCall("WideCharToMultiByte" , "Uint" , 0 , "Uint" , 0 , "str" , wSourceFile , "int" , -1 , "str" , SourceFile , "int" , 260 , "Uint" , 0 , "Uint" , 0)
		If !(A_IsUnicode) 
		{ 
			 VarSetCapacity(SourceFile , 260) 
			 DllCall("WideCharToMultiByte" , "Uint" , 0 , "Uint" , 0 , "str" , wSourceFile , "int" , -1 , "str" , SourceFile , "int" , 260 , "Uint" , 0 , "Uint" , 0) 
		} 
		Else 
		{ 
			 SourceFile := wSourceFile 
    }  
	
		StringReplace , SourceFile , SourceFile , `%SystemRoot`% , %A_WinDir%
	}
	


	msgbox %SourceFile%,%nIndex%
	
	
	
	
	
	
	
	
	
	
	
	
	; --------------------------------------------------------------------------------
; ERROR EXIT
; --------------------------------------------------------------------------------
_Error(sMSG)
{
	Msgbox , 262160 , %MSG_TITLE% , %sMSG%
}

_Error_Exit(sMSG)
{
	global SaveIniInScript, Ini_File
	FileAppend , `n`n* ~~~ ERROR_EXIT ~~~ *`n`n%sMSG% , %A_WorkingDir%%Log_File%
	Msgbox , 262160 , %MSG_TITLE% , %sMSG%
	If SaveIniInScript
		FileDelete , %Ini_File%
	_EXIT(1)
}
_EXIT(ExitCode = 1)
{
	ExitApp , %ExitCode%
}
	
	
	; --------------------------------------------------------------------------------
; Get IconGroupID / ResourceID from IconIndex
; --------------------------------------------------------------------------------
ResourceIdOfIcon(Filename , IconIndex)
{
	hmod := DllCall("GetModuleHandle" , "str" , Filename)
	; If the DLL isn't already loaded , load it as a data file.
	loaded := !hmod
	&& hmod := DllCall("LoadLibraryEx" , "str" , Filename , "uint" , 0 , "uint" , 0x2)

	if !hmod
		Return

	enumproc := RegisterCallback("ResourceIdOfIcon_EnumIconResources" , "F")
	VarSetCapacity(Param , 12 , 0) , NumPut(IconIndex , Param , 0)
	; to work with enabled DEP --> http://www.autohotkey.com/forum/viewtopic.php?t=25480
	DllCall("VirtualProtect", "uint", enumproc, "uint", 8, "uint", 0x40, "uint*", 0)
	; Enumerate the icon group resources. (RT_GROUP_ICON=14)
	DllCall("EnumResourceNames" , "uint" , hmod , "uint" , 14 , "uint" , enumproc , "uint" , &Param)
	DllCall("GlobalFree" , "uint" , enumproc)

	; If we loaded the DLL , free it now.
	if loaded
		DllCall("FreeLibrary" , "uint" , hmod)

	Return NumGet(Param , 8) ? NumGet(Param , 4) : ""
}

ResourceIdOfIcon_EnumIconResources(hModule , lpszType , lpszName , lParam)
{
	Index := NumGet(lParam+4)
	if (Index = NumGet(lParam+0))
	{	; for named resources , lpszName might not be valid once we Return (?)
		; if (lpszName >> 16 == 0) , lpszName is an integer resource ID.
		NumPut(lpszName , lParam+4)
		NumPut(1 , lParam+8)
		Return false ; break
	}
	NumPut(Index+1 , lParam+4)
	Return true
}
; --------------------------------------------------------------------------------
; Check for valid Icon Path
; --------------------------------------------------------------------------------
CHECK_ICON(sPATH)
{
	Global
	Local sEXT
	SplitPath , sPATH , , , sEXT
	If (sEXT = "ICO") {
		If (FileExist(sPATH)) {
			Return True
		}
	}
	Return False
}



给TA捐赠
共{{data.count}}人
人已捐赠
其他

盲打练习器

2020-3-9 4:30:44

其他

短信群发单体版v2

2020-3-9 4:32:44

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索