注册 登录
编程论坛 VFP论坛

startpage dll函数声明报错

sam_jiang 发布于 2023-09-27 15:23, 473 次点击
只有本站会员才能查看附件,请 登录

运行一个打印屏幕的程序,但是出现一个错误提示,怎么解决???

代码如下:
程序代码:

*!*    VFP中将表单的内容直接打印

*-- 定义常量

#DEFINE LOGPIXELSX           88

#DEFINE LOGPIXELSY           90

#DEFINE PHYSICALOFFSETX     112

#DEFINE PHYSICALOFFSETY     113

#DEFINE SRCCOPY        13369376

#DEFINE DIB_RGB_COLORS        0



*-- 调用本程序段中的子过程

DO decl

*-- 定义变量

LOCAL hwnd, hdc, hPrnDC, xOffsPrn, yOffsPrn, xScale, yScale, lnwidth,lnheight,lcDocInfo

STORE 0 TO lnwidth,lnheight

*-- 得到打印机设备的坐标偏移量

hPrnDC =getDefaultPrnDC()  && 没有进行错误检查

xOffsPrn =GetDeviceCaps(hPrnDC, PHYSICALOFFSETX)

yOffsPrn =GetDeviceCaps(hPrnDC, PHYSICALOFFSETY)



*-- 得到屏幕的窗口句柄,及她们的宽度、高度等。

hwnd =GetFocus()  && a window with keyboard focus

hDC =GetWindowDC(hwnd)

=getWinRect (hwnd, @lnWidth, @lnHeight)



*-- 根据屏幕和打印机得到缩放值

xScale =GetDeviceCaps(hPrnDC, LOGPIXELSX)/GetDeviceCaps(hDC,LOGPIXELSX)

yScale =GetDeviceCaps(hPrnDC, LOGPIXELSY)/GetDeviceCaps(hDC,LOGPIXELSY)



*-- 将屏幕的内容创建为位图图象数据

hvdc =CreateCompatibleDC(hprnDC)

hbitBmp =CreateCompatibleBitmap (hprnDC, lnWidth, lnHeight)

=deleteobject(SelectObject(hvDC, hbitBmp))

*-- 将位图数据从屏幕拷贝到虚拟设备上

=BitBlt (hvDC, 0,0, lnWidth,lnHeight, hDC, 0,0, SRCCOPY)

lcDocInfo =Chr(20) +Repli(Chr(0), 19) && DOCINFO struct - 20 bytes

IF StartDoc(hPrnDC, @lcDocInfo) > 0


 =StartPage(hPrnDC)


 =Stretchblt(hPrnDC, xOffsPrn, yOffsPrn,;


 xOffsPrn +Int(xScale * lnWidth),;


 yOffsPrn +Int(yScale * lnHeight),;


 hvdc,0,0, lnWidth, lnHeight,SRCCOPY)


 =EndPage(hPrnDC)


 =EndDoc(hPrnDC)

ENDIF

*-- 退出时释放系统资源

=DeleteObject(hbitBmp)

=DeleteDC(hvDC)

=DeleteDC(hPrnDC)

=ReleaseDC(hwnd, hDC)

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  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 win32api INTEGER hdc


 DECLARE INTEGER EndPage IN gdi32 INTEGER hdc


 DECLARE INTEGER 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 StretchBlt IN gdi32 INTEGER hDestDC, INTEGER x, INTEGER y,INTEGER nWidth, INTEGER nHeight, INTEGER hSrcDC,INTEGER xSrc, INTEGER ySrc, integer widthSrc,integer heightSrc,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
5 回复
#2
吹水佬2023-09-27 20:31
以下是引用sam_jiang在2023-9-27 15:23:14的发言:

 DECLARE INTEGER StartPage IN win32api INTEGER hdc

 

StartPage在gdi32.dll
试试
DECLARE INTEGER StartPage IN gdi32 INTEGER hdc

#3
sam_jiang2023-09-28 14:39
回复 2楼 吹水佬
我就是把gdi32 改成win32api 也不行。。。

这是我的手提电脑,winxp+vfp9.0。 在win7+vfp9.0环境没有报错,但是好像也没打印出来。。。



[此贴子已经被作者于2023-9-28 14:47编辑过]

#4
吹水佬2023-09-28 21:15
回复 3楼 sam_jiang
具体不清楚
MS的说法:
https://learn.
#5
sostemp2023-10-08 16:49
以下是引用sam_jiang在2023-9-28 14:39:54的发言:

我就是把gdi32 改成win32api 也不行。。。

这是我的手提电脑,winxp+vfp9.0。 在win7+vfp9.0环境没有报错,但是好像也没打印出来。。。

有没有一个PRG可以学习下,上面粘的代码无法用啊
#6
iswith2023-10-08 19:30
GDI+ sp1有BUG
1