Paltalking (any version) with VB 2005 Express Beta

You can talk about VB programming here

Paltalking (any version) with VB 2005 Express Beta

Postby mightythor » Thu Jul 28, 2005 9:17 pm


I would have preferred to zip up my project and attach it, or stick it in the download area, but I didn't see how. Sorry if this violates etiquette.

I am using Visual Basic 2005 Express Beta. I think you will find the code interesting. I have not written anything that has not been accomplished before in different ways. I wrote yet another routine to write to Paltak for a specific group name, in Version 8. Big Woop. But I think you will find the use of collections, classes, and recursion worth a look. These are three things that were greatly improved in the new Visual Basic. Special thanks to loco for coming up with the idea to declare a richtextbox to do formatting.

This code should work for any Paltalk verson. Let me know if I am wrong.
Code: Select all
Imports System.Collections.Generic
Public Class HandleGrabber

    ' ********** Well I do declare **********
    Declare Function GetWindow Lib "user32" (ByVal hwnd As Int32, ByVal wCmd As Int32) As Int32
    Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Int32, ByVal lpString As String, ByVal cch As Int32) As Int32
    Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Int32, ByVal lpClassName As String, ByVal nMaxCount As Int32) As Int32
    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
    Public Declare Function SendMessageByString Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As String) As Int32
    Public Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32

    Public Const GW_CHILD = 5
    Public Const GW_HWNDNEXT = 2

    Public Const WM_LBUTTONDOWN As Int32 = &H201
    Public Const WM_LBUTTONUP As Int32 = &H202
    Public Const WM_SETTEXT As Int32 = &HC
    Public Const WM_GETTEXT As Int32 = &HD
    Public Const VK_RETURN As Int32 = &HD
    Public Const WM_KEYDOWN As Int32 = &H100
    Public Const WM_KEYUP As Int32 = &H101

    Public Const TextBoxParentClass As String = "#32770"
    Public Const TextBoxClass As String = "RichEdit20A"
    Public Const TextBoxIndex As Int32 = 2

    Public Const GroupName As String = "MyCoolGroup - Voice Room"
    Public Const GroupClass As String = "My Window Class"

    Private Sub HandleGrabber_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ChatStream As OutputStream
        ChatStream = New OutputStream(GroupClass, GroupName)
        ChatStream.SendText(ChatStream.ChatHandle, "It works! (w)", "Courier New", Color.Orange, 12, FontStyle.Bold)
        Application.Exit()
    End Sub
    Public Class Window
        Public ChatRoom As Frame
        Public ChatHandle As Int32
        Sub New(ByVal WindowClass, ByVal WindowName)
            ' add the initial frame to the window tree
            ' because of recursion, this call then builds the entire tree
            ChatRoom = New Frame(FindWindow(WindowClass, WindowName))
            ChatHandle = GetSendTextHandle(ChatRoom)
        End Sub
        '  This frame objects refers to any subsection of a window, including the whole window.
        '  It includes a pointer (Branch) to each of its child frames.
        '  the child frames are sorted by class name for easier access.
        Public Class Frame
            Public Handle As Int32 = 0
            Public Name As String = Space(256)
            Public RegClass As String = Space(256)
            Public Branch As Dictionary(Of String, List(Of Frame)) = Nothing
            Sub New(ByVal FrameHandle As Int32)
                Dim NameLen, ClassLen As Int32
                Handle = FrameHandle

                NameLen = GetWindowText(Handle, Name, 255)
                ClassLen = GetClassName(Handle, RegClass, 255)

                Name = Name.Substring(0, NameLen)
                RegClass = RegClass.Substring(0, ClassLen)

                If Handle > 0 Then
                    Call AddBranch()
                End If
            End Sub

            ' gets all the frame nodes for a parent frame
            Public Sub AddBranch()
                Dim NodeHandle As Int32
                NodeHandle = GetWindow(Handle, GW_CHILD)

                Branch = New Dictionary(Of String, List(Of Frame))
                Do While NodeHandle > 0
                    AddNode(NodeHandle)
                    NodeHandle = GetWindow(NodeHandle, GW_HWNDNEXT)
                Loop
            End Sub
            'Sticks a frame into its corresponding branch
            Public Sub AddNode(ByVal NodeHandle As Int32)
                Dim FrameNode As Frame
                FrameNode = New Frame(NodeHandle)

                If Not Branch.ContainsKey(FrameNode.RegClass) Then
                    Branch.Add(FrameNode.RegClass, New List(Of Frame))
                End If
                Branch(FrameNode.RegClass).Add(FrameNode)

            End Sub
        End Class
        ' after the window tree is built, this finds the send text frame and returns its handle
        Public Shared Function GetSendTextHandle(ByVal CurrentFrame As Frame) As Int32
            Dim KVP As KeyValuePair(Of String, List(Of Frame))
            Dim F As Frame
            Dim I As Int32

            For Each KVP In CurrentFrame.Branch
                I = 0
                For Each F In CurrentFrame.Branch(KVP.Key)
                    If CurrentFrame.RegClass = TextBoxParentClass Then
                        If KVP.Key = TextBoxClass Then
                            I = I + 1
                            If I = TextBoxIndex Then
                                Return (F.Handle)
                            End If
                        End If
                    End If
                    If GetSendTextHandle > 0 Then Return (GetSendTextHandle)
                    GetSendTextHandle = GetSendTextHandle(F)
                Next F
            Next KVP

        End Function
    End Class

    Private Class OutputStream
        Public ChatRoom As Window
        Public ChatHandle As Int32
        Public RTB As RichTextBox

        Sub New(ByVal WindowClass As String, ByVal WindowName As String)
            ChatRoom = New Window(WindowClass, WindowName)
            ChatHandle = ChatRoom.ChatHandle

            RTB = New RichTextBox

            ' pull the handle to the send text box out of the tree
            If IsNothing(ChatRoom) Then
                MsgBox("Could not find an open window named: " & GroupName)
            Else
                If ChatRoom.ChatHandle = 0 Then
                    MsgBox("Could not find the text box in: " & GroupName)
                End If
            End If

        End Sub
        Public Function SendText(ByVal SendTextBox As Int32, ByVal TheText As String, ByVal FontName As String, ByVal ColorValue As System.Drawing.Color, ByVal Size As Int32, ByVal Style As System.Drawing.FontStyle)
            Dim Status

            'Paltalk will take anything greater than 12 and make it 10, so I make it 12
            If Size > 12 Then Size = 12

            RTB.SelectedText = TheText
            RTB.SelectAll()
            RTB.SelectionFont = New Font(FontName, Size, Style)
            RTB.SelectionColor = ColorValue

            Status = SendMessageByString(SendTextBox, WM_SETTEXT, Nothing, RTB.Rtf)
            If (Status > 0) Then
                Status = SendMessage(SendTextBox, WM_KEYDOWN, VK_RETURN, Nothing)
            End If

            If (Status) Then
                MsgBox("Write to chatroom failed.")
            End If

            Return (Status)
        End Function

    End Class

End Class



Create a project and then paste this code into it. Enjoy.

Andrew :)
mightythor
 
Posts: 4
Joined: Thu Jul 28, 2005 9:06 pm

Postby Johnny5 » Thu Aug 04, 2005 7:51 pm

wonder if you could do for vb.net?
Johnny5
imFiles Junior
imFiles Junior
 
Posts: 72
Joined: Wed Dec 29, 2004 7:16 pm

Postby locohacker » Mon Sep 05, 2005 1:09 pm

OMG I think this exactly what i am looking for :)

hey mightythor if u ever pass bye can u attach the file lol is tha u need to be trusted member to attach file.

now u are :)
User avatar
locohacker
Site Admin
Site Admin
 
Posts: 4364
Joined: Fri Dec 31, 2004 6:59 pm

Gettting chat handle with VB .net 2005 beta

Postby mightythor » Tue Sep 06, 2005 8:41 pm

Um, like, here it is, and stuff.
mightythor
 
Posts: 4
Joined: Thu Jul 28, 2005 9:06 pm

Postby locohacker » Thu Sep 08, 2005 8:45 am

Perfect. thanks a lot this is great work :)
User avatar
locohacker
Site Admin
Site Admin
 
Posts: 4364
Joined: Fri Dec 31, 2004 6:59 pm

Postby method » Fri Nov 11, 2005 6:39 pm

could i run this project in visual studio 2003 ? By the way what does this code ? is it a new paltalk ?Thanks
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am


Return to Visual Basic Programming

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 0 guests