Re: win32lib, LV's and icons

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

Wolf pointed out to me that I was incorrectly use
peek4signed when I should have been using
peek4unsigned which could have caused some problems
with error checking, thanks.  I also realized that my
extractIconEx didn't cohabitate with win32libs
addIcon(extractIcon()) pair.  I have slightly
rewritten the routine to take both of these things
into account.  It can still be found here;
http://home.attbi.com/~sea.star/code/lvextras.ew
I have converted the tabs to spaces so it should copy
better now, or a right-click save would work.  As
before it need to be pasted into win32lib.ew. I will
also paste it into this post per Dan's suggestion. 
Yahoo mail has a really narrow text box for writing
emails so it breaks the lines in wierd places.  I have
also rewritten the routine to test extractIconEx.  It
now calls addIcon(extractIcon()) then extractIconEx()
so you can see the difference between the two calls. 
Any problems or suggestions are always welcome.  Chris
cafromsw at yahoo.com

--paste into win32lib.ew--------------
-- Version 2003.01.12a CMA
-- Routines to extract both large (32x32) and small
(16x16) icons from .ico, .dll and .exe files
-- for use in ListViews that need both sizes.  Can
also be used as a replacement for
-- NewIco &= addIcon(extractIcon({"shell32.dll",1}))
-- Example:
-- NewIco &= extractIconEx({"shell32.dll", 1})
-- both examples return an index to the image list for
use in ListViews etc.
-- can be used as a replacement for or in conjuction
with addIcon(extractIcon())


global constant
	xExtractIconEx  = registerw32Function(shell32, 
				"ExtractIconEx", {C_POINTER, C_INT, C_POINTER,
C_POINTER, C_INT}, C_INT)

--global function extractIcon( sequence Filename )    
               -- REM'd by CMA 1.10.03
global function extractIconEx( sequence Filename )    
               -- added by CMA 1.10.03
  atom icon                                           
               -- REM'd by CMA 1.12.03
  integer lIdx
    
  atom lgico, smico                                   
               -- added by CMA 1.10.03
  object hIcon                                        
               -- added by CMA 1.12.03

  lIdx = 0
  if length(Filename) > 0 then
    if sequence(Filename[1]) then
      lIdx = Filename[2]-1
      Filename = Filename[1]
    end if
  end if

  lgico = acquire_mem(0, Long)                        
               -- added by CMA 1.10.03
  smico = acquire_mem(0, Long)                        
               -- added by CMA 1.10.03
  hIcon = w32Func( xExtractIconEx, {Filename, lIdx,
lgico, smico, 1} ) -- added by CMA 1.12.03
  if hIcon > 0 then                                   
               -- added by CMA 1.12.03
    ILAddIcon( ILlarge, peek4u(lgico) )               
               -- added by CMA 1.10.03
    ILAddIcon( ILsmall, peek4u(smico) )               
               -- added by CMA 1.10.03
    ilicon_list &= hIcon                              
               -- added by CMA 1.12.03
  end if                                              
               -- added by CMA 1.10.03
  release_mem(lgico)                                  
               -- added by CMA 1.10.03
  release_mem(smico)                                  
               -- added by CMA 1.10.03
  return length(ilicon_list)                          
               -- added by CMA 1.12.03
  
  --icon = w32Func( xExtractIcon, {0, Filename, lIdx}
)               -- REM'd by CMA 1.10.03
  --return icon                                       
               -- REM'd by CMA 1.10.03
end function
--end of extractIconEx()-----------------

--test program for extractIconEx()------
include win32lib.ew

constant Win1 = createEx( Window, "LV Test", 0,
Default, Default, 320, 350, 0, 0)

constant LV1 = createEx( ListView, {"Column 1"}, Win1,
4, 10, 300, 150,
                                   
or_all({LVS_REPORT,LVS_SHOWSELALWAYS}), 0)

