VFP打开系统“页面设置”对话框以指定打印页面的属性

6e6dc8b2758ad53b70f1ab9e57899504.gif

VFP打开系统的页面设置,并且返回参数表。

79e8dbb822156ecbc0fa0f24b6cc0e91.png

a25df78288d30c437da9fa511d29cf0d.png

DO decl


LOCAL lcBuffer, lcSource
lcBuffer = GetSetupBuffer()


IF PageSetupDlg (@lcBuffer) <> 0
  LOCAL hDevmode, hDevnames
  hDevmode = buf2dword(SUBSTR(lcBuffer, 9,4))
  hDevnames = buf2dword(SUBSTR(lcBuffer, 13,4))


  * creating resulting cursor
  CREATE CURSOR csResult (src C(20), name C(50), value C(250))


  * retrieving data from three different structures
  * returned by this function


  = SavePageSetupDlg (lcBuffer)
  = SaveDevmode(hDevmode)
  = SaveDevnames(hDevnames)


  GO TOP
  BROW NORMAL NOWAIT
ENDIF
* end of main


FUNCTION  GetSetupBuffer
* this function fills and returns the PAGESETUPDLG structure
* in a FoxPro string


*| typedef struct tagPSD {
*|   DWORD           lStructSize;            0:4
*|   HWND            hwndOwner;              4:4
*|   HGLOBAL         hDevMode;               8:4
*|   HGLOBAL         hDevNames;             12:4
*|   DWORD           Flags;                 16:4
*|   POINT           ptPaperSize;           20:8
*|   RECT            rtMinMargin;           28:16
*|   RECT            rtMargin;              44:16
*|   HINSTANCE       hInstance;             60:4
*|   LPARAM          lCustData;             64:4
*|   LPPAGESETUPHOOK lpfnPageSetupHook;     68:4
*|   LPPAGEPAINTHOOK lpfnPagePaintHook;     72:4
*|   LPCTSTR         lpPageSetupTemplName;  76:4
*|   HGLOBAL         hPageSetupTempl;       80:4
*| } PAGESETUPDLG, *LPPAGESETUPDLG; total = 84 bytes
#DEFINE PAGESETUPDLG_SIZE  84


* several Page Setup flags
#DEFINE PSD_RETURNDEFAULT               1024
#DEFINE PSD_INTHOUSANDTHSOFINCHES          4
#DEFINE PSD_INHUNDREDTHSOFMILLIMETERS      8
#DEFINE PSD_ENABLEPAGESETUPTEMPLATE    32768


#DEFINE GWL_HINSTANCE  -6


  LOCAL lcBuffer, lnFlags


*  lnFlags = PSD_RETURNDEFAULT  && the dialog not displayed
  lnFlags = 0


  lcBuffer = num2dword(PAGESETUPDLG_SIZE) +;
    num2dword(0) +;
    num2dword(0) +;
    num2dword(0) +;
    num2dword(lnFlags) +;
    num2dword(0)+num2dword(0) +;
    num2dword(0)+num2dword(0)+num2dword(0)+num2dword(0) +;
    num2dword(0)+num2dword(0)+num2dword(0)+num2dword(0) +;
    num2dword(0) +;
    num2dword(0) +;
    num2dword(0) +;
    num2dword(0) +;
    num2dword(0) +;
    num2dword(0)


  * if you do not care for the page setup flags
  * the buffer becomes pretty simple:
  * lcBuffer = num2dword(PAGESETUPDLG_SIZE) +;
  * Repli(Chr(0), PAGESETUPDLG_SIZE-4)
RETURN  lcBuffer


PROCEDURE  SavePageSetupDlg (lcBuffer)
* this procedure retrieves and saves parameters from
* the PAGESETUPDLG structure passed as a string
  lcSource = "PAGESETUPDLG"
  = _save ("Paper width",      buf2dword(SUBSTR(lcBuffer, 21,4)))
  = _save ("Paper height",     buf2dword(SUBSTR(lcBuffer, 25,4)))
  = _save ("MinMargin left",   buf2dword(SUBSTR(lcBuffer, 29,4)))
  = _save ("MinMargin top",    buf2dword(SUBSTR(lcBuffer, 33,4)))
  = _save ("MinMargin right",  buf2dword(SUBSTR(lcBuffer, 37,4)))
  = _save ("MinMargin bottom", buf2dword(SUBSTR(lcBuffer, 41,4)))
  = _save ("Margin left",      buf2dword(SUBSTR(lcBuffer, 45,4)))
  = _save ("Margin top",       buf2dword(SUBSTR(lcBuffer, 49,4)))
  = _save ("Margin right",     buf2dword(SUBSTR(lcBuffer, 53,4)))
  = _save ("Margin bottom",    buf2dword(SUBSTR(lcBuffer, 57,4)))
RETURN


PROCEDURE  SaveDevnames (hMem)
* this procedure retrieves and saves parameters from
* the DEVNAMES structure


