How To Hook NotePad In VisualBasic 6.0

Write your "How To" regarding anything you are comfortable with and you feel it will help the forum members.

NOTE :: All threads started here will appear only after the approval from Administrator
Post Reply
ag3nt
Posts: 80
Joined: Mon Apr 30, 2007 6:57 pm

How To Hook NotePad In VisualBasic 6.0

Post by ag3nt »

You can hook notepad's textarea from visual basic via code below.

add one text1 ad write down code below.

Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function SendMessageS Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

Private Const WM_GETTEXT = &HD

Dim TmpText As String * 256
Dim hwnd_Title As Long
Dim hwnd_Text As Long
Dim TextLen As Long

Private Sub Form_Load()


hwnd_Title = FindWindow("Notepad", "ag3nt.txt - Notepad")'Write title here
hwnd_Text = FindWindowEx(hwnd_Title, 0, "Edit", vbNullString) ' now after finding the program pid, get the edit box hwnd

TextLen = SendMessageS(hwnd_Text, WM_GETTEXT, Len(TmpText), TmpText) 'get the edit box containment
If TmpText = vbNullString Then
Text1.Text = "No text detected..."
Else:
Text1.Text = Left(TmpText, TextLen)
End If

End Sub

I hope it will be helpful for you all,ag3nt


New And Crazy Member Of SmokyHosts Community

By Ag3nt
SHAdmin
Posts: 2089
Joined: Sat Dec 18, 2004 11:28 am
Contact:

Post by SHAdmin »

Your 'How To' has been approved and you have been credited 20 points for sharing it.
Post Reply