EditBox1、EditBox2、EditBox3があるとして
EditBox1+EditBox2=EditBox3
のようにしたいのですがEditBoxの中身を取得する方法が分かりません
教えてください
エディットボックスの内容の取得
Re: エディットボックスの内容の取得
GetWindowText()を使います。使い方はヘルプを見てください。
ヘルプセンターの「Win32プログラミング講座」→「11.テキスト エディタを作る」も参照するとよいと思います。
ちなみに、イグトランス様が実践コードモジュールに投稿なされている
GetWindowTextStr()を使うと簡単にできます。
サンプル。
※EditBox1が変更されたときに、EditBox3に出力する。
ヘルプセンターの「Win32プログラミング講座」→「11.テキスト エディタを作る」も参照するとよいと思います。
ちなみに、イグトランス様が実践コードモジュールに投稿なされている
GetWindowTextStr()を使うと簡単にできます。
サンプル。
※EditBox1が変更されたときに、EditBox3に出力する。
コード: 全て選択
'EditBox1のEN_CHANGEイベント
Sub MainWnd_EditBox1_Change()
Dim strEdit1 As String
Dim strEdit2 As String
Dim strEdit3 As String
GetWindowTextStr( GetDlgItem(hMainWnd, EditBox1), strEdit1 ) 'strEdit1の内容を取得
GetWindowTextStr( GetDlgItem(hMainWnd, EditBox2), strEdit2 ) 'strEdit2の内容を取得
strEdit3 = strEdit1 + strEdit2
SetWindowText( GetDlgItem(hMainWnd, EditBox3), StrPtr(strEdit3) )'strEdit3に内容をセット
End Sub
実践コードモジュール(上記リンク先)の刹那さん さんが書きました:> "GetWindowTextStr" 無効な識別子です
「↓使うときにはこれをコピーしてください。」に示されている
コードもソース内に貼り付けてますでしょうか?
追記。
せっかくなのでGetWindowTextStr()の定義も一緒にしたコードを載せます。
こちらをクリックしてください。 [ここをクリックすると内容が表示されます]
コード: 全て選択
'EditBox1のEN_CHANGEイベント
Sub MainWnd_EditBox1_Change()
Dim strEdit1 As String
Dim strEdit2 As String
Dim strEdit3 As String
GetWindowTextStr( GetDlgItem(hMainWnd, EditBox1), strEdit1 ) 'strEdit1の内容を取得
GetWindowTextStr( GetDlgItem(hMainWnd, EditBox2), strEdit2 ) 'strEdit2の内容を取得
strEdit3 = strEdit1 + strEdit2
SetWindowText( GetDlgItem(hMainWnd, EditBox3), StrPtr(strEdit3) )'strEdit3に内容をセット
End Sub
'実践コードモジュールから「String型のGetWindowText」転載
Function GetWindowTextStr(hwnd As HWND, ByRef str As String) As Long
Dim Length As Long
Length = GetWindowTextLength(hwnd)
str = ZeroString(Length)
If Length = 0 Then
GetWindowTextStr = 0
Exit Function
End If
GetWindowTextStr = GetWindowText(hwnd, StrPtr(str), Length + 1)
SetDWord(StrPtr(str) - SizeOf (DWord), GetWindowTextStr)
End Function