*|typedef struct tagDEVNAMES {
*|  WORD wDriverOffset;  0:2
*|  WORD wDeviceOffset;  2:2
*|  WORD wOutputOffset;  4:2
*|  WORD wDefault;       6:2
*|// Driver, device, and port name strings follow wDefault.
*|} DEVNAMES, *LPDEVNAMES;


  LOCAL lnPtr, lcBuffer, wDriverOffset, wDeviceOffset, wOutputOffset, wDefault
  * pointer to the first byte of the DEVNAMES memory block
  lnPtr = GlobalLock (hMem)


  * copying data from the memory block to a string
  lcBuffer = Repli(Chr(0), 8)
  = Heap2Str (@lcBuffer, lnPtr, 8)
  
  * retrieveing offsets to the names
  wDriverOffset = buf2word(SUBSTR(lcBuffer, 1,2))
  wDeviceOffset = buf2word(SUBSTR(lcBuffer, 3,2))
  wOutputOffset = buf2word(SUBSTR(lcBuffer, 5,2))
  wDefault      = buf2word(SUBSTR(lcBuffer, 7,2))


  lcSource = "DEVNAMES"
  = _save ("Device driver name", mem2str(lnPtr+wDriverOffset))
  = _save ("Device name",        mem2str(lnPtr+wDeviceOffset))
  = _save ("Output port",        mem2str(lnPtr+wOutputOffset))
  = _save ("The printer is default", wDefault)
  
  = GlobalUnlock(hMem)
RETURN


PROCEDURE  SaveDevmode (hMem)
* this procedure retrieves and saves parameters from
* the DEVMODE strusture


#DEFINE CCHDEVICENAME  32
#DEFINE CCHFORMNAME    32


*|typedef struct _devicemode {
*|  BCHAR  dmDeviceName[CCHDEVICENAME];   0:32
*|  WORD   dmSpecVersion;                32:2
*|  WORD   dmDriverVersion;              34:2
*|  WORD   dmSize;                       36:2
*|  WORD   dmDriverExtra;                38:2
*|  DWORD  dmFields;                     40:4
*|  union {
*|    struct {
*|      short dmOrientation;             44:2
*|      short dmPaperSize;               46:2
*|      short dmPaperLength;             48:2
*|      short dmPaperWidth;              50:2
*|      short dmScale;                   52:2
*|      short dmCopies;                  54:2
*|      short dmDefaultSource;           56:2
*|      short dmPrintQuality;            58:2
*|    };
*|    POINTL dmPosition;                 44:8
*|    DWORD  dmDisplayOrientation;       44:4
*|    DWORD  dmDisplayFixedOutput;       44:4
*|  };
*|  short  dmColor;                      60:2
*|  short  dmDuplex;                     62:2
*|  short  dmYResolution;                64:2
*|  short  dmTTOption;                   66:2
*|  short  dmCollate;                    68:2
*|  BYTE  dmFormName[CCHFORMNAME];       70:32
*|  WORD  dmLogPixels;                  102:2
*|  DWORD  dmBitsPerPel;                104:4
*|  DWORD  dmPelsWidth;                 108:4
*|  DWORD  dmPelsHeight;                112:4
*|  union {
*|    DWORD  dmDisplayFlags;            116:4
*|    DWORD  dmNup;                     116:4
*|  }
*|  DWORD  dmDisplayFrequency;          120:4
*|#if(WINVER >= 0x0400)
*|  DWORD  dmICMMethod;                 124:4
*|  DWORD  dmICMIntent;                 128:4
*|  DWORD  dmMediaType;                 132:4
*|  DWORD  dmDitherType;                136:4
*|  DWORD  dmReserved1;                 140:4
*|  DWORD  dmReserved2;                 144:4
*|#if (WINVER >= 0x0500) || (_WIN32_WINNT >= 0x0400)
*|  DWORD  dmPanningWidth;              148:4
*|  DWORD  dmPanningHeight;             152:4
*|#endif
*|#endif /* WINVER >= 0x0400 */
*|} DEVMODE; total bytes = 156
#DEFINE DEVMODE_STRU_SIZE  156


  LOCAL lnPtr, lcBuffer, lcDevicename, lcFormname


  * pointer to the first byte of the DEVMODE memory block
  lnPtr = GlobalLock (hMem)


  lcBuffer = Repli(Chr(0), DEVMODE_STRU_SIZE)
  = Heap2Str (@lcBuffer, lnPtr, DEVMODE_STRU_SIZE)


  lcDevicename = SUBSTR(lcBuffer, 1,CCHDEVICENAME)
  lcFormname = SUBSTR(lcBuffer, 71,CCHFORMNAME)


  lcSource = "DEVMODE"
  = _save ("Device name", STRTRAN(lcDevicename, Chr(0),""))
  = _save ("Form name", STRTRAN(lcFormname, Chr(0),""))


  = _save ("Driver version", buf2word(SUBSTR(lcBuffer, 35,2)))
  = _save ("DEVMODE structure size", buf2word(SUBSTR(lcBuffer, 37,2)))


  = _save ("Orientation",    buf2word(SUBSTR(lcBuffer, 45,2)))
  = _save ("Paper size",     buf2word(SUBSTR(lcBuffer, 47,2)))
  = _save ("Paper length",   buf2word(SUBSTR(lcBuffer, 49,2)))
  = _save ("Paper width",    buf2word(SUBSTR(lcBuffer, 51,2)))
  = _save ("Scale",          buf2word(SUBSTR(lcBuffer, 53,2)))
  = _save ("Copies",         buf2word(SUBSTR(lcBuffer, 55,2)))
  = _save ("Default source", buf2word(SUBSTR(lcBuffer, 57,2)))
  = _save ("Print quality",  buf2word(SUBSTR(lcBuffer, 59,2)))
  = _save ("Y resolution",   buf2word(SUBSTR(lcBuffer, 65,2)))


  = _save ("Media type", buf2word(SUBSTR(lcBuffer, 133,4)))
  = _save ("Ditherting type", buf2word(SUBSTR(lcBuffer, 137,4)))


  = GlobalUnlock(hMem)
