RE: Win API question

new topic     » goto parent     » topic index » view thread      » older message » newer message

I figured it out :)  Here's a demo that will give the small icon for an 
associated file.

--begin code

include win32lib.ew
without warning

constant
  Win = create( Window, "Win", 0, Default, Default, 100, 100, 0 ),
  Icn = create( Icon, "", Win, 35, 20, 16, 16, 0 )

constant xSHGetFileInfo = registerw32Function( shell32,
  "SHGetFileInfoA", { C_POINTER, C_INT, C_POINTER, C_INT, C_INT },
  C_INT )
     
constant hIcon = allot( Hndl ),
         iIcon = allot( Int32 ),
         dwAttributes = allot( DWord ),
         szDisplayName = allot( Strz ),
         szTypeName = allot( Strz ),
         SIZEOF_SHFILEINFO = allotted_size()

function getSmallIcon( sequence path )

  atom pszPath, SHFileInfo_STRUCT, icon, mem
   
  mem = new_memset()
  SHFileInfo_STRUCT = acquire_mem( mem, SIZEOF_SHFILEINFO )

  pszPath = allocate_string( path )

  VOID = w32Func( xSHGetFileInfo, { pszPath, 0, SHFileInfo_STRUCT,
    SIZEOF_SHFILEINFO, or_all( { SHGFI_ICON, SHGFI_SMALLICON } ) } )
   
  icon = fetch( SHFileInfo_STRUCT, hIcon )
   
  free( pszPath )
  release_mem( mem )

  return icon
   
end function

procedure clickWin( integer self, integer event, sequence params )
          
  setIcon( Icn, getSmallIcon( getOpenFileName(Win, "", {}) ) )

end procedure
setHandler( Win, w32HClick, routine_id( "clickWin" ) )

WinMain( Win, Normal )

--end code

Thanks for your help,
Phil

Brian Broker wrote:
> 
> 
> You can't get the small icon using ExtractAssociatedIcon. The 
> CreateIconFromResource, DrawIcon, ExtractAssociatedIcon, ExtractIcon, 
> ExtractIconEx, and LoadIcon functions all use system large icons.  If I 
> figure out a way to do it, I'll let you know...
> 
> -- Brian
> 
> Philip Deets wrote:
> > 
> > 
> > Ok, I see that is one way I could get the small icon, but is there a way 
> > 
> > for 
> > me to know what file to look in?  That is why I was using 
> > getAssociatedIcon, 
> > because I won't know what file to look in for the icon.  How can I get 
> > small 
> > icons with the getAssociatedIcon function?
> > 
> > ------
> > 
> > Brian Broker wrote:
> > 
> > Hi Philip,
> > 
> > Here's a demo that extracts the large and small icons directly from
> > shell32.dll:
> > 
> > include win32lib.ew
> > without warning
> > 
> > constant
> >     Win = create( Window, "Win", 0, Default, Default, 100, 100, 0 ),
> >     Big_Icon = create( Icon, "", Win, 35, 20, 0, 0, 0 ),
> >     Small_Icon = create( Icon, "", Win, 10, 20, 0, 0, 0 )
> > 
> > constant
> >     xExtractIconEx = registerw32Function(shell32, "ExtractIconExA",
> > {C_POINTER, C_INT, C_POINTER, C_POINTER, C_UINT}, C_UINT)
> > 
> > procedure init( integer self, integer event, sequence params )
> >     integer icon
> >     atom lpszFile, phiconLarge, phiconSmall
> > 
> >     lpszFile = allocate_string( "shell32.dll" )
> >     phiconLarge = allocate(4)
> >     phiconSmall = allocate(4)
> >     -- get total number of icons in file
> >     --icon = w32Func( xExtractIconEx, { lpszFile, -1, 0, 0, 0 } )
> > 
> >     -- extract large and small txt doc icons
> >     icon = w32Func( xExtractIconEx, { lpszFile, 70, phiconLarge,
> > phiconSmall, 1 } )
> > 
> >     setIcon( Small_Icon, peek4u(phiconSmall) )
> >     setIcon( Big_Icon, peek4u(phiconLarge) )
> >     -- compare small icon to squished large icon in window
> >     setIcon( Win, peek4u(phiconLarge) )
> > 
> >     free( lpszFile )
> >     free( phiconLarge )
> >     free( phiconSmall )
> > end procedure
> > setHandler( Win,w32HOpen,routine_id("init") )
> > 
> > WinMain( Win, Normal )
> > 
> > -- Brian
> > 
> > Philip Deets wrote:
> >  >
> >  >
> >  > I just tried every number from 1 to 10, none of them look any different,
> >  >
> >  > they all look crammed.
> >  >
> >  > Also, where can I find an icon editor?  I don't have one.
> >  >
> >  > Phil
> >  >
> >  >
> >  > ------
> >  >
> >  > Bernie Ryan wrote:
> >  >
> >  >  >Yes, but how do I get it to display the 16x16 version of the icon
> >  >  >instead of the crammed 32x32 version?
> >  >
> >  > Philip:
> >  >
> >  >     I look at the ICON used on NotePad and it contains 8 icons.
> >  >     first, forth, and eight icons are the smallest icons.
> >  >
> >  > icon = addIcon( w32Func( xExtractAssociatedIcon,
> >  >        { 0, "C:\\myfile.txt", 0 } ) )
> >  >
> >  > In the last parameter you used index zero which will try to use a
> >  > default
<snip>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu