RE: I need help with a win32lib app.

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

Philip Deets wrote:
> 
> 
> Hi, I'm making an editor with the win32lib.  I've already posted
> about various problems I've been having with it.  Thanks for all 
> your help so far.  I'm having another problem though.  Here is some 
> source code that produces an error that I don't know how to fix.
> 
> It includes the TBAR_XPM.E which is located in the win32lib demo 
> folder. Please move that to a place where it can be included.

<snip>

> It will work if you comment the addDirectory call right above the 
> WinMain call.  You can do this to see what the GUI looks like.
> 
> If you can find the problem, please tell me.

It seems to be a memory issue.  First, I'd recommend not reallocating 
SHFileInfo_STRUCT for each call--it just slows you down.  Also, you seem 
to be creating a new icon in memory for each file.  You only need to do 
this for each file *type*.  The (topica-mangled) code below works for me 
on Win2K.

-- begin code
-- cut and paste this code to replace all of getIconFor() 
-- and addDirectory()

atom SHFileInfo_STRUCT
SHFileInfo_STRUCT = allocate( SIZEOF_SHFILEINFO ) 
sequence extensions, icons
extensions = {}
icons = {}

function getExt( sequence path )
	integer ix
	ix = length(path)
	while ix and path[ix] != '.' do
		ix -= 1
	end while
	if ix then
		return path[ix+1..length(path)]
	else
		return ""
	end if
end function

function getIconFor( sequence path )

	atom pszPath,icon, mset
	integer ex
	sequence ext

	ext = getExt( path )
	ex = find(ext, extensions)
	if ex then
		return icons[ex]
	end if
	
	pszPath = allocate_string( path )
	poke( SHFileInfo_STRUCT, repeat( 0, SIZEOF_SHFILEINFO ) )
	VOID = w32Func( xSHGetFileInfo, { pszPath, 0, SHFileInfo_STRUCT, 
		SIZEOF_SHFILEINFO, or_all( { SHGFI_ICON, SHGFI_SMALLICON } ) } )

	icon = fetch( SHFileInfo_STRUCT, hIcon )

	free( pszPath )

	extensions = append( extensions, ext )
	icons &= addIcon(icon)
	return icons[length(icons)]

end function

--add a folder to the filesystem_treeview
global procedure addDirectory( integer parent, sequence path )
	sequence files
	integer id
	id = addTVItem( filesystem_treeview, CLOSE_DIR, CLOSE_DIR, iff( parent 
= 0, path, getDirectoryName( path ) ), parent )

	files = rearrange( dir( path ) ) --put directories first

	for i = 1 to length( files ) do

		--don't let "." and ".." through
		if files[i][1][1] != '.' then

		   if find( 'd', files[i][2] ) then

			  addDirectory( id, path & "\\" & files[i][1] )
		   else

			   VOID = addTVItem( filesystem_treeview, getIconFor( path & 
					"\\" & files[i][1] ), getIconFor( path & "\\" & files[i][1] ), 
					files[i][1], id )
		   end if
		end if
	end for

end procedure

-- end code

Matt Lewis

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

Search



Quick Links

User menu

Not signed in.

Misc Menu