From: RB Smissaert on 9 Nov 2007 16:14 Have a VB6 ActiveX dll with a form with a multiline textbox. I need to get the line number at a right mouse click and so far no success with this yet. There is no problem when I move the cursor to the right place (with for example the up or down keys) but I can't set the cursor at the position of the right mouse click. This is the code I have tried amongst many others: 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_LINEFROMCHAR = &HC9 Private Const WM_LBUTTONDOWN = &H201 Private Const WM_LBUTTONUP = &H202 Private Const WM_RBUTTONDOWN = &H204 Private Const WM_RBUTTONUP = &H205 Private Function GetCursorLine(lHwnd As Long) As Long GetCursorLine = SendMessage(lHwnd, EM_LINEFROMCHAR, -1, 0) + 1 End Function Private Sub txtPrompt_MouseDown(Index As Integer, _ Button As Integer, _ Shift As Integer, _ x As Single, _ y As Single) Dim lParam As Long If m_ReturnLineNumber Then If Button = 2 Then 'to disable the popup '----------------------- SendMessage Me.hwnd, WM_RBUTTONDOWN, 0, 0 'to place the cursor '---------------------- lParam = CInt(x / Screen.TwipsPerPixelX) Or _ (&H10000 * CInt(y / Screen.TwipsPerPixelY)) SendMessage Me.hwnd, WM_LBUTTONDOWN, 0, lParam SendMessage Me.hwnd, WM_LBUTTONUP, 0, lParam 'to get the line number '------------------------- s_RetVal = GetCursorLine(txtPrompt(0).hwnd) Me.Hide End If End If End Sub I don't get any errors, but I just can't place the cursor. Any ideas what I might be doing wrong? RBS
From: RB Smissaert on 9 Nov 2007 18:21 OK, this comes closer (had used the wrong hwnd) as it sets the cursor, but in the wrong line (always line 2) and I now get the textbox popup: Private Sub txtPrompt_MouseDown(Index As Integer, _ Button As Integer, _ Shift As Integer, _ x As Single, _ y As Single) Dim lParam As Long Dim lHwnd As Long If m_ReturnLineNumber And Button = 2 Then lHwnd = txtPrompt(0).hwnd lParam = CInt(x / Screen.TwipsPerPixelX) Or _ (&H10000 * CInt(y / Screen.TwipsPerPixelY)) SendMessage lHwnd, WM_LBUTTONDOWN, 0, lParam s_RetVal = GetCursorLine(lHwnd) Me.Hide End If End Sub RBS "RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> wrote in message news:O%23vePWxIIHA.2100(a)TK2MSFTNGP03.phx.gbl... > Have a VB6 ActiveX dll with a form with a multiline textbox. > I need to get the line number at a right mouse click and so far no success > with this yet. > There is no problem when I move the cursor to the right place (with for > example the up or down keys) > but I can't set the cursor at the position of the right mouse click. > This is the code I have tried amongst many others: > > 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_LINEFROMCHAR = &HC9 > > Private Const WM_LBUTTONDOWN = &H201 > Private Const WM_LBUTTONUP = &H202 > > Private Const WM_RBUTTONDOWN = &H204 > Private Const WM_RBUTTONUP = &H205 > > Private Function GetCursorLine(lHwnd As Long) As Long > GetCursorLine = SendMessage(lHwnd, EM_LINEFROMCHAR, -1, 0) + 1 > End Function > > Private Sub txtPrompt_MouseDown(Index As Integer, _ > Button As Integer, _ > Shift As Integer, _ > x As Single, _ > y As Single) > > Dim lParam As Long > > If m_ReturnLineNumber Then > If Button = 2 Then > > 'to disable the popup > '----------------------- > SendMessage Me.hwnd, WM_RBUTTONDOWN, 0, 0 > > 'to place the cursor > '---------------------- > lParam = CInt(x / Screen.TwipsPerPixelX) Or _ > (&H10000 * CInt(y / Screen.TwipsPerPixelY)) > > SendMessage Me.hwnd, WM_LBUTTONDOWN, 0, lParam > SendMessage Me.hwnd, WM_LBUTTONUP, 0, lParam > > 'to get the line number > '------------------------- > s_RetVal = GetCursorLine(txtPrompt(0).hwnd) > Me.Hide > End If > End If > > End Sub > > > I don't get any errors, but I just can't place the cursor. > Any ideas what I might be doing wrong? > > > RBS >
From: Vinchenzo vinç on 10 Nov 2007 14:31 "RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> escribió en el mensaje news:%23Zz$7cyIIHA.2268(a)TK2MSFTNGP02.phx.gbl... > OK, this comes closer (had used the wrong hwnd) as it sets the cursor, but > in the wrong line (always line 2) > ... > SendMessage lHwnd, WM_LBUTTONDOWN, 0, lParam Use 'PostMessage' instead of 'SendMessage'. -- Greetings - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ( ! ) Preceding answers in Google: http://groups.google.com/group/microsoft.public.vb.winapi ( i ) Temperance in the forum: http://www.microsoft.com/communities/conduct/default.mspx - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
From: RB Smissaert on 11 Nov 2007 13:57 Thanks, will give that a try. RBS "Vinchenzo vin�" <Vin�@newsgroup.nospam> wrote in message news:uQyvSB9IIHA.1620(a)TK2MSFTNGP03.phx.gbl... "RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> escribi� en el mensaje news:%23Zz$7cyIIHA.2268(a)TK2MSFTNGP02.phx.gbl... > OK, this comes closer (had used the wrong hwnd) as it sets the cursor, but > in the wrong line (always line 2) > ... > SendMessage lHwnd, WM_LBUTTONDOWN, 0, lParam Use 'PostMessage' instead of 'SendMessage'. -- Greetings - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ( ! ) Preceding answers in Google: http://groups.google.com/group/microsoft.public.vb.winapi ( i ) Temperance in the forum: http://www.microsoft.com/communities/conduct/default.mspx - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
From: RB Smissaert on 11 Nov 2007 15:55 Had a go with PostMessage, but no success. What I need is the line number (at the mouse-down position) in a multi-line textbox when that textbox gets a right-click. Has anybody done this successfully? RBS "Vinchenzo vin�" <Vin�@newsgroup.nospam> wrote in message news:uQyvSB9IIHA.1620(a)TK2MSFTNGP03.phx.gbl... "RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> escribi� en el mensaje news:%23Zz$7cyIIHA.2268(a)TK2MSFTNGP02.phx.gbl... > OK, this comes closer (had used the wrong hwnd) as it sets the cursor, but > in the wrong line (always line 2) > ... > SendMessage lHwnd, WM_LBUTTONDOWN, 0, lParam Use 'PostMessage' instead of 'SendMessage'. -- Greetings - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ( ! ) Preceding answers in Google: http://groups.google.com/group/microsoft.public.vb.winapi ( i ) Temperance in the forum: http://www.microsoft.com/communities/conduct/default.mspx - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Next
|
Last
Pages: 1 2 3 4 Prev: 5904 - Cannot Edit Range Next: [VB5+MSINET.OCX] Err 13/Type Mismatch? |