Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   accessing notepad's textfield (http://www.programmingforums.org/showthread.php?t=2213)

GoO Feb 11th, 2005 3:42 PM

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! :D

big_k105 Feb 11th, 2005 3:48 PM

i dont know if that is even possible. but i dont know

Ooble Feb 12th, 2005 8:20 AM

Try the SendKeys API. It's not extremely reliable, unfortunately, but it should get the job done.

GoO Feb 13th, 2005 3:07 AM

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.

Ooble Feb 13th, 2005 7:51 AM

Ah... sorry, thought you wanted to send text to Notepad. All you really need, then, is the handle to the text box.

Rory Feb 13th, 2005 5:27 PM

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


GoO Feb 14th, 2005 5:20 AM

thanks.. ill try it

Cipher Feb 16th, 2005 6:11 PM

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

Ooble Feb 16th, 2005 8:21 PM

I said that. He needs to get stuff from the text field, not send stuff.

Cipher Feb 17th, 2005 4:40 PM

Oh I see...I am not quite sure how to do that. Maybe a read API?


All times are GMT -5. The time now is 6:08 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC