L
Lee Weiner
I'm a VB6 guy playing around with VB.NET. Trying to convert one of my old VB6
projects, a plain old text editor. A problem I'm having is using the
SendMessage API function to retrieve the line in the textbox the insertion
cursor is on. I have the following declarations:
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Const EM_LINEFROMCHAR = &HC9
Const EM_LINEINDEX = &HBB
In VB6, the first parameter is a Long, but in .NET, the Handle property is an
IntPtr, so I changed the declaration. I'm not sure that was the right thing to
do. I suppose there might be a way to cast an IntPtr as a Long but I couldn't
figure out how.
These two lines of code:
line = SendMessage(txtEditor.Handle, EM_LINEFROMCHAR, _
txtEditor.SelectionStart, 0)
col = SendMessage(txtEditor.Handle, EM_LINEINDEX, line, 0)
both return 0 no matter what the actual cursor position in the textbox is.
The first call should return the actual line in the textbox the cursor is on.
The second should return the index of the first character on the line
specified.
Can someone tell me what I'm doing wrong or if there's a new .NET way of
accomplishing the same task?
Lee Weiner
projects, a plain old text editor. A problem I'm having is using the
SendMessage API function to retrieve the line in the textbox the insertion
cursor is on. I have the following declarations:
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Const EM_LINEFROMCHAR = &HC9
Const EM_LINEINDEX = &HBB
In VB6, the first parameter is a Long, but in .NET, the Handle property is an
IntPtr, so I changed the declaration. I'm not sure that was the right thing to
do. I suppose there might be a way to cast an IntPtr as a Long but I couldn't
figure out how.
These two lines of code:
line = SendMessage(txtEditor.Handle, EM_LINEFROMCHAR, _
txtEditor.SelectionStart, 0)
col = SendMessage(txtEditor.Handle, EM_LINEINDEX, line, 0)
both return 0 no matter what the actual cursor position in the textbox is.
The first call should return the actual line in the textbox the cursor is on.
The second should return the index of the first character on the line
specified.
Can someone tell me what I'm doing wrong or if there's a new .NET way of
accomplishing the same task?
Lee Weiner