constant LV2 = createEx( ListView, {"Column 1"}, Win1,
4, 170, 300, 150, 
                                   
or_all({LVS_ICON,LVS_SHOWSELALWAYS}), 0)
with trace
object OK

OK = setLVInsert(1)			-- append to end of list

seq sq sq = {}
seq NewIco NewIco = {}

NewIco &= addIcon(extractIcon({"shell32.dll",1}))
NewIco &= extractIconEx({"shell32.dll", 1})
NewIco &= addIcon(extractIcon("disks04.ico"))
NewIco &= extractIconEx("disks04.ico")
NewIco &= addIcon(extractIcon({"shell32.dll",2}))
NewIco &= extractIconEx({"shell32.dll", 2})

for i = 1 to length(NewIco) do
  OK = addLVItem(LV1, NewIco[i], "test line" &
sprint(i))
  sq = append(sq, {"test line" & sprint(i)})
end for

loadLVInfo(LV2, sq)

WinMain(Win1, Normal)


--- Dan Moyer <DANIELMOYER at prodigy.net> wrote:
> 
> Chris,
> 
> You might want to copy the code you put at your
> website directly into a
> posting here;  when I tried to copy it from your
> webpage into a file, it
> mysteriously dropped the "less than" symbol from the
> line:
> "  if length(Filename) > 0 then",
> even though it copied it *here* just fine.  Not sure
> if anything else gets
> mangled or not.
> 
> Dan Moyer
> 
> 
> ----- Original Message -----
> From: <cafromsw at yahoo.com>
> To: "EUforum" <EUforum at topica.com>
> Sent: Friday, January 10, 2003 4:55 PM
> Subject: win32lib, LV's and icons
> 
> 
> > Thanks to input form the list I was able to solve
> my
> > ListView icon problem.  It turns out that
> extractIcon
> > will only pull one icon from an .ico, .dll or .exe
> at
> > a time.  It then resizes that icon either up or
> down
> > to make it fit the iconLarge and iconSmall
> imageLists.
> > This is fine for some .ico files, but in .dll's,
> > namely shell32.dll the icons are grouped.  Group
> > 1(one) may have a 32x32, 16x16, and 48x48 icon in
> 16
> > colors and again in 256 colors.  After spending
> hours
> > browsing around the MSDN website I found that
> > extractIconEx will pull both a small 16x16 and a
> large
> > 32x32 icon for a given group index, at the same
> time.
> >
> >
> > Since there are already iconLarge and iconSmall
> > imageLists in win32lib and the ListView will
> display
> > the right size depending on its state; LVS_REPORT,
> > LVS_ICON etc. all I had to do was put the correct
> icon
> > in the correct imageList.
> >
> > After many more hours figuring out how to use and
> call
> > extractIconEx I made a modified version of
> > extractIcon.
> > idx = extractIconEx({"shell32.dll", 1})
> > It basically calls extractIconEx and addIcon at
> the
> > same time and returns the index to the last icon
> > loaded.  That index can then be used in addLVItem
> just
> > as normal.
> > This is that same as calling
> > idx = addIcon(extractIcon({"shell32.dll", 1}))
> except
> > that a large and small icon get added to the image
> > list.
> > I haven't played with TreeViews so I don't know if
> it
> > has any relevence or not.  I have just tested it
> on a
> > couple of listViews
> >
> > I don't know if this list accepts attachments so
> here
> > is a link to the code
> > http://home.attbi.com/~sea.star/code/lvextras.ew
> > I took the whole thing and dropped it into
> win32lib.ew
> > because it calls routines already there and I
> wasn't
> > sure how to access them externaly.
> > This is my first time digging into the Windows API
> or
> > messing with win32lib, if there are problems or
> > mistakes please let me know.  If it works for
> anyone
> > else I would be interested in hearing that as
> well.
> > If the win32lib people want to implement these
> ideas
> > in someway that's ok as well.  Thanks.  Chris
> cafromsw at yahoo.com
<snip>

> 
> 
>
>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu