Results 1 to 2 of 2

Thread: Getting This To Work Plz Help

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    53

    Getting This To Work Plz Help

    Well i grabbed this peice of code from somehwere aint taking credits i just thought it be cool to modify it for other games and what not like notepad wordpad games etc , this was orginally for Ultima Online , for a test i tryed doing it with notepad it brings it up but does not put text into it and i don't know why heres the code

    Code:
    ' Module for sending text to Ultima Online's Window & Declares here
    ' Code by Jason ([email protected])
    
    Option Explicit
    
    Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
    
    Public Const WM_CHAR = &H102
    
    Public Sub SendUOText(text$)
        Dim k As Integer
        Dim handle As Long
        Dim anerror As Boolean
        Dim lretval As Long
        Dim title$
        Dim uotitle$
        text$ = text$ & Chr$(13) 'adds Chr$(13) {which is enter} to actually send text
    
            handle = 0
            handle = FindWindow("Notepad", CLng(0)) 'normal UO:2D
            If handle = 0 Then
                handle = FindWindow("Notepad", CLng(0)) 'UO:Third Dawn
            End If
            'this part of the code can also be used to determine window name (character and shard)
            title$ = String(GetWindowTextLength(handle) + 1, Chr$(0))
            lretval = GetWindowText(handle, title$, Len(title$))
            If handle <> 0 Then
                For k = 1 To Len(text$)
                   lretval = PostMessage(handle, WM_CHAR, Asc(Mid$(text$, k, 1)), 0) 'actually sends text to UO
                Next
                anerror = False 'no error, home free
                AppActivate (title$) 'brings it forward once text sent to screen
            Else
                anerror = True 'there was an error, message for error below
            End If
        If anerror = True Then Err = MsgBox("Something went wrong," + vbCr + "either UO is not running or another error ocurred" + vbCr + "Please run UO first. ", vbOKOnly, "Oops!")
    End Sub
    so ive changed the name to find the window notepad but it isn't writing anything in it , do i need to get a process id or something to put in
    here is the peice of code i think needs something changed if anyone could tell me thanks and explain that peice of line cuz idk

    lretval = PostMessage(handle, WM_CHAR, Asc(Mid$(text$, k, 1)),

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Getting This To Work Plz Help

    The characters are being sent to Notepad's Application Window. Send the characters to Notepad's Editor window. I did a google search and found you need to add

    Code:
    Private Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long 
    
    handle = FindWindow("Notepad", CLng(0))
    hwndEditor = GetDlgItem(handle, &HF)
    No idea how they knew to use &HF

    Call PostMessage using the value of the hwndEditor variable instead of the handle variable.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width