1、在VFP中,如何用代码实现将表单界面直接打印?是不是要转换成图片的形式?怎么样编写程序?
2、有一种产品属性多达30几种,我建了8个数据表来存放字段属性,并以产品编号作为每个表的主键值,请问在一个表单中,怎么样实现选择产品的任意几个属性后,按查找功能键查寻出具有该属性的产品种类并以表格的形式显示出来?表单中显示产品属性的控件我已经把它们与数据源绑定了。
第一个
*******************************************
*-- 程序名称:将表单的内容直接打印 --*
*-- 将窗口中的内容以一个位图的形式打印 --*
*-- 程序作者:未知,来源论坛转帖 --*
*-- 使用方法:在表单中执行该程序既可 --*
* 例:在某表单的一个command --*
* 按纽中执行 do printform.prg --*
*******************************************
*-- 定义常量
#define logpixelsx 88
#define logpixelsy 90
#define physicaloffsetx 112
#define physicaloffsety 113
#define srccopy 13369376
#define dib_rgb_colors 0
*-- 调用本程序段中的子过程
do decl
*-- 定义变量
private pnwidth, pnheight, lnbitsperpixel, lnbytesperscan
store 0 to pnwidth, pnheight, lnbitsperpixel, lnbytesperscan
local hwnd, hformdc, hprndc, hmemdc, hmembmp, hsavedbitmap,;
xoffsprn, yoffsprn, xscale, yscale, lcdocinfo, lcbinfo, lpbitsarray
*-- 得到打印机设备的坐标偏移量
hprndc = getdefaultprndc() && 没有进行错误检查
xoffsprn = getdevicecaps(hprndc, physicaloffsetx)
yoffsprn = getdevicecaps(hprndc, physicaloffsety)
*-- 得到屏幕的窗口句柄,及她们的宽度、高度等。
hwnd = getfocus() && a window with keyboard focus
hformdc = getwindowdc(hwnd)
= getwinrect (hwnd, @pnwidth, @pnheight)
*-- 根据屏幕和打印机得到缩放值
xscale = getdevicecaps(hprndc, logpixelsx)/getdevicecaps(hformdc,logpixelsx)
yscale = getdevicecaps(hprndc, logpixelsy)/getdevicecaps(hformdc,logpixelsy)
*-- 将屏幕的内容创建为位图图象数据
hmemdc = createcompatibledc (hformdc)
hmembmp = createcompatiblebitmap (hformdc, pnwidth, pnheight)
hsavedbitmap = selectobject(hmemdc, hmembmp)
*-- 将位图数据从屏幕拷贝到虚拟设备上
= bitblt (hmemdc, 0,0, pnwidth,pnheight, hformdc, 0,0, srccopy)
= selectobject(hmemdc, hsavedbitmap)
* retrieving bits from the compatible bitmap into a buffer
* as a device-independent bitmap (dib) with a bitsperpixel value
* as one of the printer device context
lcbinfo = initbitmapinfo(hprndc)
lpbitsarray = initbitsarray()
= getdibits (hmemdc, hmembmp, 0, pnheight,;
lpbitsarray, @lcbinfo, dib_rgb_colors)
lcdocinfo = chr(20) + repli(chr(0), 19) && docinfo struct - 20 bytes
if startdoc(hprndc, @lcdocinfo) > 0
= startpage(hprndc)
= stretchdibits (hprndc, xoffsprn, yoffsprn,;
xoffsprn + int(xscale * pnwidth),;
yoffsprn + int(yscale * pnheight),;
0,0, pnwidth, pnheight,;
lpbitsarray, @lcbinfo, dib_rgb_colors, srccopy)
= endpage(hprndc)
= enddoc(hprndc)
endif
*-- 退出时释放系统资源
= globalfree(lpbitsarray)
= deleteobject(hmembmp)
= deletedc(hmemdc)
= deletedc(hprndc)
= releasedc(hwnd, hformdc)
return
procedure getwinrect (lnhwnd, lnwidth, lnheight)
*-- 返回指定句柄的窗口的宽和高
#define maxdword 4294967295 && 0xffffffff
local lprect, lnleft, lntop, lnright, lnbottom
lprect = repli (chr(0), 16)
= getwindowrect (lnhwnd, @lprect)
lnright = buf2dword(substr(lprect, 9,4))
lnbottom = buf2dword(substr(lprect, 13,4))
lnleft = buf2dword(substr(lprect, 1,4))
if lnleft > lnright
lnleft = lnleft - maxdword
endif
lntop = buf2dword(substr(lprect, 5,4))
if lntop > lnbottom
lntop = lntop - maxdword
endif
lnwidth = lnright - lnleft
lnheight = lnbottom - lntop
return
function getdefaultprndc
* returns device context for the default printer
#define pd_returndc 256
#define pd_returndefault 1024
local lcstruct, lnflags
lnflags = pd_returndefault + pd_returndc
* fill printdlg structure
lcstruct = num2dword(66) + repli(chr(0), 16) +;
num2dword(lnflags) + repli(chr(0), 42)
if printdlg (@lcstruct) <> 0
return buf2dword (substr(lcstruct, 17,4))
endif
return 0
function initbitmapinfo(htargetdc)
#define bi_rgb 0
#define rgbquad_size 4 && rgbquad
#define bhdr_size 40 && bitmapinfoheader
local lnrgbquadsize, lcrgbquad, lcbihdr
* use printer bitperpixel value
lnbitsperpixel = 24
* initializing bitmapinfoheader structure
lcbihdr = num2dword(bhdr_size) +;
num2dword(pnwidth) + num2dword(pnheight) +;
num2word(1) + num2word(lnbitsperpixel) +;
num2dword(bi_rgb) + repli(chr(0), 20)
* creating a buffer for the color table
if lnbitsperpixel <= 8
lnrgbquadsize = (2^lnbitsperpixel) * rgbquad_size
lcrgbquad = repli(chr(0), lnrgbquadsize)
else
lcrgbquad = ""
endif
return lcbihdr + lcrgbquad
procedure initbitsarray()
#define gmem_fixed 0
local lnptr, lnallocsize
* making sure the value is dword-aligned
lnbytesperscan = int((pnwidth * lnbitsperpixel)/8)
if mod(lnbytesperscan, 4) <> 0
lnbytesperscan = lnbytesperscan + 4 - mod(lnbytesperscan, 4)
endif
lnallocsize = pnheight * lnbytesperscan
lnptr = globalalloc (gmem_fixed, lnallocsize)
= zeromemory (lnptr, lnallocsize)
return lnptr
function num2word (lnvalue)
return chr(mod(m.lnvalue,256)) + chr(int(m.lnvalue/256))
function num2dword (lnvalue)
#define m0 256
#define m1 65536
#define m2 16777216
local b0, b1, b2, b3
b3 = int(lnvalue/m2)
b2 = int((lnvalue - b3*m2)/m1)
b1 = int((lnvalue - b3*m2 - b2*m1)/m0)
b0 = mod(lnvalue, m0)
return chr(b0)+chr(b1)+chr(b2)+chr(b3)
function buf2word (lcbuffer)
return asc(substr(lcbuffer, 1,1)) + ;
asc(substr(lcbuffer, 2,1)) * 256
function buf2dword (lcbuffer)
return asc(substr(lcbuffer, 1,1)) + ;
asc(substr(lcbuffer, 2,1)) * 256 +;
asc(substr(lcbuffer, 3,1)) * 65536 +;
asc(substr(lcbuffer, 4,1)) * 16777216
procedure decl && so many of them declared here
declare integer getfocus in user32
declare integer enddoc in gdi32 integer hdc
declare integer getwindowdc in user32 integer hwnd
declare integer deleteobject in gdi32 integer hobject
declare integer createcompatibledc in gdi32 integer hdc
declare integer releasedc in user32 integer hwnd, integer hdc
declare integer getwindowrect in user32 integer hwnd, string @lprect
declare integer globalalloc in kernel32 integer wflags, integer dwbytes
declare integer getdevicecaps in gdi32 integer hdc, integer nindex
declare integer selectobject in gdi32 integer hdc, integer hobject
declare integer startdoc in gdi32 integer hdc, string @ lpdi
declare integer globalfree in kernel32 integer hmem
declare integer printdlg in comdlg32 string @ lppd
declare integer deletedc in gdi32 integer hdc
declare integer startpage in gdi32 integer hdc
declare integer endpage in gdi32 integer hdc
declare rtlzeromemory in kernel32 as zeromemory;
integer dest, integer numbytes
declare integer createcompatiblebitmap in gdi32;
integer hdc, integer nwidth, integer nheight
declare integer bitblt in gdi32;
integer hdestdc, integer x, integer y,;
integer nwidth, integer nheight, integer hsrcdc,;
integer xsrc, integer ysrc, integer dwrop
declare integer stretchdibits in gdi32;
integer hdc, integer xdest, integer ydest,;
integer ndestwidth, integer ndestheight, integer xsrc,;
integer ysrc, integer nsrcwidth, integer nsrcheight,;
integer lpbits, string @lpbitsinfo,;
integer iusage, integer dwrop
declare integer getdibits in gdi32;
integer hdc, integer hbmp, integer ustartscan,;
integer cscanlines, integer lpvbits, string @lpbi,;
integer uusage
return && decl