文字列のスクロール <TOP>
エディットボックスの文字列表示位置をスクロールします。
SendMessage ウィンドウにメッセージを送信
SB_LINERIGHT(1) 右矢印ボタンクリック例では、左右スクロール5文字、上下スクロール1行に設定しています。
'================================================================ '= 文字列のスクロール
'= (TextScroll.bas) '================================================================ #include "Windows.bi" ' ウィンドウにメッセージを送信。この関数は、指定したウィンドウのウィンドウプロシージャが処理を終了するまで制御を返さない Declare Function Api_SendMessage& Lib "user32" Alias "SendMessageA" (ByVal hWnd&, ByVal wMsg&, ByVal wParam&, ByVal lParam&) #define SB_LINERIGHT 1 '右矢印ボタンクリック #define SB_LINELEFT 0 '左矢印ボタンクリック #define SB_LINEUP 0 '上向きの矢印ボタンクリック #define SB_LINEDOWN 1 '下向きの矢印ボタンクリック #define WM_HSCROLL &H114 '水平スクロールバーを調整している #define WM_VSCROLL &H115 'ユーザーが垂直スクロールバーを調整した Var Shared Edit1 As Object Edit1.Attach GetDlgItem("Edit1") : Edit1.SetFontSize 14 '================================================================ '= '================================================================ Declare Function EditHScroll(hWnd As Long, bScrollRight As Integer, LenTxt As Long) As Long Function EditHScroll(hWnd As Long, bScrollRight As Integer, LenTxt As Long) As Long Var Txt As Long If bScrollRight Then For Txt = 1 To LenTxt EditHScroll = Api_SendMessage(hWnd, WM_HSCROLL, SB_LINERIGHT, ByVal 0) Next Else For Txt = 1 To LenTxt EditHScroll = Api_SendMessage(hWnd, WM_HSCROLL, SB_LINELEFT, ByVal 0) Next End If End Function '================================================================ '= '================================================================ Declare Function EditVScroll(hWnd As Long, bScrollUp As Integer, LenTxt As Long) As Long Function EditVScroll(hWnd As Long, bScrollUp As Integer, LenTxt As Long) As Long Var Txt As Long If bScrollUp Then For Txt = 1 To LenTxt EditVScroll = Api_SendMessage(hWnd, WM_VSCROLL, SB_LINEUP, ByVal 0) Next Else For Txt = 1 To LenTxt EditVScroll = Api_SendMessage(hWnd, WM_VSCROLL, SB_LINEDOWN, ByVal 0) Next End If End Function '================================================================ '= '================================================================ Declare Sub MainForm_Start edecl () Sub MainForm_Start() Var txt As String For i = 0 To 19 For j = 65+i To 120+i txt = txt & Chr$(j) Next txt = txt & Chr$(13, 10) Next Edit1.SetWindowText txt End Sub '================================================================ '= '================================================================ Declare Sub Button1_on edecl () Sub Button1_on() Var Ret As Long Ret = EditHScroll(Edit1.GethWnd, False, 5) End Sub '================================================================ '= '================================================================ Declare Sub Button2_on edecl () Sub Button2_on() Var Ret As Long Ret = EditHScroll(Edit1.GethWnd, True, 5) End Sub '================================================================ '= '================================================================ Declare Sub Button3_on edecl () Sub Button3_on() Var Ret As Long Ret = EditVScroll(Edit1.GethWnd, False, 1) End Sub '================================================================ '= '================================================================ Declare Sub Button4_on edecl () Sub Button4_on() Var Ret As Long Ret = EditVScroll(Edit1.GethWnd, True, 1) End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End