使用PB開發來電管理軟件 |
chen在2007/8/5發表,被瀏覽8725次
|
適合對象:記得來電顯示管理器 開發環境:PowerBuilder 下載范例:JDDemoPB.rar 下載控件:MSCOMM.rar
 注意:需要使用ActiveX控件MSCOMM32.OCX 方法:選擇“Insert”-〉“Control”-〉“OLE...”-〉“Insert Object”-〉“Insert Control”-〉“Microsoft Communications Control”
?Generated Application Objectforward global type jddemo1 from application string appname = "jddemo1" string displayname = "來電顯示" end type global jddemo1 jddemo1 on jddemo1.create appname="jddemo1" message=create message sqlca=create transaction sqlda=create dynamicdescriptionarea sqlsa=create dynamicstagingarea error=create error end on on jddemo1.destroy destroy(sqlca) destroy(sqlda) destroy(sqlsa) destroy(error) destroy(message) end on event open;Open(Form1) end event
?forward global type form1 from window end type type lb_1 from listbox within form1 end type type ole_1 from olecustomcontrol within form1 end type type cb_2 from commandbutton within form1 end type type cb_1 from commandbutton within form1 end type type ddlb_1 from dropdownlistbox within form1 end type type st_1 from statictext within form1 end type end forward global type form1 from window integer width = 1765 integer height = 960 boolean titlebar = true string title = "來電顯示" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 lb_1 lb_1 ole_1 ole_1 cb_2 cb_2 cb_1 cb_1 ddlb_1 ddlb_1 st_1 st_1 end type global form1 form1 on form1.create this.lb_1=create lb_1 this.ole_1=create ole_1 this.cb_2=create cb_2 this.cb_1=create cb_1 this.ddlb_1=create ddlb_1 this.st_1=create st_1 this.Control[]={this.lb_1,& this.ole_1,& this.cb_2,& this.cb_1,& this.ddlb_1,& this.st_1} end on on form1.destroy destroy(this.lb_1) destroy(this.ole_1) destroy(this.cb_2) destroy(this.cb_1) destroy(this.ddlb_1) destroy(this.st_1) end on event open;lb_1.Reset() end event type lb_1 from listbox within form1 integer x = 59 integer y = 56 integer width = 1074 integer height = 728 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 boolean sorted = false borderstyle borderstyle = stylelowered! end type type ole_1 from olecustomcontrol within form1 event oncomm ( ) integer x = 1303 integer y = 656 integer width = 174 integer height = 152 integer taborder = 40 borderstyle borderstyle = stylelowered! boolean focusrectangle = false string binarykey = "form1.win" integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! string facename = "Arial" long textcolor = 33554432 end type type cb_2 from commandbutton within form1 integer x = 1230 integer y = 508 integer width = 402 integer height = 112 integer taborder = 30 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" string text = "關閉" end type event clicked;//關閉端口。 ole_1.object.PortOpen = FALSE lb_1.AddItem("已關閉連接") end event type cb_1 from commandbutton within form1 integer x = 1230 integer y = 344 integer width = 402 integer height = 112 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" string text = "連接" end type event clicked; String s Integer k Integer l Integer i Integer p String ss //使用COM1端口。 ole_1.object.CommPort = Integer(Right(ddlb_1.Text,1)) //設置速率為9600,無奇偶校驗,8 位數據,一個停止位。 ole_1.object.Settings = "9600,N,8,1" //讀入整個緩沖區的數據。 ole_1.object.InputLen = 1 //打開端口 ole_1.object.PortOpen = True lb_1.Reset() lb_1.AddItem("已連接,正在監聽...") //等待數據。 Do while True Do Yield() //從Com端口取數據 if not ole_1.object.portopen then Return s += ole_1.object.Input LOOP Until(Pos(s, char(85) + char(85) + char(85) + char(85) + char(85) + char(85)) > 0) //Hex=55 Do Yield() s = ole_1.object.Input Loop Until s <> "" K = Asc(s) Do Yield() s = ole_1.object.Input Loop Until s <> "" l = Asc(s) i = 0 ss = "" Do Yield() s = ole_1.object.Input If s <> "" Then ss = ss + s i = i + 1 End If Loop Until i >= l //復合數據格式 If k = 128 Then //Hex=80 p = Pos(ss, Char(1)) if p > 0 Then l = Asc(Mid(ss, p + 1, 1)) lb_1.AddItem("來電時間: " + Mid(ss, p + 2, l)) End If p = Pos(ss, Char(2)) If p > 0 Then l = Asc(Mid(ss, p + 1, 1)) lb_1.AddItem("來電號碼: " + Mid(ss, p + 2, l)) End If End If // 單數據格式 If k = 4 Then lb_1.AddItem("來電時間: " + Mid(ss, 1, 8)) lb_1.AddItem("來電號碼: " + Mid(ss, 9, l - 8)) End If ss = "" Loop end event type ddlb_1 from dropdownlistbox within form1 integer x = 1216 integer y = 160 integer height = 400 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 string text = "COM1" boolean allowedit = true string item[] = {"COM1","COM2","COM3","COM4"} borderstyle borderstyle = stylelowered! end type type st_1 from statictext within form1 integer x = 1225 integer y = 56 integer width = 402 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 long backcolor = 67108864 string text = "連接端口" boolean focusrectangle = false end type
|
|
|
|