Skip to content
Home > Programming > Paltalk 9 WINAPI (API) Examples

Paltalk 9 WINAPI (API) Examples

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #191228
    codemastr_
    Member

    Here are some examples for people that want to write programs in C/C++

    Make sure iostream and windows.h are always included by trying any of these examples

    #include
    #include

    Getting Text (Last Line Written)

    int main() {
    HWND mywindowclass = FindWindow("DlgGroupChat Window Class", NULL);
    HWND wtlsplitterwindow = FindWindowEx(mywindowclass, 0, "wtl_splitterwindow", NULL);
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0, "wtl_splitterwindow", NULL);
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0, "wtl_splitterwindow", NULL);
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0, "wtl_splitterwindow", NULL);
    HWND atlfe = GetWindow(wtlsplitterwindow, GW_CHILD);
    HWND atlaxwin = FindWindowEx(atlfe, 0, "atlaxwin71", NULL);
    atlaxwin = FindWindowEx(atlfe, atlaxwin, "atlaxwin71", NULL);
    HWND x = FindWindowEx(atlaxwin, 0, "#32770", NULL);
    HWND richedita = FindWindowEx(x, 0, "richedit20a", NULL);
    
    // Error Checking:
    if (!mywindowclass) { printf( "E_WINDOW_NOT_FOUND"); }
    if (!wtlsplitterwindow) { printf( "E_WINDOW_NOT_FOUND"); }
    if (!atlfe) { printf( "E_UNABLE_TO_FIND_PARENT"); }
    if (!richedita) { printf( "E_RICHEDIT_NOT_FOUND"); }
    
    long lngCount = SendMessage(richedita, EM_GETLINECOUNT, 0, 0);
    long lngLength = SendMessage(richedita, EM_LINELENGTH, lngCount-2, 0);
    TCHAR strBuffer[1024]; *(WORD *) strBuffer = 1024;
    LRESULT bla = SendMessage(richedita, EM_GETLINE, lngCount-2, (LPARAM)(LPCSTR)strBuffer);
    printf(" Text: %s nn", strBuffer);
    
    system("pause"); // Testing blah
    
    return 0;
    }

    Sending Text

    int main() {
    HWND parent = FindWindow("DlgGroupChat Window Class", NULL);
    HWND child = FindWindowEx(parent, 0, "WTL_SplitterWindow", NULL);
    child = FindWindowEx(child, 0, "WTL_SplitterWindow", NULL);
    child = FindWindowEx(child, 0, "WTL_SplitterWindow", NULL);
    child = FindWindowEx(child, 0, "WTL_SplitterWindow", NULL);
    HWND alt = GetWindow(child, GW_CHILD);
    alt = FindWindowEx(alt, 0, "AtlAxWin71", NULL);
    alt = FindWindowEx(alt, 0, "#32770", NULL);
    HWND rich20 = FindWindowEx(alt, 0, "RichEdit20A", NULL);
    rich20 = FindWindowEx(alt, rich20, "RichEdit20A", NULL);
    TCHAR mytext[25] = "Hello World!";
    
    SendMessage(rich20, WM_SETTEXT, strlen(mytext), (LRESULT)(LPCSTR)mytext);
    SendMessage(rich20, WM_KEYDOWN, 13, 0);
    printf("Text: %s -- has been sent", mytext);
    return 3;
    }

     

    Lock Microphone

    int main() {
    HWND dlggroupchatwindowclass = FindWindow("dlggroupchat window class", NULL);
    PostMessage(dlggroupchatwindowclass, WM_COMMAND, 33340, 0);
    return 0;
    }

    Free Microphone

    int main() {
    HWND dlggroupchatwindowclass = FindWindow("dlggroupchat window class", NULL);
    PostMessage(dlggroupchatwindowclass, WM_COMMAND, 33343, 0);
    return 0;
    }

    Raise Hand

    int main() {
    HWND dlggroupchatwindowclass = FindWindow("dlggroupchat window class", NULL);
    PostMessage(dlggroupchatwindowclass, WM_COMMAND, 901, 0);
    return 0;
    }

    Sincerely, Haso Keric.

    #191241
    nice_fox102
    Member

    usefull. thanks a lot code mastr.

    #191240
    SassyJasmine
    Member

    This is exactly what I am looking for but in C#, Does anyone know how to do this in C# please help me.

    #191239

    google it on google.com, and if one week passed, you still stick with this problem, I will help you. I love the play with new comer:)

    #191238
    SassyJasmine
    Member

    I have been trying to figure it out for about 2 weeks now. Please help me.

    #191237
    public static string GetRichTextLine(IntPtr richedita)
    {
    int nblines = SendMessage(richedita, EM_GETLINECOUNT, 0, 0);
    int linelength = SendMessage(richedita, EM_LINELENGTH, nblines - 2, 0);
    
    IntPtr lpLocalBuffer = IntPtr.Zero;
    lpLocalBuffer = Marshal.AllocHGlobal(linelength+ 1);
    SendMessage(richedita, EM_GETLINE, nblines - 2, lpLocalBuffer);
    string retval = Marshal.PtrToStringAnsi(lpLocalBuffer);
    if (lpLocalBuffer != IntPtr.Zero)
    Marshal.FreeHGlobal(lpLocalBuffer);
    
    return retval;
    
    }

    or turn on your project to accept unsafe code to use this unsafe function

    public static unsafe string GetRichTextLine(IntPtr handle, uint line)
    {
    int i = 0;
    int linelength = SendMessage(handle, EM_LINELENGTH,(int) line, 0);
    byte[] buffer = new byte[linelength + 1];
    buffer[1] = 1;
    fixed (byte* ptr = buffer)
    {
    
    i = SendMessage(handle, EM_GETLINE, line, (void*)ptr);
    }
    
    if (i == 0)
    return null;
    ASCIIEncoding ae = new ASCIIEncoding();
    buffer[linelength] =13;
    
    string s = ae.GetString(buffer);
    buffer = null;
    ae = null;
    return s;
    
    }

    remember use unsafe function must import api win32 as unsafe like this

    [DllImport("user32.dll")]
    static extern unsafe int SendMessage(IntPtr hWndControl, uint msg, uint wParam, void* lParam);

    now you have 2 methods to get the last line of pt text chat
    but I have an other method; I dont like this third method but I will show you also

    static string GetWindowText(IntPtr hwnd)
    {
    int lgText = SendMessage(hwnd, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero) + 1;
    #if STRING
    string sbTitle = new string('0',lgText);
    #else
    StringBuilder sbTitle = new StringBuilder(lgText);
    #endif
    SendMessage(hwnd, WM_GETTEXT, (IntPtr)lgText, sbTitle);
    return sbTitle.ToString();
    }

    with this you get all the text and use split function to split like this

    String s=GetWindowText( hRich);
    String[] s2=s.split('n');
    String lastline=s2[s2.length-2);
    #191236
    SassyJasmine
    Member

    I can’t seem to get any of this working, I am very new to C~ please could you post a working example. Pleaseee

    #191235
    Jesus
    Member

    I tell you what SassyJasmine, You can’t get any to work because they people just Copy + Paste and these codes are simply faulty ;).

    #191234

    @Jesus wrote:

    I tell you what SassyJasmine, You can’t get any to work because they people just Copy + Paste and these codes are simply faulty ;).

    I wont code it for you, just show u the way. try to do a search yourself on how to interop unmanaged function with managed project. Man when I code it, no one show me a hint like that, so you are lucky than me

    #191233
    SassyJasmine
    Member

    Ive known how to do it i just havent been able to. The code you have shown me doesn’t show me anything new. Please help me!

    #191232
    Jesus
    Member

    Glactica I think u r the silliest girl or guy on earth lol
    I said ur a leecher a copy+paster
    i didn’t say code it for me, what u call coding up there is the same as me shitting on a bowl

    #191231

    ok I will show the the step by step to get the last line of richtext control pt room

    first import some api const and function.

    to able to use this function

    public static string GetRichTextLine(IntPtr richedita)
    {
    int nblines = SendMessage(richedita, EM_GETLINECOUNT, 0, 0);
    int linelength = SendMessage(richedita, EM_LINELENGTH, nblines - 2, 0);
    
    IntPtr lpLocalBuffer = IntPtr.Zero;
    lpLocalBuffer = Marshal.AllocHGlobal(linelength+ 1);
    SendMessage(richedita, EM_GETLINE, nblines - 2, lpLocalBuffer);
    string retval = Marshal.PtrToStringAnsi(lpLocalBuffer);
    if (lpLocalBuffer != IntPtr.Zero)
    Marshal.FreeHGlobal(lpLocalBuffer);
    
    return retval;
    
    }

     

    before your form1 class; you will see some code using System; …ect
    after right there you have to do this

    using System.Runtime.InteropServices;

    and in your form1 class public declaration import some api like this

    public const int EM_GETLINE = 196;
    public const int EM_GETLINECOUNT = 186;
    public const int EM_LINELENGTH = 193;
    [DllImport("user32.dll", EntryPoint = "SendMessage")]
    public static extern int SendMessage(
    IntPtr hwnd, int wMsg, int wParam, int lParam);
    
    [DllImport("user32.dll", EntryPoint = "SendMessage")]
    public static extern int SendMessage(IntPtr hwnd, int Msg, int wParam, IntPtr lParam);

     

    #191230

    here is class I use to deal with paltalk, notice some win32 api are there for nothing( for future purpose)

    learn this class, almost what you need.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Threading;
    namespace Win32ForPaltalk
    {
    public delegate void NotifyNewLine(String newText);
    class WIN32PaltalkApi
    {
    public const int SM_CXSCREEN = 0;
    public const int SM_CYSCREEN = 1;
    public const int WM_GETTEXTLENGTH = 14;
    public const int WM_GETTEXT = 13;
    public const int WM_SETTEXT = 12;
    public const int WM_KEYDOWN = 256;
    public const int WM_KEYUP = 257;
    public const int WM_CLOSE = 16;
    public const int WM_LBUTTONDOWN = 0x0201;
    public const int WM_LBUTTONUP = 0x0202;
    public const int SRCCOPY = 13369376;
    public const uint GW_CHILD = 5;
    public const uint GW_HWNDNEXT = 2;
    public const uint EM_GETLINE = 196;
    public const int EM_GETLINECOUNT = 186;
    public const int EM_LINEINDEX = 187;
    public const int EM_LINELENGTH = 193;
    public delegate bool CallBack(IntPtr handle, IntPtr param);
    [DllImport("user32.dll")]
    public static extern bool EnumWindows(CallBack cb, IntPtr param);
    
    [DllImport("user32.dll", EntryPoint = "FindWindowA")]
    public static extern IntPtr FindWindow(
    string lpClasse, string lpTitre);
    
    [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
    public static extern IntPtr FindWindowEx(
    IntPtr hwndParent, IntPtr hwndchild, string lpClasse, string lpTitre);
    
    [DllImport("user32.dll", EntryPoint = "SendMessage")]
    public static extern int SendMessage(
    IntPtr hwnd, uint wMsg, IntPtr wParam, IntPtr lParam);
    
    [DllImport("user32.dll", EntryPoint = "SendMessage")]
    public static extern int SendMessage(
    #if STRING
    IntPtr hwnd, uint wMsg, IntPtr wParam, string lParam);//lParam
    #else
    IntPtr hwnd, uint wMsg, IntPtr wParam, StringBuilder lParam);
    #endif
    
    [DllImport("user32.dll", EntryPoint = "SendMessage")]
    public static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, StringBuilder lParam);//lParam
    
    [DllImport("user32.dll", EntryPoint = "SendMessage")]
    public static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, IntPtr lParam);//lParam
    
    [DllImport("user32.dll", EntryPoint = "PostMessage")]
    public static extern int PostMessage(IntPtr hWnd, IntPtr uMsg, IntPtr wParam, IntPtr lParam);
    
    static string GetWindowText(IntPtr hwnd)
    {
    int lgText = SendMessage(hwnd, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero) + 1;
    #if STRING
    string sbTitle = new string('0',lgText);
    #else
    StringBuilder sbTitle = new StringBuilder(lgText);
    #endif
    SendMessage(hwnd, WM_GETTEXT, (IntPtr)lgText, sbTitle);
    return sbTitle.ToString();
    
    }
    [DllImport("user32.dll", EntryPoint = "SendMessage")]
    public static extern int SendMessage(
    IntPtr hwnd, uint wMsg, int wParam, int lParam);
    
    [DllImport("user32.dll", EntryPoint = "FindWindow")]
    public static extern int FindWindowA(
    string lpClasse, string lpTitre);
    [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
    public static extern int FindWindowEx(
    int hwndParent, int hwndEnfant, string lpClasse, string lpTitre);
    [DllImport("user32.dll", EntryPoint = "SendMessage")]
    public static extern int SendMessage(
    int hwnd, uint wMsg, int wParam, int lParam);
    
    [DllImport("user32.dll", EntryPoint = "GetWindow")]
    public static extern IntPtr GetWindow(
    IntPtr hwnd, uint uCmd);
    
    [DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
    public static extern IntPtr GetDesktopWindow();
    
    [DllImport("user32.dll", EntryPoint = "GetDC")]
    public static extern IntPtr GetDC(IntPtr ptr);
    
    [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
    public static extern int GetSystemMetrics(int abc);
    
    [DllImport("user32.dll", EntryPoint = "GetWindowDC")]
    public static extern IntPtr GetWindowDC(Int32 ptr);
    
    [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
    public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
    
    [DllImport("gdi32.dll",EntryPoint="DeleteDC")]
    public static extern IntPtr DeleteDC(IntPtr hDc);
    
    [DllImport("gdi32.dll",EntryPoint="DeleteObject")]
    public static extern IntPtr DeleteObject(IntPtr hDc);
    
    [DllImport("gdi32.dll",EntryPoint="BitBlt")]
    public static extern bool BitBlt(IntPtr hdcDest,int xDest,int yDest,int wDest,int hDest,IntPtr hdcSource,int xSrc,int ySrc,int RasterOp);
    
    [DllImport ("gdi32.dll",EntryPoint="CreateCompatibleBitmap")]
    public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
    
    [DllImport ("gdi32.dll",EntryPoint="CreateCompatibleDC")]
    public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
    
    [DllImport("gdi32.dll", EntryPoint = "SelectObject")]
    public static extern IntPtr SelectObject(IntPtr hdc, IntPtr bmp);
    
    //[DllImport("user32.dll")]
    //static extern unsafe int SendMessage(IntPtr hWndControl, uint msg, uint wParam, void* lParam);
    
    public const int LVM_GETITEM = 0x1005;
    public const int LVM_SETITEM = 0x1006;
    public const int LVIF_TEXT = 0x0001;
    public const uint PROCESS_ALL_ACCESS = (uint)(0x000F0000L | 0x00100000L | 0xFFF);
    public const uint MEM_COMMIT = 0x1000;
    public const uint MEM_RELEASE = 0x8000;
    public const uint PAGE_READWRITE = 0x04;
    public const int LVM_FIRST = 0x1000;
    public const int LVM_GETITEMCOUNT = LVM_FIRST + 4;
    public const int LVIF_STATE = 0x0008;
    public const int LVIS_SELECTED = 0x0002;
    public const int LVIS_FOCUSED = 0x0001;
    public const int LVM_SETITEMSTATE = LVM_FIRST + 43;
    public const int LVM_GETNEXTITEM = LVM_FIRST + 12;
    public const int LVIF_IMAGE = 0x002;
    
    [DllImport("user32.dll")]
    static extern int SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, IntPtr lParam);
    [DllImport("user32.dll", EntryPoint = "SendMessage")]
    static extern int SendMessageLong(IntPtr hWnd, Int32 msg, Int32 wParam, IntPtr lParam);
    
    [DllImport("user32")]
    static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out int lpwdProcessID);
    
    [DllImport("kernel32")]
    static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle,
    int dwProcessId);
    
    [DllImport("kernel32")]
    static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress,
    int dwSize, uint flAllocationType, uint flProtect);
    
    [DllImport("kernel32")]
    static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize,
    uint dwFreeType);
    
    [DllImport("kernel32")]
    static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,
    ref LV_ITEM buffer, int dwSize, IntPtr lpNumberOfBytesWritten);
    
    [DllImport("kernel32")]
    static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,
    ref string buffer, int dwSize, IntPtr lpNumberOfBytesWritten);
    
    [DllImport("kernel32")]
    static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,
    IntPtr buffer, int dwSize, IntPtr lpNumberOfBytesWritten);
    
    [DllImport("kernel32")]
    static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,
    IntPtr lpBuffer, int dwSize, IntPtr lpNumberOfBytesRead);
    [DllImport("kernel32")]
    static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,
    ref IntPtr lpBuffer, int dwSize, IntPtr lpNumberOfBytesRead);
    [DllImport("kernel32")]
    static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,
    ref LV_ITEM lpBuffer, int dwSize, IntPtr lpNumberOfBytesRead);
    
    [DllImport("kernel32")]
    static extern bool CloseHandle(IntPtr hObject);
    
    [StructLayout(LayoutKind.Sequential)]
    public struct LV_ITEM
    {
    public uint mask;
    public int iItem;
    public int iSubItem;
    public uint state;
    public uint stateMask;
    public IntPtr pszText;
    public int cchTextMax;
    public int iImage;
    }
    
    static int tosave;
    static string patern = "Create your own Away";
    private String room;
    private String oldLine;
    public volatile bool stop;
    public volatile bool useFirstMethod;
    static IntPtr hWndFound;
    ///
    /// ////////////////////////////
    ///
    
    ///
    public NotifyNewLine eventNewLine;
    ////////////////////////////
    
    public static void SetMessAWay(string msg)
    {
    
    IntPtr hRoom = FindWindow("SEINFELD_SUPERMAN", null);
    PostMessage(hRoom, (IntPtr)0x0111, (IntPtr)33286, IntPtr.Zero);
    Thread.Sleep(100);
    EnumWindows(EnumWindowsProc, IntPtr.Zero);
    IntPtr hAway = hWndFound;
    IntPtr hCombo = FindWindowEx(hAway, IntPtr.Zero, "ComboBox", null);
    IntPtr hEdit = FindWindowEx(hCombo, IntPtr.Zero, "Edit", null);
    StringBuilder sb = new StringBuilder(msg);
    SendMessage(hEdit, WM_SETTEXT, IntPtr.Zero, sb);
    
    IntPtr hSave = FindWindowEx(hAway, IntPtr.Zero, "Button", "Save");
    
    tosave = FindWindowEx(hAway.ToInt32(), 0, "Button", "Save");
    Thread.Sleep(100);
    
    SendMessage(tosave, WM_LBUTTONDOWN, 0, 0);
    SendMessage(tosave, WM_LBUTTONUP, 0, 0);
    
    }
    private static bool EnumWindowsProc(IntPtr hWnd, IntPtr param)
    {
    string tmp = GetWindowText(hWnd);
    if (tmp.IndexOf(patern) > -1)
    {
    hWndFound = hWnd;
    
    return false;
    }
    return true;
    }
    
    public static void sendPalx(string text,String room)
    {
    try
    {
    
    IntPtr hRich=GetRichHandle(room,true);
    StringBuilder sb = new StringBuilder(text);
    SendMessage(hRich, WM_SETTEXT, IntPtr.Zero, sb);
    SendMessage(hRich, WM_KEYDOWN, 13, 0);
    }
    catch (Exception ex)
    { }
    
    }
    public static IntPtr GetRichHandle(String room, bool hRich2Send)
    {
    int mywindowclass, wtlsplitterwindow, atlfe, atlaxwin, X, richedita;
    mywindowclass = FindWindowA("DlgGroupChat Window Class", room);
    if (hRich2Send == true)
    {
    wtlsplitterwindow = FindWindowEx(mywindowclass, 0, "wtl_splitterwindow", null);
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0, "wtl_splitterwindow", null);
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0, "wtl_splitterwindow", null);
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0, "wtl_splitterwindow", null);
    atlfe = (int)GetWindow(new IntPtr(wtlsplitterwindow), GW_CHILD);
    atlaxwin = FindWindowEx(atlfe, 0, "atlaxwin71", null);
    
    X = FindWindowEx(atlaxwin, 0, "#32770", null);
    richedita = FindWindowEx(X, 0, "richedit20a", null);
    richedita = FindWindowEx(X, richedita, "richedit20a", null);
    return new IntPtr(richedita);
    }
    else
    {
    wtlsplitterwindow = FindWindowEx(mywindowclass, 0, "wtl_splitterwindow", null);
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0, "wtl_splitterwindow", null);
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0, "wtl_splitterwindow", null);
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0, "wtl_splitterwindow", null);
    atlfe = (int)GetWindow(new IntPtr(wtlsplitterwindow), GW_CHILD);
    atlaxwin = FindWindowEx(atlfe, 0, "atlaxwin71", null);
    atlaxwin = FindWindowEx(atlfe, atlaxwin, "atlaxwin71", null);
    X = FindWindowEx(atlaxwin, 0, "#32770", null);
    richedita = FindWindowEx(X, 0, "richedit20a", null);
    return new IntPtr(richedita);
    
    }
    
    }
    public static void sendPalx(IntPtr richedita, string text)
    {
    try
    {
    
    StringBuilder sb = new StringBuilder(text);
    SendMessage((IntPtr)richedita, WM_SETTEXT, IntPtr.Zero, sb);
    SendMessage(richedita, WM_KEYDOWN, 13, 0);
    }
    catch (Exception ex)
    { }
    
    }
    
    public static string GetPaltalkText(String room)
    {
    
    IntPtr richedita= GetRichHandle(room, false);
    return GetWindowText(richedita);
    }
    //public static unsafe string GetRichTextLine(IntPtr handle, uint line)
    //{
    // int i = 0;
    // int linelength = SendMessage(handle, EM_LINELENGTH,(int) line, 0);
    // byte[] buffer = new byte[linelength + 1];
    // buffer[1] = 1;
    // fixed (byte* ptr = buffer)
    // {
    
    // i = SendMessage(handle, EM_GETLINE, line, (void*)ptr);
    // }
    
    // if (i == 0)
    // return null;
    // ASCIIEncoding ae = new ASCIIEncoding();
    // buffer[linelength] =13;
    
    // string s = ae.GetString(buffer);
    // buffer = null;
    // ae = null;
    // return s;
    
    //}
    public static string GetRichTextLine(IntPtr richedita)
    {
    int nblines = SendMessage(richedita, EM_GETLINECOUNT, 0, 0);
    int linelength = SendMessage(richedita, EM_LINELENGTH, nblines - 2, 0);
    
    IntPtr lpLocalBuffer = IntPtr.Zero;
    lpLocalBuffer = Marshal.AllocHGlobal(linelength+ 1);
    SendMessage(richedita, EM_GETLINE, nblines - 2, lpLocalBuffer);
    string retval = Marshal.PtrToStringAnsi(lpLocalBuffer);
    if (lpLocalBuffer != IntPtr.Zero)
    Marshal.FreeHGlobal(lpLocalBuffer);
    
    return retval;
    
    }
    public static string GetPaltalkText(String room, bool lastlineonly)
    {
    IntPtr richedita = GetRichHandle(room, false);
    //if (lastlineonly == true)
    //{
    return GetRichTextLine(richedita);
    //}
    //else
    //{
    
    // int nblines = SendMessage(richedita, EM_GETLINECOUNT, 0, 0);
    // int linelength = SendMessage(richedita, EM_LINELENGTH, nblines - 2, 0);
    // string s = GetRichTextLine(richedita, (uint)nblines - 2);
    // return s;
    //}
    //return null;
    
    }
    
    public static int GetLineCount(String room)
    {
    int ret = 0;
    ret = SendMessage(GetRichHandle(room, false), EM_GETLINECOUNT, 0, 0);
    return ret;
    
    }
    public static String GetPaltalkRoomName()
    {
    IntPtr mywindowclass = FindWindow("DlgGroupChat Window Class", null);
    return GetWindowText(mywindowclass);
    
    }
    public WIN32PaltalkApi()
    {
    
    }
    public WIN32PaltalkApi(String room)
    {
    this.room = room;
    this.useFirstMethod = false;
    Thread t = new Thread(new ParameterizedThreadStart(GetTextChange));
    t.IsBackground = true;
    t.Start(null);
    
    }
    private void GetTextChange(object obj)
    {
    //bool lastlineonly = (bool)obj;
    while (stop==false)
    {
    if (this.useFirstMethod == true)
    {
    String curLine = GetPaltalkText(this.room, this.useFirstMethod);
    if (oldLine != curLine)
    {
    try
    {
    if (curLine != null)
    {
    eventNewLine(curLine);
    oldLine = curLine;
    }
    
    }
    catch (Exception ex)
    {
    
    }
    
    }
    }
    else
    {
    String text = GetPaltalkText(this.room);
    String[] s2 = text.Split('n');
    if (s2.Length > 2)
    {
    try
    {
    String curLine = s2[s2.Length - 2];
    if (oldLine != curLine)
    {
    eventNewLine(curLine);
    oldLine = curLine;
    
    }
    }
    catch (Exception ex)
    {
    
    }
    }
    }
    Thread.Sleep(100);
    }
    
    }
    public static string ReadListViewItem(IntPtr hWnd, int item)
    {
    const int dwBufferSize = 1024;
    
    int dwProcessID;
    LV_ITEM lvItem;
    string retval;
    bool bSuccess;
    IntPtr hProcess = IntPtr.Zero;
    IntPtr lpRemoteBuffer = IntPtr.Zero;
    IntPtr lpLocalBuffer = IntPtr.Zero;
    IntPtr threadId = IntPtr.Zero;
    
    try
    {
    lvItem = new LV_ITEM();
    lpLocalBuffer = Marshal.AllocHGlobal(dwBufferSize);
    // Get the process id owning the window
    threadId = GetWindowThreadProcessId(hWnd, out dwProcessID);
    if ((threadId == IntPtr.Zero) || (dwProcessID == 0))
    throw new ArgumentException("hWnd");
    
    // Open the process with all access
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, dwProcessID);
    if (hProcess == IntPtr.Zero)
    throw new ApplicationException("Failed to access process");
    
    // Allocate a buffer in the remote process
    lpRemoteBuffer = VirtualAllocEx(hProcess, IntPtr.Zero, dwBufferSize, MEM_COMMIT,
    PAGE_READWRITE);
    if (lpRemoteBuffer == IntPtr.Zero)
    throw new SystemException("Failed to allocate memory in remote process");
    
    // Fill in the LVITEM struct, this is in your own process
    // Set the pszText member to somewhere in the remote buffer,
    // For the example I used the address imediately following the LVITEM stuct
    lvItem.mask = LVIF_TEXT;
    
    lvItem.iItem = item;
    lvItem.iSubItem = 2;
    lvItem.pszText = (IntPtr)(lpRemoteBuffer.ToInt32() + Marshal.SizeOf(typeof(LV_ITEM)));
    lvItem.cchTextMax = 50;
    
    // Copy the local LVITEM to the remote buffer
    bSuccess = WriteProcessMemory(hProcess, lpRemoteBuffer, ref lvItem,
    Marshal.SizeOf(typeof(LV_ITEM)), IntPtr.Zero);
    if (!bSuccess)
    throw new SystemException("Failed to write to process memory");
    
    // Send the message to the remote window with the address of the remote buffer
    SendMessage(hWnd, LVM_GETITEM, 0, lpRemoteBuffer);
    
    // Read the struct back from the remote process into local buffer
    bSuccess = ReadProcessMemory(hProcess, lpRemoteBuffer, lpLocalBuffer, dwBufferSize,
    IntPtr.Zero);
    if (!bSuccess)
    throw new SystemException("Failed to read from process memory");
    
    // At this point the lpLocalBuffer contains the returned LV_ITEM structure
    // the next line extracts the text from the buffer into a managed string
    retval = Marshal.PtrToStringAnsi((IntPtr)(lpLocalBuffer.ToInt32() +
    Marshal.SizeOf(typeof(LV_ITEM))));
    }
    finally
    {
    if (lpLocalBuffer != IntPtr.Zero)
    Marshal.FreeHGlobal(lpLocalBuffer);
    if (lpRemoteBuffer != IntPtr.Zero)
    VirtualFreeEx(hProcess, lpRemoteBuffer, 0, MEM_RELEASE);
    if (hProcess != IntPtr.Zero)
    CloseHandle(hProcess);
    }
    return retval;
    }
    public static int CheckUserStatus(IntPtr hWnd, int item)
    {
    
    int dwProcessID;
    LV_ITEM lvItem;
    int retval;
    bool bSuccess;
    IntPtr hProcess = IntPtr.Zero;
    IntPtr lpRemoteBuffer = IntPtr.Zero;
    IntPtr threadId = IntPtr.Zero;
    
    try
    {
    lvItem = new LV_ITEM();
    
    // Get the process id owning the window
    threadId = GetWindowThreadProcessId(hWnd, out dwProcessID);
    if ((threadId == IntPtr.Zero) || (dwProcessID == 0))
    throw new ArgumentException("hWnd");
    
    // Open the process with all access
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, dwProcessID);
    if (hProcess == IntPtr.Zero)
    throw new ApplicationException("Failed to access process");
    
    lvItem.mask = LVIF_IMAGE | LVIF_STATE;
    lvItem.iItem = item; //position of item
    lvItem.iSubItem = 1; //0 for webcam, 1 for hand,mic,reddot...
    lvItem.stateMask = 0xFFFF; // get all state flags
    
    // Allocate a buffer in the remote process
    lpRemoteBuffer = VirtualAllocEx(hProcess, IntPtr.Zero, Marshal.SizeOf(lvItem), MEM_COMMIT, PAGE_READWRITE);
    if (lpRemoteBuffer == IntPtr.Zero)
    throw new SystemException("Failed to allocate memory in remote process");
    
    // Copy the local LVITEM to the remote buffer
    bSuccess = WriteProcessMemory(hProcess, lpRemoteBuffer, ref lvItem,
    Marshal.SizeOf(typeof(LV_ITEM)), IntPtr.Zero);
    if (!bSuccess)
    throw new SystemException("Failed to write to process memory");
    
    // Send the message to the remote window with the address of the remote buffer
    SendMessage(hWnd, LVM_GETITEM, item, lpRemoteBuffer);
    
    // Read the struct back from the remote process into local buffer
    bSuccess = ReadProcessMemory(hProcess, lpRemoteBuffer,ref lvItem, Marshal.SizeOf(lvItem),
    IntPtr.Zero);
    if (!bSuccess)
    throw new SystemException("Failed to read from process memory");
    
    retval = lvItem.iImage;
    
    }
    finally
    {
    
    if (lpRemoteBuffer != IntPtr.Zero)
    VirtualFreeEx(hProcess, lpRemoteBuffer, 0, MEM_RELEASE);
    if (hProcess != IntPtr.Zero)
    CloseHandle(hProcess);
    }
    return retval;
    }
    public static void SelectListViewItem(IntPtr hWnd, int item)
    {
    
    int dwProcessID;
    LV_ITEM lvItem;
    
    bool bSuccess;
    IntPtr hProcess = IntPtr.Zero;
    IntPtr lpRemoteBuffer = IntPtr.Zero;
    IntPtr lpLocalBuffer = IntPtr.Zero;
    IntPtr threadId = IntPtr.Zero;
    
    try
    {
    lvItem = new LV_ITEM();
    
    // Get the process id owning the window
    threadId = GetWindowThreadProcessId(hWnd, out dwProcessID);
    if ((threadId == IntPtr.Zero) || (dwProcessID == 0))
    throw new ArgumentException("hWnd");
    
    // Open the process with all access
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, dwProcessID);
    if (hProcess == IntPtr.Zero)
    throw new ApplicationException("Failed to access process");
    
    // Allocate a buffer in the remote process
    lpRemoteBuffer = VirtualAllocEx(hProcess, IntPtr.Zero, Marshal.SizeOf(typeof(LV_ITEM)), MEM_COMMIT,
    PAGE_READWRITE);
    if (lpRemoteBuffer == IntPtr.Zero)
    throw new SystemException("Failed to allocate memory in remote process");
    
    // Fill in the LVITEM struct, this is in your own process
    // Set the pszText member to somewhere in the remote buffer,
    // For the example I used the address imediately following the LVITEM stuct
    lvItem.mask = LVIF_STATE;
    
    lvItem.state = 15;
    lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
    
    // Copy the local LVITEM to the remote buffer
    bSuccess = WriteProcessMemory(hProcess, lpRemoteBuffer, ref lvItem,
    Marshal.SizeOf(typeof(LV_ITEM)), IntPtr.Zero);
    if (!bSuccess)
    throw new SystemException("Failed to write to process memory");
    
    // Send the message to the remote window with the address of the remote buffer
    SendMessage(hWnd, LVM_SETITEMSTATE, item, lpRemoteBuffer);
    
    }
    finally
    {
    
    if (lpRemoteBuffer != IntPtr.Zero)
    VirtualFreeEx(hProcess, lpRemoteBuffer, 0, MEM_RELEASE);
    if (hProcess != IntPtr.Zero)
    CloseHandle(hProcess);
    }
    
    }
    public static IntPtr GetPaltalkRoomNickListHandle(String room)
    {
    IntPtr wtlsplitterwindow, mywindowclass, atldd, syslistview;
    
    mywindowclass = FindWindow("DlgGroupChat Window Class", room);
    wtlsplitterwindow = FindWindowEx(mywindowclass, IntPtr.Zero, "wtl_splitterwindow", null);
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, IntPtr.Zero, "wtl_splitterwindow", null);
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, IntPtr.Zero, "wtl_splitterwindow", null);
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, IntPtr.Zero, "wtl_splitterwindow", null);
    
    atldd = GetWindow(wtlsplitterwindow, WIN32PaltalkApi.GW_CHILD);
    atldd = GetWindow(atldd, WIN32PaltalkApi.GW_HWNDNEXT);
    syslistview = FindWindowEx(atldd, IntPtr.Zero, "syslistview32", null);
    return syslistview;
    
    }
    }
    }

     

    just add this class to your project and here is example to use this class

    String room = Win32ForPaltalk.WIN32PaltalkApi.GetPaltalkRoomName(); //get the active pt room name;

    Win32ForPaltalk.WIN32PaltalkApi.sendPalx(“your text”, room);

    and more… just learn that class

    #191229
    Jesus
    Member

    Okay that’s a very nice Copy+Paste but I didn’t say teach me it loooool

    Gd LucK

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.