PowerBuilder Scrolling Text/Marquee Text/Typing Text
Example Code
uo_sle_scrollingtext from singlelineedit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | forward global type uo_sle_scrollingtext from singlelineedit end type type os_size from structure within uo_sle_scrollingtext end type end forward type os_size from structure long cx long cy end type global type uo_sle_scrollingtext from singlelineedit integer width = 402 integer height = 112 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "none" boolean autohscroll = false borderstyle borderstyle = stylelowered! event timer pbm_timer end type global uo_sle_scrollingtext uo_sle_scrollingtext type prototypes Function UInt SetTimer( UInt hwin, UInt idtimer, UInt TimeOut, Long tmprc ) Library "user32.dll" Function Boolean KillTimer( UInt hwin, UInt idtimer ) Library "user32.dll" Function ULong GetDC(ULong hWnd) Library "user32.dll" Function ULong SelectObject(ULong hdc, ULong hWnd) Library "gdi32.dll" Function Boolean GetTextExtentPoint32A(ULong hdcr, String lpString, Long nCount, Ref os_size size) Library "gdi32.dll" Function Long ReleaseDC(ULong hWnd, ULong hdcr) Library "user32.dll" end prototypes type variables Constant Integer WM_GETFONT = 49 end variables forward prototypes public subroutine addspace () public subroutine adjustsize () public subroutine of_start (integer ai_type, long al_time) public subroutine of_stop () public function integer settext (string as_text) end prototypes event timer;SetRedraw(False) Text = Mid(Text,2) + Left(Text,1) SetRedraw(True) end event public subroutine addspace ();If Len(Text) < 1 Then Return ULong lul_Handle, lul_hDC, lul_hFont os_size lstr_Size // create device context for statictext lul_Handle = Handle(This) lul_hDC = GetDC(lul_Handle) // get handle to the font used by statictext lul_hFont = Send(lul_Handle, WM_GETFONT, 0, 0) // Select it into the device context SelectObject(lul_hDC, lul_hFont) String ls_text = " " long ll_widthchar, ll_numchar If Not GetTextExtentPoint32A(lul_hDC, ls_text, Len(ls_text), lstr_Size) Then ReleaseDC(lul_Handle, lul_hDC) Return End If ll_widthchar = PixelsToUnits(lstr_Size.cx , XPixelsToUnits!) If ll_widthchar < 1 Then ll_widthchar = 1 ll_numchar = long(Width/ll_widthchar) If ll_numchar <=0 Then ll_numchar = 1 Text = Text + Fill(" ", ll_numchar) // release the device context ReleaseDC(lul_Handle, lul_hDC) end subroutine public subroutine adjustsize ();If Len(Text) < 1 Then Return ULong lul_Handle, lul_hDC, lul_hFont //integer li_font os_size lstr_Size //li_font = this.textsize + 1 // create device context for statictext lul_Handle = Handle(This) lul_hDC = GetDC(lul_Handle) // get handle to the font used by statictext lul_hFont = Send(lul_Handle, WM_GETFONT, 0, 0) // Select it into the device context SelectObject(lul_hDC, lul_hFont) If Not GetTextExtentPoint32A(lul_hDC, Text, Len(Text), lstr_Size) Then ReleaseDC(lul_Handle, lul_hDC) Return End If // convert length in pixels to PBUnits Width = PixelsToUnits(lstr_Size.cx, XPixelsToUnits!) //Height = PixelsToUnits(lstr_Size.cy, YPixelsToUnits!) // release the device context ReleaseDC(lul_Handle, lul_hDC) end subroutine public subroutine of_start (integer ai_type, long al_time);If al_time < 1 Then al_time = 1 Choose Case ai_type Case 1 adjustsize( ) SetTimer( Handle( This ), 0, al_time, 0 ) Case 2 addspace( ) SetTimer( Handle( This ), 0, al_time, 0 ) End Choose end subroutine public subroutine of_stop ();KillTimer( Handle( this ),0 ) end subroutine public function integer settext (string as_text);If IsNull(as_text) Then Return -1 If Len(as_text) = 0 Then Return -1 Text = as_text Return 1 end function on uo_sle_scrollingtext.create end on on uo_sle_scrollingtext.destroy end on event destructor;KillTimer( Handle( this ),0 ) end event |
uo_sle_typingtext from singlelineedit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | forward global type uo_sle_typingtext from singlelineedit end type end forward global type uo_sle_typingtext from singlelineedit integer width = 402 integer height = 112 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "none" borderstyle borderstyle = stylelowered! event timer pbm_timer end type global uo_sle_typingtext uo_sle_typingtext type prototypes Subroutine Sleep(Long lMilliSec) Library "Kernel32.dll" Function UInt SetTimer( UInt hwin, UInt idtimer, UInt TimeOut, Long tmprc ) Library "user32.dll" Function Boolean KillTimer( UInt hwin, UInt idtimer ) Library "user32.dll" end prototypes type variables String is_text boolean ib_stop long il_speed, il_char end variables forward prototypes public subroutine of_start (long al_time) public subroutine of_typing () public subroutine of_setspeed (long al_speed) public subroutine of_stop () end prototypes event timer;//of_typing() il_char++ Text = Text + Mid(is_text, il_char, 1) If il_char > Len(is_text) Then Text = "" il_char = 0 End If end event public subroutine of_start (long al_time);is_text = Text Text = "" il_char = 0 If al_time < 1 Then al_time = 1 SetTimer( Handle( This ), 0, al_time, 0 ) end subroutine public subroutine of_typing ();If ib_stop Then Return Long ll_len, li_r String ls_Text ls_Text = is_text ll_len = Len(ls_Text) Text = "" For li_r = 1 To ll_len If ib_stop Then Exit Text = Text + Mid(ls_Text, li_r, 1) Sleep(il_speed) Next end subroutine public subroutine of_setspeed (long al_speed);If al_speed < 1 Then al_speed = 1 il_speed = al_speed end subroutine public subroutine of_stop ();KillTimer( Handle( this ),0 ) end subroutine on uo_sle_typingtext.create end on on uo_sle_typingtext.destroy end on |
w_main from window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | forward global type w_main from window end type type sle_4 from uo_sle_typingtext within w_main end type type sle_3 from singlelineedit within w_main end type type sle_2 from uo_sle_scrollingtext within w_main end type type sle_1 from uo_sle_scrollingtext within w_main end type type st_3 from statictext within w_main end type type sle_speed from singlelineedit within w_main end type type cb_2 from commandbutton within w_main end type type cb_1 from commandbutton within w_main end type end forward global type w_main from window integer width = 2875 integer height = 1284 boolean titlebar = true string title = "Scrolling Text" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true sle_4 sle_4 sle_3 sle_3 sle_2 sle_2 sle_1 sle_1 st_3 st_3 sle_speed sle_speed cb_2 cb_2 cb_1 cb_1 end type global w_main w_main forward prototypes public function string wf_running (string as_text, long as_num) end prototypes public function string wf_running (string as_text, long as_num);Return Mid(as_text ,(as_num + 1) ) + Left(as_text ,as_num) end function on w_main.create this.sle_4=create sle_4 this.sle_3=create sle_3 this.sle_2=create sle_2 this.sle_1=create sle_1 this.st_3=create st_3 this.sle_speed=create sle_speed this.cb_2=create cb_2 this.cb_1=create cb_1 this.Control[]={this.sle_4,& this.sle_3,& this.sle_2,& this.sle_1,& this.st_3,& this.sle_speed,& this.cb_2,& this.cb_1} end on on w_main.destroy destroy(this.sle_4) destroy(this.sle_3) destroy(this.sle_2) destroy(this.sle_1) destroy(this.st_3) destroy(this.sle_speed) destroy(this.cb_2) destroy(this.cb_1) end on event timer;sle_3.Text = wf_running(sle_3.Text,1) end event type sle_4 from uo_sle_typingtext within w_main integer x = 73 integer y = 744 integer width = 2670 integer height = 144 integer taborder = 20 integer textsize = -18 string text = "https://pblib.com" end type type sle_3 from singlelineedit within w_main integer x = 73 integer y = 32 integer width = 2670 integer height = 172 integer taborder = 10 integer textsize = -18 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "https://pblib.com " borderstyle borderstyle = stylelowered! end type type sle_2 from uo_sle_scrollingtext within w_main integer x = 73 integer y = 516 integer width = 2670 integer height = 144 integer taborder = 10 integer textsize = -18 string text = "https://pblib.com" end type type sle_1 from uo_sle_scrollingtext within w_main integer x = 73 integer y = 288 integer width = 2670 integer height = 144 integer taborder = 10 integer textsize = -18 string text = "https://pblib.com " end type type st_3 from statictext within w_main integer x = 73 integer y = 1024 integer width = 219 integer height = 64 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Speed:" boolean focusrectangle = false end type type sle_speed from singlelineedit within w_main integer x = 293 integer y = 1004 integer width = 439 integer height = 96 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "100" borderstyle borderstyle = stylelowered! end type type cb_2 from commandbutton within w_main integer x = 1097 integer y = 1004 integer width = 293 integer height = 96 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Stop" end type event clicked;sle_1.of_stop() sle_2.of_stop() timer(0) sle_4.of_stop() end event type cb_1 from commandbutton within w_main integer x = 768 integer y = 1004 integer width = 293 integer height = 96 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Start" end type event clicked;sle_1.of_start( 1, Long(sle_speed.Text)) sle_2.of_start( 2, Long(sle_speed.Text)) timer(Long(sle_speed.Text)/1000) sle_4.of_start( Long(sle_speed.Text)) end event |
Find Projects On Github click here
Good Luck!