1. RE: I need help with a win32lib app.

Philip:
   Don't you need a PARENT to use addDirectory() ?
Bernie

new topic     » topic index » view message » categorize

2. RE: I need help with a win32lib app.

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 message » categorize

3. RE: I need help with a win32lib app.

Matt Lewis wrote:
> 
> 
> 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] ), 
<snip>

Thanks.  It works, but there is still a problem.  When it hits a .ico 
file, it uses that same icon to display all the future .ico files it 
hits.  It also does this with .exe files or any other file that has more 
than one icon possible with the same extention.

I'll look for a solution, but if you come up with one first, please let 
me know.

Thanks,
Phil

new topic     » goto parent     » topic index » view message » categorize

4. RE: I need help with a win32lib app.

--- Philip Deets <philip1987 at hotmail.com> wrote:
> 
> Thanks.  It works, but there is still a problem.  When it hits a .ico 
> file, it uses that same icon to display all the future .ico files it 
> hits.  It also does this with .exe files or any other file that has more 
> than one icon possible with the same extention.
> 
> I'll look for a solution, but if you come up with one first, please let 
> me know.

No problem:

function getIconFor( sequence path )

	atom pszPath,icon, mset
	integer ex
	sequence ext

	ext = getExt( path )
	ex = find(ext, extensions)

	-- CHANGE THIS:
	if ex and compare(ext, "ico") then
		return icons[ex]
	end if


Matt Lewis


__________________________________
Do you Yahoo!?
Find out what made the Top Yahoo! Searches of 2003
http://search.yahoo.com/top2003

new topic     » goto parent     » topic index » view message » categorize

5. RE: I need help with a win32lib app.

Matt Lewis wrote:
> 
> 
> --- Philip Deets <philip1987 at hotmail.com> wrote:
> > 
> > Thanks.  It works, but there is still a problem.  When it hits a .ico 
> > file, it uses that same icon to display all the future .ico files it 
> > hits.  It also does this with .exe files or any other file that has more 
> > 
> > than one icon possible with the same extention.
> > 
> > I'll look for a solution, but if you come up with one first, please let 
> > me know.
> 
> No problem:
> 
> function getIconFor( sequence path )
> 
> 	atom pszPath,icon, mset
> 	integer ex
> 	sequence ext
> 
> 	ext = getExt( path )
> 	ex = find(ext, extensions)
> 
> 	-- CHANGE THIS:
> 	if ex and compare(ext, "ico") then
> 		return icons[ex]
> 	end if
> 
> 
> Matt Lewis
> 
> 

That works for .ico, and I could just add .exe, but are there any other 
extentions other than .ico and .exe that can have multiple icons for 
different files of the same extention?

Phil

new topic     » goto parent     » topic index » view message » categorize

6. RE: I need help with a win32lib app.

Philip Deets wrote:
> 
> 
> Matt Lewis wrote:
> > 
> > 
> > --- Philip Deets <philip1987 at hotmail.com> wrote:
> > > 
> > > Thanks.  It works, but there is still a problem.  When it hits a .ico 
> > > file, it uses that same icon to display all the future .ico files it 
> > > hits.  It also does this with .exe files or any other file that has more 
> > > 
> > > 
> > > than one icon possible with the same extention.
> > > 
> > > I'll look for a solution, but if you come up with one first, please let 
> > > me know.
> > 
> > No problem:
> > 
> > function getIconFor( sequence path )
> > 
> > 	atom pszPath,icon, mset
> > 	integer ex
> > 	sequence ext
> > 
> > 	ext = getExt( path )
> > 	ex = find(ext, extensions)
> > 
> > 	-- CHANGE THIS:
> > 	if ex and compare(ext, "ico") then
> > 		return icons[ex]
> > 	end if
> > 
> > 
> > Matt Lewis
> > 
> > 
> That works for .ico, and I could just add .exe, but are there any other 
> extentions other than .ico and .exe that can have multiple icons for 
> different files of the same extention?
> 
> Phil
> 

Actually it doesn't fix the problem on my computer.  I hadn't tested it 
yet when I made that previous post.

Phil

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu