//自適應螢幕解析度的基類視窗(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 = "Null 物件引用"
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 = "Null 物件引用不能賦值或傳遞給一個這種類型的變數"
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