ウィンドウのタイトル文字数を取得          <TOP>


ウィンドウのタイトル文字数を取得します。

GetWindowTextLength ウィンドウのタイトル文字数を取得

SetWindowText ウインドウのタイトルを変更

GetWindowText ウインドウのタイトル文字列を取得

GetActiveWindow アクティブなウィンドウのハンドルを取得  

 

SetWindowText、GetWindowTextはF-BASICと同じです。

   

 

'================================================================
'= ウィンドウのタイトル文字数を取得
'=    (GetWindowTextLength.bas)
'================================================================
#include "Windows.bi"

' ウィンドウのタイトル文字数を取得
Declare Function Api_GetWindowTextLength& Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd&)

' ウインドウのタイトルを変更
Declare Function Api_SetWindowText& Lib "user32" Alias "SetWindowTextA" (ByVal hWnd&, ByVal lpString$)

' ウインドウのタイトル文字列を取得
Declare Function Api_GetWindowText& Lib "user32" Alias "GetWindowTextA" (ByVal hWnd&, ByVal lpString$, ByVal cch&)

' アクティブなウィンドウのハンドルを取得
Declare Function Api_GetActiveWindow& Lib "user32" Alias "GetActiveWindow" ()

Var Shared Text1 As Object
Var Shared Button1 As object
Var Shared Button2 As object
Var Shared Button3 As object

Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14
Button2.Attach GetDlgItem("Button2") : Button2.SetFontSize 14
Button3.Attach GetDlgItem("Button3") : Button3.SetFontSize 14

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var ActiveWnd As Long
    Var Ret As Long

    ActiveWnd = Api_GetActiveWindow()
    Ret = Api_GetWindowTextLength(ActiveWnd)
    Text1.SetWindowText Str$(Ret)
End Sub

'================================================================
'=
'================================================================
Declare Sub Button2_on edecl ()
Sub Button2_on()
    Var ActiveWnd As Long
    Var NewTitle As String
    Var Ret As Long

    NewTitle = "tokovalue.hp.infoseek.co.jp"
    
    ActiveWnd = Api_GetActiveWindow()
    Ret = Api_SetWindowText(ActiveWnd, NewTitle)
End Sub

'================================================================
'=
'================================================================
Declare Sub Button3_on edecl ()
Sub Button3_on()
    Var ActiveWnd As Long
    Var Buffer As String
    Var Char As Integer
    
    Buffer = Space$(255)
    ActiveWnd = Api_GetActiveWindow()
    Char = Api_GetWindowText(ActiveWnd, Buffer, 255)
    Text1.SetWindowText Left$(Buffer, Len(Buffer)-1)
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End