I am anxiously awaiting your UDF

CCH
http://cch4clipper.blogspot.com
Moderator: Rathinagiri
Code: Select all
# include "minigui.ch"
function main
define window sample at 0,0 width 800 height 600 main
define button button1
row 10
col 10
caption "Click here"
action showtext("readme.txt")
end button
end window
sample.center
sample.activate
return nil
Code: Select all
#include "minigui.ch"
function showtext(_filename)
local _pointchar := at(".",_filename)
local _winname := ""
private _winwidth := 700 //getdesktopwidth() - 60
private _winheight := 550 //getdesktopheight() - 60
if _pointchar > 0
_winname := substr(_filename,1,_pointchar - 1)
else
_winname := _filename
endif
if iswindowdefined(&_winname)
release window &_winname
endif
define window &_winname at 0,0 width _winwidth height _winheight title _filename modal nosize on init textshow(_filename,_winname)
@ _winheight - 60,int(_winwidth /2)-90 button exit1 caption "Exit" width 80 action textshowexit(_winname)
@ _winheight - 60,int(_winwidth /2)+10 button print1 caption "Print" width 80 action textfileprint(_filename)
end window
center window &_winname
activate window &_winname
return nil
function textshowexit(_winname)
release window &_winname
return nil
function textshow(_filename,_winname)
local lines := {}
local handle := fopen(_filename,0)
local size1 := 0
local size2 := 0
local sample := 0
local lineno := 0
local eof1 := .f.
local linestr := ""
local c := ""
local len1 := 0
local x := 0
local finished := .f.
local m := 0
local length1 := 0
local totpages := 0
local linecount := 0
local length2 := 0
local pagecount := 0
local start := 0
local end := 0
local v := 0
local v1 := 0
if handle == -1
return nil
endif
size1 := fseek(handle,0,2)
size2 := size1
if size1 > 65000
sample := 65000
else
sample := size1
endif
fseek(handle,0)
lineno := 1
aadd(lines,"")
c := space(sample)
eof1 := .f.
linestr := ""
len1 := 0
do while .not. eof1
x := 0
x := fread(handle,@c,sample)
len1 := len1 + sample
if x < 1
eof1 := .t.
lines[lineno] := linestr
else
finished := .f.
do while .not. finished
m := at(chr(13),c)
if m > 0
if m == 1
linestr := ""
lineno := lineno + 1
aadd(lines,"")
c := substr(c,m+1,len(c))
else
if len(alltrim(linestr)) > 0
linestr := linestr + substr(c,1,m-1)
else
linestr := substr(c,1,m-1)
endif
c := substr(c,m+1,len(c))
lines[lineno] := linestr
linestr := ""
lineno := lineno + 1
aadd(lines,"")
endif
else
linestr := c
finished := .t.
endif
enddo
c := space(sample)
endif
enddo
fclose(handle)
define tab pages of &_winname at 10,10 width _winwidth - 20 height _winheight - 90
length1 := len(lines)
if length1 <= 10000
totpages := 1
else
totpages := 0
length2 := length1
do while length2 > 0
length2 := length2 - 10000
totpages := totpages + 1
enddo
endif
if totpages > 15
return nil
endif
for pagecount := 1 to totpages
start := ((pagecount-1) * 10000) + 1
if pagecount == totpages
end := len(lines)
else
end := start + 9999
endif
page "Page "+alltrim(str(pagecount))
v := "lb"+alltrim(str(pagecount))
v1 := "page"+alltrim(str(pagecount))
&v1 := {}
for linecount := start to end
aadd(&v1,{substr(lines[linecount],2,len(lines[linecount]))})
next j
@ 25,10 grid &v width _winwidth - 50 height _winheight - 120 headers {_filename} widths {800} items &v1 value 1 font "courier new" size 10 nolines
end page
next pagecount
end tab
return nil
function textfileprint(_filename)
copy file (_filename) to lpt1
return nil
rathinagiri wrote: Here comes my udf.
The udf can show a text file as read only.
Hi Sudip,sudip wrote:Hello Rathinagiri,
BTW, you mentioned Grid2print. I can't find it in HMG. Is it included in HMG or user defined function?
Sudip