![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2004
Posts: 17
Rep Power: 0
![]() |
accessing notepad's textfield
i need to access notepad's textfield. without saving. does vb have any function or api for this?
example: i have notepad open. there are some texts there but still not saved. (ie "Untitled"). i need my vb program to read those texts. thanks! ![]() |
|
|
|
|
|
#2 |
|
PFO Founder
![]() ![]() |
i dont know if that is even possible. but i dont know
__________________
BIG K aka Kyle Programming Forums Kyle K Online Please do not PM or email me programming questions. Post them in the forums instead. |
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Try the SendKeys API. It's not extremely reliable, unfortunately, but it should get the job done.
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Nov 2004
Posts: 17
Rep Power: 0
![]() |
can u tell me what those are? i dont know anything about that.
anyway i think WM_GETTEXT should get the job done. how do i use this? syntax/declarations? thanks. |
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Ah... sorry, thought you wanted to send text to Notepad. All you really need, then, is the handle to the text box.
|
|
|
|
|
|
#6 |
|
Expert Programmer
|
Put this in a blank form, open up notepad, type something in, then run!
Also works for password textboxes! Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As _
Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private m_Buffer As String
Private m_length As Long
Private notepad_hwnd As Long
Private edit_hwnd As Long
Private Sub Form_Load()
notepad_hwnd = FindWindow("notepad", vbNullString)
edit_hwnd = FindWindowEx(notepad_hwnd, 0, "Edit", vbNullString)
'Get the handle to the edit box
'---- Structure found using Spy++ - wonderful program! ----
m_length = SendMessage(edit_hwnd, WM_GETTEXTLENGTH, 0, 0) + 1
'Get the text length
m_Buffer = Space$(m_length) 'Dimension our string to the text length
If SendMessage(edit_hwnd, WM_GETTEXT, _
Len(m_Buffer), ByVal m_Buffer) Then
'Actually get the text
MsgBox TrimNull(m_Buffer) 'The text we retrieved
End If
End Sub
Private Function TrimNull(ByVal StrIn As String) As String
Dim nul As Long
'Trims null strings
nul = InStr(StrIn, vbNullChar)
Select Case nul
Case Is > 1
TrimNull = Left$(StrIn, nul - 1)
Case 1
TrimNull = ""
Case 0
TrimNull = Trim$(StrIn)
End Select
End Function |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Nov 2004
Posts: 17
Rep Power: 0
![]() |
thanks.. ill try it
|
|
|
|
|
|
#8 |
|
Hobbyist Programmer
|
Or you coudl just do this.
Private sub Cmdsend_click() Dim Text As String Text = Text1.Text AppActivate "Notepad.exe" SendKeys Text End Sub Eithier way works just fine
__________________
And there was much rejoicing... Yay.... |
|
|
|
|
|
#9 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I said that. He needs to get stuff from the text field, not send stuff.
|
|
|
|
|
|
#10 |
|
Hobbyist Programmer
|
Oh I see...I am not quite sure how to do that. Maybe a read API?
__________________
And there was much rejoicing... Yay.... |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|