Author | Message | Time |
---|---|---|
Tontow | I have a textbox. This textbox has text that is being streemed into it. --(several chat whispers a min.) I need to be able to click(or double click to select) on a word in that textbox and have it return that word that I clicked/selected along with the contens of the line that it is on IE: event would be eather a selection of a word OR a click on a word it would return the word + the contencs of the line it is on What would be the best way to do this??? | May 6, 2004, 4:35 PM |
Grok | TextBox has a DblClick event. Put code in that event to get the currently selected text. If your goal is instead to get the whole line, use SendMessage and a combination of EM_CHARFROMPOS, EM_FINDTEXT, EM_GETTEXTRANGE, and maybe EM_GETLINE. Oh, and you'll need EM_LINEINDEX. | May 6, 2004, 5:20 PM |
Tontow | my goal is to get both the currently seleced text and the whole line of text that the selection is on. umm, whats EM? (is it what you put inplace of the function name inorder to show me?) | May 6, 2004, 6:07 PM |
Eli_1 | No. Those are constants that you pass to SendMessage (bitwise OR?). | May 6, 2004, 6:23 PM |
Tontow | so im gessing that frmui.Text1.SelText would return selected text? (and yes, im kind of new to VB6, everyone has seen how sloppy my programming is) | May 6, 2004, 6:36 PM |
Tontow | and i would also help if someone would explan to me what SendMessage , EM_CHARFROMPOS, EM_FINDTEXT, EM_GETTEXTRANGE, EM_GETLINE are; i cant find them in the VB6 online reference. | May 6, 2004, 7:15 PM |
Eli_1 | [quote]and i would also help if someone would explan to me what SendMessage , EM_CHARFROMPOS, EM_FINDTEXT, EM_GETTEXTRANGE, EM_GETLINE are; i cant find them in the VB6 online reference. [/quote] [code] Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const EM_GETLINE = &HC4 Private Const EM_GETLINECOUNT = &HBA Private Const EM_LINEINDEX = &HBB Private Const EM_LINELENGTH = &HC1 [/code] e.g. [code] Dim Buffer as String // Store the line here Dim LineIndex as Long Dim LineLen as Long LineIndex = SendMessage(SomeRichTextBox.hwnd, EM_LINEINDEX, 0, 0) LineLen = SendMessage(SomeRichTextBox.hwnd, EM_LINELENGTH, LineIndex, 0) Buffer = Space$(LineLen) SendMessage SomeRichTextBox.hwnd, EM_GETLINE, 0, ByVal Buffer MsgBox Buffer, vbOkOnly + vbInformation [/code] This should be enough to get you started. If not, may god be with you. | May 6, 2004, 7:22 PM |
Tontow | ok, thx just wondering, what are &HC4, &HBA, &HC1 ? | May 6, 2004, 9:09 PM |
Eli_1 | They're just numbers. &H is hex donation (1 = &H01, 2 = &H02, ..., 10 = &H0A). Same with packet headers. For example, a packet with the header: [quote] FF 50 5A C9 ...[/quote] The packet ID is 0x50 (&H50). &HC4 (0xC4), &HBA (0xBA), and &HC1 (0xC1) are just the constant values that SendMessage uses to figure out what you want it to do. Example: Say your program is a soda machine... (I like soda) ;D [code] Private Const GS_COKE As Long = &HC4 Private Const GS_WATER As Long = &HC1 Private Const GS_PEPSI As Long = &HBA GetSoda GS_PEPSI '// Damn right I want a pepsi... Public Function GetSoda(ByVal SodaFlags as Long) as String If SodaFlags = &HC4 Then 'User wants a coke (eww) ElseIf SodaFlags = &HC1 Then 'User wants a water (wtf, why's he at a soda machine?) ElseIf SodaFlags = &HBA Then 'User wants a Pepsi (yeah baby...) End If End Function [/code] Those constant numbers are just what the function uses to determine what operation you need done. In this example, I want a god damn Pepsi... | May 6, 2004, 9:13 PM |
Tontow | umm, buffer is alwasy returning the frist line and LineIndex is alwasy 0 LineLen correctly returns the frist lines length this is wrong, the textbox is multiline, i need the line that has the selected word this is in the header (top or whatever its called) [code] Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const EM_GETLINE = &HC4 Private Const EM_GETLINECOUNT = &HBA Private Const EM_LINEINDEX = &HBB Private Const EM_LINELENGTH = &HC1 [/code] and this is the function (i imply a that the user has selected text with his double click) [code] Private Sub Text1_DblClick() Dim user As String user = frmui.Text1.SelText Dim Buffer As String Dim LineIndex As Long Dim LineLen As Long LineIndex = SendMessage(frmui.Text1.hwnd, EM_LINEINDEX, 0, 0) LineLen = SendMessage(frmui.Text1.hwnd, EM_LINELENGTH, LineIndex, 0) Buffer = Space$(LineLen) SendMessage frmui.Text1.hwnd, EM_GETLINE, 0, ByVal Buffer MsgBox Buffer & " l " & LineIndex & " l " & LineLen & " l " & user, vbOKOnly + vbInformation End Sub [/code] did i mention that i dont know a thing about sendmessage aside from whats in this post? | May 8, 2004, 1:00 AM |
Eli_1 | It's always returning the first line because: LineIndex = SendMessage(frmui.Text1.hwnd, EM_LINEINDEX, 0, 0) The number in bold is the line number your getting the index of. | May 8, 2004, 2:45 AM |
Tontow | im haveing troble comming up with something to find the line on wich the text is selected. Any help? | May 8, 2004, 5:49 AM |
Grok | [quote author=Tontow link=board=31;threadid=6679;start=0#msg59028 date=1083995378] im haveing troble comming up with something to find the line on wich the text is selected. Any help? [/quote] Q186271 HOWTO: Manipulate Text Box Contents The following messages are used: [color=yellow]EM_LINEFROMCHAR (&HC9)-returns the line number of the line where the cursor is positioned. Pass the cursor position with this message. [/color] EM_LINELENGTH (&HC1)-returns the length of the line where the cursor is positioned. Pass the cursor position with this message. EM_LINEINDEX (&HBB)-returns the number of characters in all the lines previous to the cursor position. Pass the results of the EM_LINEFROMCHAR message. Each line includes a carriage return and a line feed character. EM_GETLINECOUNT (&HBA)-returns the total number of lines in a multi-line text box. [color=yellow]EM_GETLINE (&HC4)-returns the text of the line where the cursor is positioned. Pass the results of the EM_LINEFROMCHAR message.[/color] | May 8, 2004, 2:43 PM |
Tontow | thx, that was one of the bigger helps in this thred | May 8, 2004, 3:02 PM |