Sign in to follow this  
Followers 0
jercfd

Check if file is icon

5 posts in this topic

#1 ·  Posted (edited)

How can I check if a file is an icon?

The header of an icon is below. I am only interested in offset 0 and 2.

Offset#   Size   Purpose
0         2      reserved. should always be 0
2         2      type. 1 for icon (.ICO), 2 for cursor (.CUR) file
4         2      count; number of images in the file

In hex, it would look like this

00 00 01 00 0# 00
# = number of images in file

Also, if there is any other method to check if a file is an icon, I would gladly like to know.

Edited by jercfd

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

How can I check if a file is an icon?

The header of an icon is below. I am only interested in offset 0 and 2.

Offset#   Size   Purpose
0         2      reserved. should always be 0
2         2      type. 1 for icon (.ICO), 2 for cursor (.CUR) file
4         2      count; number of images in the file

In hex, it would look like this

00 00 01 00 0# 00
# = number of images in file

Also, if there is any other method to check if a file is an icon, I would gladly like to know.

#Include <GDIPlus.au3>



if IsIconFile("C:\au3.ico") Then
MsgBox(0,"Chk","IconFile")
Else
MsgBox(0,"Chk","Another file")
EndIf

Func IsIconFile($sFileName)
Local $Modhwnd , $hImage
  _GDIPlus_Startup ()
$hImage = _GDIPlus_ImageLoadFromFile($sFileName)
_GDIPlus_ShutDown ()
if Not ($hImage) Then Return False
_WinAPI_DeleteObject ($hImage)
$Modhwnd = _WinAPI_GetModuleHandle(0)
$HICON = DllCall("shell32.dll","hwnd","ExtractIcon","hwnd",$Modhwnd,"str",$sFileName,"int",0)
if Not ($HICON[0]) Then Return False
_WinAPI_DestroyIcon($HICON[0])
Return True
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

Thanks wolf9228. This will work for me

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0