NPRao
16th April 2003, 00:41
I have seen few postings on the board about displaying photos/picture with BaaN Tools.
Thanks to Vamsi and a few others, I got some baseline code to start with and finish it off.
I have this code in a DLL and it can be called by any program.
#define ALTF4 ((1024-1) + 4)
function extern view.picture(string pic.path(256))
{
DLLUSAGE
view the *.gif file in a picture browser
ENDDLLUSAGE
long gwin
long cmap_sz
long cmap(256)
long icon_w, icon_h
long valid.icon
long buflen, fp
string imap(1) based
string bufr(1) based
long idc, idp, image
long event(EVTMAXSIZE), type, option
on case ostype()
case OS_WINDOWS_95:
case OS_WINDOWS_NT:
pic.path = tolower$(pic.path)
|* Dos/Windows files are case insensitive
break
case OS_UNIX:
case OS_OS400:
break |* Unix files are case sensitive
endcase
pic.path = strip$(shiftl$(pic.path))
if pic.path(len(pic.path) - 3) <> ".gif" then
mess("zmadms0037", 1) |* Only *.gif files can be used
return
endif
fp = seq.open(pic.path, "r")
if fp < 0 then
mess("zmadms0010", 1) |* File Handling Errors
return
endif
buflen = seq.seek(0, 2, fp)
e = alloc.mem(bufr, buflen)
e = seq.rewind(fp)
if seq.read(bufr, buflen, fp) > 0 then
if get.pixmap.info(bufr, cmap_sz, icon_w, icon_h) then
alloc.mem(imap, icon_w * icon_h)
valid.icon = decompress.pixmap(bufr, cmap, imap)
cmap(1) = rgb(128,128,128)
endif
else
mess("zmadms0010", 1) |* File Handling Errors
return
endif
e = seq.close(fp)
free.mem(bufr)
gwin = create.object( DsCgwindow, current.mwindow(),
DsNbackground, 3 ,
DsNwidth, icon_w,
DsNheight, icon_h,
DsNpointerCursor, DSCHAND, DsNeventMask, EVTALLEVENTMASK )
update.object(gwin)
idc = create.object(DsCcolormap,current.display(),DsNcolorTable,cmap,cmap_sz)
idp = create.object( DsCpixmap, current.display(),
DsNcolormap, idc,
DsNwidth, icon_w,
DsNheight, icon_h,
DsNdata, imap,
icon_w * icon_h,
DsNdataType, DSPIXMAP8 )
image = create.sub.object( gwin, DsCgpImage,
DsNpixmap, idp,
DsNx, 0,
DsNy, 0 )
raise.object(gwin)
repeat
option = 0
type = next.event(event)
on case type
case EVTKEYPRESS:
if ( evt.keypress.key(event) = ALTF4 ) then
option = 1
break
endif
case EVTBUTTONPRESS:
if ( evt.button.button(event) = ALTF4 ) then
option = 1
break
endif
endcase
until (option)
if image <> 0 then
destroy.sub.object(gwin, image)
endif
if gwin <> 0 then
destroy.object(gwin)
endif
}
|******************************************************************************
Any suggestions and enhancements are welcome!
Thanks to Vamsi and a few others, I got some baseline code to start with and finish it off.
I have this code in a DLL and it can be called by any program.
#define ALTF4 ((1024-1) + 4)
function extern view.picture(string pic.path(256))
{
DLLUSAGE
view the *.gif file in a picture browser
ENDDLLUSAGE
long gwin
long cmap_sz
long cmap(256)
long icon_w, icon_h
long valid.icon
long buflen, fp
string imap(1) based
string bufr(1) based
long idc, idp, image
long event(EVTMAXSIZE), type, option
on case ostype()
case OS_WINDOWS_95:
case OS_WINDOWS_NT:
pic.path = tolower$(pic.path)
|* Dos/Windows files are case insensitive
break
case OS_UNIX:
case OS_OS400:
break |* Unix files are case sensitive
endcase
pic.path = strip$(shiftl$(pic.path))
if pic.path(len(pic.path) - 3) <> ".gif" then
mess("zmadms0037", 1) |* Only *.gif files can be used
return
endif
fp = seq.open(pic.path, "r")
if fp < 0 then
mess("zmadms0010", 1) |* File Handling Errors
return
endif
buflen = seq.seek(0, 2, fp)
e = alloc.mem(bufr, buflen)
e = seq.rewind(fp)
if seq.read(bufr, buflen, fp) > 0 then
if get.pixmap.info(bufr, cmap_sz, icon_w, icon_h) then
alloc.mem(imap, icon_w * icon_h)
valid.icon = decompress.pixmap(bufr, cmap, imap)
cmap(1) = rgb(128,128,128)
endif
else
mess("zmadms0010", 1) |* File Handling Errors
return
endif
e = seq.close(fp)
free.mem(bufr)
gwin = create.object( DsCgwindow, current.mwindow(),
DsNbackground, 3 ,
DsNwidth, icon_w,
DsNheight, icon_h,
DsNpointerCursor, DSCHAND, DsNeventMask, EVTALLEVENTMASK )
update.object(gwin)
idc = create.object(DsCcolormap,current.display(),DsNcolorTable,cmap,cmap_sz)
idp = create.object( DsCpixmap, current.display(),
DsNcolormap, idc,
DsNwidth, icon_w,
DsNheight, icon_h,
DsNdata, imap,
icon_w * icon_h,
DsNdataType, DSPIXMAP8 )
image = create.sub.object( gwin, DsCgpImage,
DsNpixmap, idp,
DsNx, 0,
DsNy, 0 )
raise.object(gwin)
repeat
option = 0
type = next.event(event)
on case type
case EVTKEYPRESS:
if ( evt.keypress.key(event) = ALTF4 ) then
option = 1
break
endif
case EVTBUTTONPRESS:
if ( evt.button.button(event) = ALTF4 ) then
option = 1
break
endif
endcase
until (option)
if image <> 0 then
destroy.sub.object(gwin, image)
endif
if gwin <> 0 then
destroy.object(gwin)
endif
}
|******************************************************************************
Any suggestions and enhancements are welcome!