1. can somebody help me with this code?
What I am trying to do is read an file IDE_icon.e, parse the first XPM
in it and use the data but I can't get it to work.
Can anyone see my error, please?
Thanks,
Judith
--demo of reading xpm_icon.e and trapping the sequence of the xpm and
--then adding to window at x,y
include win32lib.ew
without warning
constant win=create(Window,"test xpm",0,0,0,300,200,0)
integer ok
function replace( sequence s, sequence old, sequence new )
--stollen from David Cuny
-- replace substring in sequence
integer at
sequence s1
s1 = ""
while 1 do
-- look for target
at = match( old, s )
if at = 0 then
-- no more replacements
exit
end if
-- accumulate in s1
s1 &= s[1..at-1] & new
-- remove from s
s = s[at+length(old)..length(s)]
end while
return s1 & s
end function
function trims(sequence text)
--now trim text at right
for i=length(text) to 1 by -1 do
if text[i]=' ' then
text=text[1..length(text)-1]
else
exit
end if
end for
--now trim text from left
text=reverse(text)
for i=length(text) to 1 by -1 do
if text[i]=' ' then
text=text[1..length(text)-1]
else
exit
end if
end for
text=reverse(text)
return text
end function
atom hdib
procedure onOpen_win()
integer handle, ignore, at, start
object text
sequence fName, XPM, text2
fName="XPM_Icon.e"
XPM={}
start=False
handle=open( fName, "r" )
if handle = -1 then
-- give message and exit
ignore = message_box( "Open File Error",
"Unable to read the file " & fName,
MB_ICONHAND+MB_TASKMODAL )
return
end if
-- parse the file
while 1 do
-- get a line of text
text = gets( handle )
if atom( text ) then
exit --EOF
end if
-- remove line feed
text=replace(text,"\n","")
text=trims(text)
if length( text ) = 0 then
-- ignore blank lines
end if
--see dummy test below to see what data looks like
at=match( "{", text )
if at then
XPM&=text[at+1..length(text)]
start=True
else
at=match( "}", text )
if at then
XPM&=text[1..at-1]
exit
else
if start then
XPM&=text
end if
end if
end if
end while
--if I need the {} then do
--XPM="{" & XPM & "}"
at=message_box(XPM,"",0)
--dummy test which works
--XPM = {
--"24 24 3 1",
--" c None",
--". c #FFFFFF",
--"+ c #808080",
--" ",
--" ",
--" ",
--" ",
--" ",
--" ",
--" ",
--"........................",
--" +",
--"+++++++++++++++++ +",
--" . . +",
--" . .+ +",
--" . .+. +",
--" . .+.+ +",
--"..................+.+ +",
--" +",
--"++++++++++++++++++++++++",
--" ",
--" ",
--" ",
--" ",
--" ",
--" ",
--" "}
if length( XPM ) then
hdib=xpmToPixmap(XPM)
repaintWindow( win )
end if
end procedure
procedure paint_win(integer x1, integer y1, integer x2, integer y2)
transBlt(win,10,10,hdib)
end procedure
onPaint[win]=routine_id("paint_win")
onOpen[win]=routine_id("onOpen_win")
WinMain( win, Normal )
2. Re: can somebody help me with this code?
Ooops! Just noticed that the program I sent will crash after a short while.
When repainting the window, I should have destroyed all the bitmaps
previously displayed. Currently, the program runs out of resources after a
few repaint events.