Results 1 to 6 of 6

Thread: Get text from another apps RichTextBox?

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    28

    Get text from another apps RichTextBox?

    I'm trying to make a trivia program for a chat application. I've got it working but I think it might not be the best way of doing it, and it crashes chat app occasionally. The chat app is able to keep a log of the chat window and save it to a file. At the moment, my program opens the log every second if the contents have changed, and checks each line for the correct answer to the question. I'm thinking that it crashes because both programs are trying to use the file at once, or something like that?
    So I'm going back to the original way I had in mind for checking for the corret answer, by getting the text from the RTB in the chat app. Maybe this isn't the best way of doing it either, so if you have any ideas, I'd like to hear them

    Anyway, if this is the best way to do it, here's my problem...


    I'm trying to get the text from another apps RTB using EM_GETTEXTEX.

    I looked on MSDN and this is the structure for it:
    Code:
    typedef struct _gettextex {
        DWORD cb;
        DWORD flags;
        UINT codepage;
        LPCSTR lpDefaultChar;
        LPBOOL lpUsedDefChar;
    } GETTEXTEX;
    I have a feeling this isn't the correct translation to VB, so what should it be?
    Code:
    Public Type GETTEXTEX
        cb As Long
        flags As Long
        codepage As Integer
        lpDefaultChar As String
        lpUsedDefChar As Boolean
    End Type
    From here, I just get even more lost, and structures always seem to confuse me. The only part of the structure that I think I understand is flags.

    ---------------------
    ---------------------
    Fom MSDN:
    cb
    Count of bytes in the fetched string. The size of the output buffer is lParam in the EM_GETTEXTEX message.

    flags
    Value specifying a text operation. This member can be one of the following values.

    GT_DEFAULT
    No CR translation.
    GT_SELECTION
    Retrieves the text for the current selection.
    GT_USECRLF
    Indicates that when copying text, each CR should be translated into a CRLF.

    codepage
    Code page used in the translation. It is CP_ACP for ANSI Code Page and 1200 for Unicode.

    lpDefaultChar
    Points to the character used if a wide character cannot be represented in the specified code page. It is used only if the code page is not 1200 (Unicode). If this member is NULL, a system default value is used.

    lpUsedDefChar
    Points to a flag that indicates whether a default character was used. It is used only if the code page is not 1200 (Unicode). The flag is set to TRUE if one or more wide characters in the source string cannot be represented in the specified code page. Otherwise, the flag is set to FALSE. This member may be NULL.

    ---------------------
    ---------------------

    I tried having a go at it anyway, but managed to crash the program I was trying to get the text from.
    Code:
    'Module
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
    
    Public Type GETTEXTEX
        cb As Long
        flags As Long
        codepage As Integer
        lpDefaultChar As String
        lpUsedDefChar As Boolean
    End Type
    
    Public Const GT_USECRLF = 1&
    Public Const WM_USER As Long = &H400
    Public Const EM_GETTEXTEX As Long = (WM_USER + 94)
    
    '============================
    '============================
    
    'Form1
    Dim Str1 As String
    Private Sub Command1_Click()
    Str1 = Space(20)
    GetChatHwnds
    SendMessage ChatWindow, EM_GETTEXTEX, GETTEXTEX, Str1
    Text1.Text = Str1
    End Sub

    I realise I should probaby use GETTEXTLENGTHEX for the text length, but I thought I'd try and understand this first.

    I haven't been able to find an example of this to see how it's done, so does anyone have an example they could share?

    I've done most of the code for the rest of the trivia program and would hate to abandon it just because I can't figure this part out.

    Thanks for any help with this
    Last edited by Boka; Oct 3rd, 2003 at 02:18 PM.

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