RETURN


PROCEDURE  _save (lcName, lvValue)
  LOCAL lcType, lcValue
  lcType = TYPE("lvValue")
  DO CASE
  CASE lcType = "N"
    lcValue = LTRIM(STR(lvValue, 20,2))
  OTHER
    lcValue = lvValue
  ENDCASE
  INSERT INTO csResult VALUES (lcSource, lcName, lcValue)
RETURN


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


FUNCTION  buf2word (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
  Asc(SUBSTR(lcBuffer, 2,1)) * 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  mem2str(lnMemBlock)
#DEFINE BUFFER_SIZE   16
#DEFINE EMPTY_BUFFER  Repli(Chr(0), BUFFER_SIZE)
  LOCAL lnPtr, lcResult, lcBuffer, lnPos
  lnPtr = lnMemBlock
  lcResult = ""


  DO WHILE .T.
    lcBuffer = EMPTY_BUFFER
    = Heap2Str (@lcBuffer, lnPtr, BUFFER_SIZE)
    lnPos = AT(Chr(0), lcBuffer)


    IF lnPos > 0
      lcResult = lcResult + SUBSTR(lcBuffer, 1, lnPos-1)
      RETURN  lcResult
    ELSE
      lcResult = lcResult + lcBuffer
      lnPtr = lnPtr + BUFFER_SIZE
    ENDIF
  ENDDO


PROCEDURE  decl
#DEFINE GMEM_FIXED   0
  DECLARE INTEGER PageSetupDlg IN comdlg32 STRING @lppsd
  DECLARE RtlMoveMemory IN kernel32 As Heap2Str STRING @, INTEGER, INTEGER
  DECLARE INTEGER GlobalLock IN kernel32 INTEGER hMem
  DECLARE INTEGER GlobalUnlock IN kernel32 INTEGER hMem

猫猫的心里话

加菲猫的VFP|狐友会社群接收投稿啦

加菲猫的VFP,用VFP不局限VFP,用VFP混合一切。无论是VFP,还是JS,还是C,只要能混合起来,都可以发表。

商业模式,销售技巧、需求规划、产品设计的知识通通可以发表。

暂定千字50元红包,,优秀的文章红包更大,一经发表,红包到手。

如何帮助使用VFP的人?

用VFP的人,有专业的,有非专业了,很多人其实是小白,问出的问题是小白,如果问题不对,我们引导他们问正确的问题。无论如何请不要嘲笑他们说帮助都不看,这么简单的问题都不会,嘲笑别人不行,而无法提出建设性答案,是很low的。

我们无论工作需要,还是有自己的软件,都是是需要真正的知识,如何让更多人学习真正的VFP知识呢,只需要点赞,在看,能转发朋友圈就更好了。

加菲猫的vfp倡导用"VFP极简混合开发,少写代码、快速出活,用VFP,但不局限于VFP,各种语言混合开发"

我已经带领一百多名会员成功掌到VFP的黑科技,进入了移动互联网时代,接下来我们要进入物联网领域。

2023年狐友会社群会员继续招募中

社群会员获取的权益有:

祺佑三层开发框架商业版(猫框),终身免费升级,终身技术支持。

开放的录播课程有:

微信小程序,微信公众号开发,H5 APP开发,Extjs BS开发,VFP面向对象进阶,VFP中间层开发。

源码类资源有:

支付组件源码,短信源码,权限组件源码,一些完整系统的源码。这个可以单独出售的,需要的可以联系我。

会员也可以实现群内资源对接,可以接分包,合作等各项商业或技术业务

4375a944de4c2740fca6a277f72379dc.gif

43c1fb6de1ca04351121de08096877bd.jpeg

4642cb7d665d54d644a417887003a3f2.gif

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值