Sending text to pal without clearing current text by Chike : Visual Basic Programming

Sending text to pal without clearing current text by Chike

You can talk about VB programming here

Moderators: Chike, Departure

Sending text to pal without clearing current text by Chike

Postby autopilot » Thu Jun 14, 2007 5:26 pm


This is thanks to Chike:

To get the current typed text use the following:
Code: Select all
   
    'disable editing, may not be needed
    Call EnableWindow(RichEdit20AHnd, 0)
    'Copy Text that has been typed in if any
    txt_len& = SendMessage(RichEdit20AHnd, WM_GETTEXTLENGTH, 0, 0)
    If txt_len& > 0 Then ' don't need all this if user not typing
        ' save user selection / cursor position
        Call SendMessage(RichEdit20AHnd, EM_GETSEL, ByVal VarPtr(start_pos&), ByVal VarPtr(end_pos&))
        ' select all text and cut
        res = SendMessage(RichEdit20AHnd, EM_SETSEL, 0, ByVal txt_len&)
        res = SendMessage(RichEdit20AHnd, WM_CUT, 0, 0)
    End If

Insert your code to send text to pal room... May look like the following:
Code: Select all
    'Send Text to room
    Call SendMessageByString(RichEdit20AHnd, WM_SETTEXT, 0&, Text1.Text)
    Call SendMessage(RichEdit20AHnd, WM_KEYDOWN, 13, 0)

Then restore the user text with the following:
Code: Select all
    'Send any typing back to box
    If txt_len& > 0 Then
        ' text box is empty, paste saved text
        res& = SendMessage(RichEdit20AHnd, WM_PASTE, 0, 0)
        ' restore selection / cursor position
        res& = SendMessage(RichEdit20AHnd, EM_SETSEL, start_pos&, ByVal end_pos&)
    End If
    'enable editing
    Call EnableWindow(RichEdit20AHnd, 1)


Again Thank you Chike
Last edited by autopilot on Tue Jul 31, 2007 2:49 am, edited 1 time in total.
User avatar
autopilot
Forum Moderator
Forum Moderator
 
Posts: 333
Joined: Sun Sep 24, 2006 12:19 am

Postby Departure » Tue Jul 31, 2007 1:09 am

yes very good, After a few little modifycations to the code it works perfect, thank you and i'll proberly use this in any new programs I do..
User avatar
Departure
Global Moderator
Global Moderator
 
Posts: 983
Joined: Thu Mar 17, 2005 4:26 pm
Location: Australia

Re: Sending text to pal without clearing current text by Chike

Postby jimmyng » Mon Oct 01, 2007 12:12 pm

cannot get it wok
child = FindWindowEx(parent, 0, "WTL_SplitterWindow", vbNullString)
child = FindWindowEx(child, 0, "WTL_SplitterWindow", vbNullString)
child = FindWindowEx(child, 0, "WTL_SplitterWindow", vbNullString)
child = FindWindowEx(child, 0, "WTL_SplitterWindow", vbNullString)

alt = GetWindow(child, GW_Child)

alt = GetWindow(alt, GW_HWNDNEXT)

alt = FindWindowEx(alt, 0, "AtlAxWin71", vbNullString)
alt = FindWindowEx(alt, 0, "#32770", vbNullString)

rich20 = FindWindowEx(alt, 0, "RichEdit20A", vbNullString)
rich20 = FindWindowEx(alt, rich20, "RichEdit20A", vbNullString)


Call SendMessageSTRING(rich20, WM_SETTEXT, 0&, Text$)
Call SendMessageLong(rich20, WM_KEYDOWN, 13, 0&)


please help
jimmyng
imFiles Newbie
imFiles Newbie
 
Posts: 23
Joined: Sun Feb 12, 2006 9:41 pm

Re: Sending text to pal without clearing current text by Chike

Postby Chike » Mon Oct 01, 2007 7:28 pm

Sould be simple. However depending on how SendMessage is defined it may require some changes, and of course you need to define EnableWindow and maybe some other constants.
Chike
imFiles Master
imFiles Master
 
Posts: 525
Joined: Sun May 13, 2007 11:20 pm

Re: Sending text to pal without clearing current text by Chike

Postby NVYE » Mon Sep 22, 2008 2:05 am

Very nice ... thanks ... works like charm !
Add-on Bots for educational and amusement purposes:
http://www.vipbots.com
User avatar
NVYE
imFiles Senior
imFiles Senior
 
Posts: 207
Joined: Sat Jun 11, 2005 4:29 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