PB开发笔记(8)

//自适应屏幕分辨率的基类窗口(pb)
做一个自适应屏幕分辨率的窗口,当成一个应用程序中所有窗体的基类。这样整个程序可以很好的适应
屏幕分辨率的改变。实现的原理很简单,就是在窗口打开的时候去RESIZE窗口和窗口中的控件大小,
位置。参看下面的源代码,可以很容易的看懂。
1。新建一个窗口。
为窗口写一个函数f_resize()大部分工作就在这里。
无输入参数
返回值为整形:
environment env
integer ii_ScreenWidth,ii_ScreenHeight
double WRadio,HRadio,Radio
integer ii_WinBolderWidth,ii_WinBolderHeight
getenvironment(env)
ii_WinBolderWidth=this.width - this.WorkSpaceWidth()//取得窗体的边框宽度
ii_WinBolderHeight=this.height - this.WorkSpaceHeight()
ii_ScreenWidth=env.screenwidth
ii_ScreenHeight=env.screenheight
//compute the radio that need be resize
WRadio=ii_ScreenWidth/800 //标准认为屏幕分辨率为800*600
HRadio=ii_ScreenHeight/600//计算出屏幕相对800*600分辨率的变化量
Radio=Min(WRadio,HRadio)
if Radio=1.0 then //if the screen is default 800*600
return 0
end if
this.hide()
this.width=(this.width - ii_WinBolderWidth)*Radio + ii_WinBolderWidth
this.height=(this.height - ii_WinBolderHeight)*Radio + ii_WinBolderHeight
integer i
dragobject temp//用于取各种控件
for i=1 to upperbound(this.control)
temp=this.control[i]//调整大小,位置
temp.width=temp.width*Radio
temp.x=temp.x*Radio
temp.y=temp.y*Radio
temp.Height=temp.Height*Radio
choose case typeof(temp)
    case tab!
     tab mtab
     mtab=temp
     mtab.textsize =    mtab.textsize*Radio//设置字体
    case commandbutton!
     commandbutton cb
     cb = temp
     cb.textsize =    cb.textsize*Radio
    case singlelineedit!
     singlelineedit sle
     sle = temp
     sle.textsize=sle.textsize*Radio
    case editmask!
     editmask em
     em = temp
     em.textsize =    em.textsize*Radio  
    case statictext!
     statictext st
     st = temp
     st.textsize = st.textsize*Radio
    case datawindow! // datawindows get zoomed
     datawindow dw
     dw = temp
     dw.Object.DataWindow.zoom = string(int(Radio*100))//注意DATAWINDOW与其它控件的不同
    case picturebutton!
     picturebutton pb
     pb = temp
     pb.textsize =    pb.textsize*Radio
    case checkbox!
     checkbox cbx
     cbx = temp
     cbx.textsize =    cbx.textsize*Radio
    case dropdownlistbox!
     dropdownlistbox ddlb
     ddlb = temp
     ddlb.textsize =    ddlb.textsize*Radio
    case groupbox!
     groupbox gb
     gb = temp
     gb.textsize =    gb.textsize*Radio
    case listbox!
     listbox lb
     lb = temp
     lb.textsize    =    lb.textsize*Radio
    case multilineedit!
     multilineedit mle
     mle = temp
     mle.textsize = mle.textsize*Radio
    case radiobutton!
     radiobutton rb
     rb = temp
     rb.textsize =    rb.textsize*Radio
end choose
next
this.show()
return 0
函数写好以后,在窗体的OPEN事件里调用该函数即可.


//pb打印方面的一些问题
//PB中如何使用带孔打印纸
操作系统:win98
编程工具:pb70
问题:在pb中,数据窗口打印时,常常需要用带孔打印纸,我的办法是,在数据窗口的打印属性中选择
“default(0)”,然后在打印机属性中,设置自定义纸张(3800×2800),这才可能打印。在使用中,如果有
窄行、宽行多种自定义纸张,就需要在多者之间选来选出,实在是麻烦。请问能否用命令去设置自定义
纸张,而又不用去设置打印机属性,我现在一个项目只有这个问题,其他已经完成,很急用,在这里我
万分感谢,!请帮帮我吧!!!请赐教?
水平: 中级
回答:
s_w_y的意见:
数据对象窗口有此属性:dw_control.Object.DataWindow.Print.Paper.Size可以通过设置此属性来实现
自定义打印纸张大小。
ZWD的意见:
我有一个很笨的办法不知是否可行。在打印机列表中增加一个打印机的多个驱动,分别设置各种自定义纸
的大小,在打印时只要选择打印机就可以了。
彭定友的意见:
请查看Datawindow相关的打印属性:dw_1.object.datawindow.print.property
如:dw_1.object.datawindow.print.copies=10 打印10份
dw_1.object.datawindow.print.Orientation=1 横向打印
dw_1.object.datawindow.print.Range='1,3-8,10' 打印1,3,4,5,6,7,8,10页
dw_1.object.datawindow.print.paper.Size=x (0-33分别表示纸张大小)
dw_1.object.datawindow.print.preview=true 打印预览
dw_1.object.datawindow.print.Zoom=80% 缩小预览打印
dw_1.object.datawindow.print.Scale=2 改变实际打印比例
dw_1.object.datawindow.print.margin.top=50 改变打印至顶端距离
。。。。。。。。。。。。。
//PB如何控制打印指定某页或某几页
操作系统:Windows 98 oem
编程工具:PowerBuilder 6.0
问题:在PB开发应用软件中,能否像WORD打印那样控制打印指定某页,或某几页范围(因为打印机问题
等而打坏了某页,需要这样做)。在PFC中有这似有这样的对话框,但不知道怎样用。而且是之前我开发
的PB程序中有的窗体名字与PFC库中的一样(若要改涉及许多问题),又怎样引用PFC库中的函数等。
不胜感激
回答: dw_1.object.datawindow.print.page.range='1,3,5-10,15'
//使用PRINTTEXT函数打印,如何设置打印字符的宽度
操作系统:windows、nt
编程工具:powerbuilder
问题:在使用PB中的PRINTTEXT函数打印,如何设置打印字符的宽度?
水平: 中级
回答: 用PrintDefineFont()设置。
//PB在一些已有格式和文字的表单上打印
编程工具: powerbuilder
操作系统: windows98
初接触PB,想用它为朋友编一个表单的打印程序,即在一些已打印好格式和文字的表单上,打印相应
数据。不知用PB好实现不,及如何实现?谢谢。
回答: 可以实现,用两个数据窗口(DataWindow),一个数据窗口用作数据输入,第二个数据窗口用作
打印数据,第二个数据窗口在设置数据窗口各控件位置时要根据已经打印的表单位置放置,打印样张再
重新设置,要多试几次。当第一个数据窗口输入完数据后,把数据复制到第二个数据窗口,然后用
print()函数打印第二个数据窗口。
sulo_xxr的意见:
利用printtext()、printsetspacing()、print()三个可以实现。建议你先弄清楚它们的用法之后可以
方便实现。
//如何打印条形码
操作系统:win98
编程工具:PB6.5
问题:请教老师:如何在PB中打印条形码,条形码打印机如何驱动。拜托!
回答:
如果安装了Office2000,则在其Program FilesMicrosoft OfficeOfficeMsbcode9.ocx 及 Msbcode9.hlp
条形码控件。
李海注:如果在目录中找不到该控件,说明安装的时候没有选择。可以再运行安装程序,并在Access
2000下找到Barcode控件项。安装后在Visual Basic等软件中显示为Microsoft Barcode Control 9.0。
Office97没有该控件,但Office XP中包括了这个控件,仍然为Msbcode9.ocx。
在PB7中,Insert -> Control ->OLE...
出现Insert Object对话框 选择Insert Control页 单击Register New 指定..officeMsbcode9.ocx 路径
(或run: regsvr32 c:office2kofficeMsbcode9.ocx) (好象不重新注册不能在VB & PB... 中使)
代码:
long Job
Job = PrintOpen( )
Ole_1.border=false
ole_1.Print(Job, 500,1000)
PrintClose(Job)
Ole_1.border=true
效果不错!
虽然Msbcode9.ocx本身没有Print方法,但PB中的OLE容器有Print方法(意外)。
以上文章来自互联网,著作权归原作者所有。


//PB调用外部程序及判断其完成的方法
关键:API函数FindWindowA和IsWindow
在PB中常常需要运行一些外部的程序或命令,并等待其执行完成后,才接下来运行剩余的代码。我们可以
有两种方法:
先定义全局外部函数:
Function long ShellExecuteA (long hwnd, string lpOperation ,String lpFile, String lpParameters, String lpDirectory, Long nShowCmd) Library "shell32.dll"
Function long FindWindowA (String lpClassName , String lpWindowName ) Library "user32.dll"
Function boolean IsWindow (Long hwnd ) Library "user32.dll"
第一种方式用Run() 函数,可在窗口上建立按扭,clicked事件中包含如下Script:
ulong ll_handle
int li_loop
SetPointer(HourGlass!)
//最小化执行xxx.bat
run("xxx.bat", Minimized!)
//循环到窗口打开,根据程序执行打开所需的时间设定li_loop的循环次数,可预留长一些。
for li_loop= 1 to 10000
ll_handle = FindWindowA("tty","xxx")
yield() //函数作用详见"PB技巧"中《Pb中Yield()函数的使用》
if ll_handle <> 0 then
exit
end if
next
//一直循环到窗口关闭 Do While isWindow(ll_handle)
Yield()
Loop
//应用执行完成
messagebox('ok', '执行完成!')
这种方法的缺点是不能隐藏外部应用程序窗口,只能最小化。
第二种方式用API函数,可以隐藏应用程序的窗口,但是调用bat批处理命令时需要先建立一个PIF文件指定执行完成后关闭窗口,否则窗口不会自行关闭。可在窗口上建立按扭,clicked事件中包含如下Script:
uint lu_return
ulong ll_handle
int li_loop
string ls_Path
SetPointer(HourGlass!)
lu_return = ShellExecutea(handle(parent), "open", "xxx.pif", "", ls_path, 0)
//最后一个参数改为 4,可以显示执行情况
if lu_return > 32 then
for li_loop= 1 to 10000
ll_handle = FindWindowA("tty","xxx")
yield()
if ll_handle <> 0 then
exit
end if
next
//一直循环到窗口关闭
Do While isWindow(lu_handle)
Yield()
Loop
//应用执行完成
MessageBox("ok", "执行完成!")
Else
//error
messagebox("错误", "调用外部应用程序不成功,请检查应用程序路径!")
end if


//在PB中如何得到计算机的IP地址
声明win32 API函数:
function int WSAStartup( uint UIVersionRequested, ref s_WSAData lpWSAData ) library "wsock32.dll"
function int WSACleanup() library "wsock32.dll"
function int WSAGetLastError ( ) library "wsock32.dll"
function int gethostname ( ref string name, int namelen ) library "wsock32.dll"
function string GetHost(string lpszhost, ref blob lpszaddress ) library "pbws32.dll"  
使用方法:
s_wsadata l_WSAData
string ls_HostName = space(128)
string ls_IpAddress
int li_version = 257
blob{4} lb_hostaddress
IF wsastartup ( li_version, l_WSAData ) = 0 THEN
IF gethostname ( ls_HostName, len(ls_HostName) ) < 0 THEN
messagebox("GetHostName",WSAGetLastError())
ELSE
GetHost(ls_HostName, lb_HostAddress)
ls_IpAddress = string(asc(string(blobmid(lb_HostAddress,1,1))),"000") + "."
ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,2,1))),"000") + "."
ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,3,1))),"000") + "."
ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,4,1))),"000")
END IF
WSACleanup()
ELSE
messagebox("GetHostName",WSAGetLastError())
END IF
sle_1.text=ls_hostname
sle_2.text=ls_ipaddress


//PB的error.number列表,有待继续补充
string    ls_msg
choose case error.number
case 1//by zero
    ls_msg = "发生被 0 除错误"
case 2//2 Null object reference
    ls_msg = "空对象引用"
case 3//3 Array boundary exceeded
    ls_msg = "数组越界"
case 4//4 Enumerated value is out of range for function
    ls_msg = "枚举值超出函数的范围"
case 5//5 Negative value encountered in function
    ls_msg = "函数中遇到负数"
case 6//6 Invalid DataWindow row/column specified
    ls_msg = "数据窗口的列或行非法"
case 7//7 Unresolvable external when linking reference
    ls_msg = "链接调用时不能解决外部对象"
case 8//8 Reference of array with null subscript
    ls_msg = "使用空下标引用数组"
case 9//9 DLL function not found in current application
    ls_msg = "当前应用中没有找到动态链接库的函数"
case 10//10 Unsupported argument type in DLL function
    ls_msg = "使用了动态链接库函数不支持的参数类型"
case 11//11 Object file is out of date and must be converted to current version
    ls_msg = "对象文件已经过时并且必须使用当前的版本"
case 12//12 DataWindow column type does not match GetItem type
    ls_msg = "数据窗口的列的数据类型与GetItem函数的类型不符"
case 13//13 Unresolved property reference
    ls_msg = "属性引用尚未解决"
case 14//14 Error opening DLL library for external function
    ls_msg = "为外部函数调用而打开动态链接库时发生错误"
case 15//15 Error calling external function name
    ls_msg = "调用外部函数时发生错误"
case 16//16 Maximum string size exceeded
    ls_msg = "字符串长度超越了最大限制"
case 17//17 DataWindow referenced in DataWindow object does not exist
    ls_msg = "数据窗口引用的数据窗口对象不存在"
case 18//18 Function doesn't return value
    ls_msg = "函数没有返回值(应该有而没有)"
case 19//19 Cannot convert name in Any variable to name
    ls_msg = "不能转换Any类型的变量到另一个类型"
case 20//20 Database command has not been successfully prepared
    ls_msg = "数据库命令没有成功准备"
case 21//21 Bad runtime function reference
    ls_msg = "引用了错误的运行时函数"
case 22//22 Unknown object type
    ls_msg = "不知道的对象类型"
case 23//23 Cannot assign object of type name to variable of type name
    ls_msg = "不能将对象赋给变量,两种类型不能赋值"
case 24//24 Function call doesn't match its definition
    ls_msg = "函数调用格式与其定义不一致"
case 25//25 Double or Real expression has overflowed
    ls_msg = "双精度型或实型表达式溢出"
case 26//26 Field name assignment not supported
    ls_msg = "不支持这种字段赋值"
case 27//27 Cannot take a negative to a noninteger power
    ls_msg = "不能计算一个负数的非整数次方"
case 28//28 VBX Error: name
    ls_msg = "VBX 错误"
case 29//29 Nonarray expected in ANY variable
    ls_msg = "ANY 类型变量期待非数组类型"
case 30//30 External object does not support data type name
    ls_msg = "外部对象不支持这种变量类型"
case 31//31 External object data type name not supported
    ls_msg = "外部对象的数据类型不支持"
case 32//32 Name not found calling external object function name
    ls_msg = "调用外部对象函数时函数名称没有找到"
case 33//33 Invalid parameter type calling external object function name
    ls_msg = "调用外部对象函数时使用了错误的参数类型"
case 34//34 Incorrect number of parameters calling external object function name
    ls_msg = "调用外部对象函数时使用的参数个数不对"
case 35//35 Error calling external object function name
    ls_msg = "调用外部对象的函数错误"
case 36//36 Name not found accessing external object property name
    ls_msg = "访问外部对象属性时属性名称没有找到"
case 37//37 Type mismatch accessing external object property name
    ls_msg = "访问外部对象属性时使用了不匹配的类型"
case 38//38 Incorrect number of subscripts accessing external object property name
    ls_msg = "访问外部对象属性时使用了错误的下标"
case 39//39 Error accessing external object property name
    ls_msg = "访问外部对象的属性错误"
case 40//40 Mismatched ANY data types in expression
    ls_msg = "表达式中ANY数据类型不匹配"
case 41//41 Illegal ANY data type in expression
    ls_msg = "表达式中使用了非法的ANY数据类型"
case 42//42 Specified argument type differs from required argument type at runtime in DLL function name
    ls_msg = "指定的参数类型与动态链接库中的函数所需要的参数类型不一致"
case 43//43 Parent object doesn't exist
    ls_msg = "父对象不存在"
case 44//44 Function has conflicting argument or return type in ancestor
    ls_msg = "函数与祖先的参数或返回值冲突"  
case 45//45 Internal table overflow; maximum number of objects exceeded
    ls_msg = "内部表溢出;对象的最大数目已经超越"
case 46//46 Null object reference cannot be assigned or passed to a variable of this type
    ls_msg = "空对象引用不能赋值或传递给一个这种类型的变量"
case 47//47 Array expected in ANY variable
    ls_msg = "ANY类型期待数组"
case 48//48 Size mismatch in array to object conversion
    ls_msg = "将数组转换成对象时数组的大小不匹配"
case 49//49 Type mismatch in array to object conversion
    ls_msg = "将数组转换成对象不匹配"
case 50//50 Distributed Service Error
    ls_msg = "分布式服务错误"
case 51//51 Bad argument list for function/event
    ls_msg = "函数/事件的参数列表错误"
case 52//52 Distributed Communications Error
    ls_msg = "分布式通讯错误"
case 53//53 Requested server not active
    ls_msg = "被请求的服务器没有激活"
case 54//54 Server not accepting requests
    ls_msg = "服务器不接受请求"
case 55//55 Request terminated abnormally
    ls_msg = "请求意外中断"
case 56//56 Response to request incomplete
    ls_msg = "响应请求不完整"
case 57//57 Not connected
    ls_msg = "没有连接"
case 58//58 Object instance does not exist
    ls_msg = "对象实例不存在"
case 59//59 Invalid column range
    ls_msg = "无效的列的范围"
case 60//60 Invalid row range
    ls_msg = "无效的行的范围"
case 61//61 Invalid conversion of number dimensional array to object
    ls_msg = "转换多维数组到一个对象无效"
case 62//62 Server busy
    ls_msg = "服务器忙"
case 63//63 Function/event with no return value used in expression
    ls_msg = "在表达式中函数/事件没有返回值"
case 64//64 Object array expected in left side of assignment
    ls_msg = "赋值语句左边期待对象数组"
case 65//65 Dynamic function not found. Possible causes include: pass by value/reference mismatch
    ls_msg = "动态函数没有找到,可能是因为:值传递/引用传递不匹配"
case 66//66 Invalid subscript for array index operation
    ls_msg = "属组索引使用了非法的下标"
case 67//67 NULL object reference cannot be assigned or passed to an autoinstantiate
    ls_msg = "空的对象引用不能赋值或传递给一个自动实例化对象"
case 68//68 NULL object reference cannot be passed to external DLL function name
    ls_msg = "空的对象引用不能传递给外部动态链接库函数"
case 69//69 Function name cannot be called from a secured runtime session
    ls_msg = "安全模式中不能调用该函数"
case 70//70 External DLL function name cannot be called from a secured runtime session
    ls_msg = "安全模式中不能调用外部动态链接库函数"
case 71//71 General protection fault occurred
    ls_msg = "发生一般的保护错误"
case 72//72 name failed with an operating system error code of number
    ls_msg = "字段发生一个操作系统错误"
case 73//73 Reference parameters cannot be passed to an asynchronous shared/remote object method
    ls_msg = "引用型参数不能传递给一个异步的共享/远程对象方法"
case 74//74 Reference parameters cannot be passed to a shared object method
    ls_msg = "引用型参数不能传递给一个共享对象的方法"
case 75//75 The server has forced the client to disconnect
    ls_msg = "服务器已经强制客户端断开连接"
case 76//76 Passing NULL as a parameter to external function name
    ls_msg = "给外部函数传递了一个空值参数"
case 77//77 Object passed to shared/remote object method is not a nonvisual user object
    ls_msg = "对象传递给共享/远程对象的方法不是一个不可视的用户对象"
case 78//78 Listen can only be done in Enterprise version of PowerBuilder
    ls_msg = "监听只能在企业版的PowerBuilder中使用"
case 79//79 The argument to name must be an array
    ls_msg = "参数必须是一个数组"
case 80//80 The server has timed out the client connection
    ls_msg = "客户端尝试连接的时间已经超出服务器设置的限制时间"
case 81//81 Function argument file creator must be a four character string
    ls_msg = "函数参数文件创建者必须是一个四个字符的字符串"
case 82//82 Function argument file type must be a four character string
    ls_msg = "函数参数文件类型必须是一个四个字符的字符串"
case 83//83 Attempt to invoke a function or event that is not accessible
    ls_msg = "试图调用一个不可存取的函数或事件"
case 84//84 Wrong number of arguments passed to function/event call
    ls_msg = "在函数/事件中传递的参数个数错误"
case 85//85 Error in reference argument passed in function/event call
    ls_msg = "在函数/事件中传递的引用型参数错误"
case 86//86 Ambiguous function/event reference
    ls_msg = "引用不明确的函数/事件"
case 87//87 The connection to the server has been lost
    ls_msg = "与服务器的连接已经丢失"
case 88//88 Cannot ask for ClassDefinition Information on open painter: name
    ls_msg = "不能在打开的画笔中查询类定义信息"
case 85//89 5.0 style proxy objects are not supported. Copy the new style proxy that was generated at migration time
    ls_msg = "5.0中的类型代理对象不支持,拷贝移植时产生的新的类型代理"
case 90//90 Cannot assign array of type name to variable of type array of name
    ls_msg = "这两种数据类型的数组不能赋值"
case 91//91 Cannot convert any in Any variable to string.Possible cause uninitialized value.
    ls_msg = "不能将任意型变量转变成字符型变量"
case else
    ls_msg = '未知错误, 请记录错误号并与管理员联系'
end choose

 
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值