Bonjour

1 --------------------------------------------------------------------
je cherche le code qui permet d'indiquer :
- la ligne
- la colonne
(- et meme le caratere)

en cours au fur et a mesure de la saisie dans une richtextbox ou a l'evenement mousedown de la souris
afin de l'afficher bien entendu dans la barre de statut

en fait comme visual studio fait

bon deja pour la ligne, ca doit etre quelque chose comme cela mais quest ce que je mets pour recuperer la ligne courante de la richtextbox (c un integer) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
Dim nligne As Integer = RichTextBox1.GetLineFromCharIndex(...)
2 --------------------------------------------------------------------
a pi tiens pendant que jy suis
quelquun pourrait il m'expliquer a quoi sert exactement chaque element (description) et comment on utilise API SendMessageW pour effectuer la coloration syntaxique dans un éditeur comme visual studio ou code snippet editor (mots cles du langage)
EXEMPLES :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
 
#Region "win API"
 
 
   Private Sub SetDefaultTabStop(ByVal tabSize As Int32)
      NativeMethods.SetDefaultTabStop(tabSize, Me)
   End Sub
 
   Private Function GetText() As String
      Return NativeMethods.GetText(Me)
   End Function
 
   Private Function GetSelection() As NativeMethods.CharRange
      Return NativeMethods.GetSelection(Me)
   End Function
 
   Private Sub SetSelection(ByVal range As NativeMethods.CharRange)
      NativeMethods.SetSelection(range, Me)
   End Sub
 
   Private Class NativeMethods
 
      Private Sub New()
         ' class is Shared
      End Sub
 
      Friend Shared Sub SetDefaultTabStop(ByVal tabSize As Int32, ByVal editor As CodeEditor)
         SendMessageW(New HandleRef(editor, editor.Handle), &HCB, New IntPtr(1), tabSize * 4)
      End Sub
 
      Friend Shared Function GetText(ByVal editor As CodeEditor) As String
         Dim href As New HandleRef(editor, editor.Handle)
         Dim length As Int32 = SendMessageW(href, WM_GETTEXTLENGTH, IntPtr.Zero, 0).ToInt32 + 2
         Dim sb As New System.Text.StringBuilder(length + 2)
         SendMessageW(href, WM_GETTEXT, New IntPtr(length), sb)
         Return sb.ToString
      End Function
 
      Friend Shared Function GetSelection(ByVal editor As CodeEditor) As NativeMethods.CharRange
         Dim range As CharRange
         SendMessageW(New HandleRef(editor, editor.Handle), EM_EXGETSEL, IntPtr.Zero, range)
         Return range
      End Function
 
      Friend Shared Sub SetSelection(ByVal range As NativeMethods.CharRange, ByVal editor As CodeEditor)
         SendMessageW(New HandleRef(editor, editor.Handle), EM_EXSETSEL, IntPtr.Zero, range)
      End Sub
 
      Friend Shared Function GetOLEInterface(ByVal editor As CodeEditor) As ITextDocument
         Dim iDoc As ITextDocument = Nothing
         SendMessageW(New HandleRef(editor, editor.Handle), EM_GETOLEINTERFACE, IntPtr.Zero, iDoc)
         Return iDoc
      End Function
 
 
		'Friend Shared Function GetCurrentLine(ByVal editor As CodeEditor) As String
		'   Return GetCurrentLine(New HandleRef(editor, editor.Handle))
		'End Function
 
      Friend Shared Function GetCurrentLine(ByVal href As HandleRef) As String
         Return GetLine(href, GetCurrentLineNumber(href))
      End Function
 
		'Friend Shared Function GetLine(ByVal editor As CodeEditor, ByVal lineNumber As Int32) As String
		'   Return GetLine(New HandleRef(editor, editor.Handle), lineNumber)
		'End Function
 
      Friend Shared Function GetLine(ByVal href As HandleRef, ByVal lineNumber As Int32) As String
         Dim lineLength As Int32 = GetLineLength(href, lineNumber)
 
         If lineLength <= 0 Then Return ""
 
         Dim sb As New StringBuilder(lineLength + 2)
         sb.Append(VB.ChrW(lineLength))
         Dim rtn As Int32 = SendMessageW(href, EM_GETLINE, New IntPtr(lineNumber), sb).ToInt32
 
         Return sb.ToString(0, rtn)
 
      End Function
 
 
 
		'Friend Shared Function GetLineLength(ByVal editor As CodeEditor, ByVal lineNumber As Int32) As Int32
		'   Return GetLineLength(New HandleRef(editor, editor.Handle), lineNumber)
		'End Function
 
      Private Shared Function GetLineLength(ByVal href As HandleRef, ByVal lineNumber As Int32) As Int32
         Return SendMessageW(href, EM_LINELENGTH, New IntPtr(GetLineCharIndex(href, lineNumber)), 0).ToInt32
      End Function
 
 
		'Friend Shared Function GetCurrentLineNumber(ByVal editor As CodeEditor) As Int32
		'   Return GetCurrentLineNumber(New HandleRef(editor, editor.Handle))
		'End Function
 
      Friend Shared Function GetCurrentLineNumber(ByVal href As HandleRef) As Int32
         Return SendMessageW(href, EM_LINEFROMCHAR, New IntPtr(-1), 0).ToInt32
      End Function
 
 
		'Friend Shared Function GetLineCharIndex(ByVal editor As CodeEditor, ByVal lineNumber As Int32) As Int32
		'   Return GetLineCharIndex(New HandleRef(editor, editor.Handle), lineNumber)
		'End Function
 
      Friend Shared Function GetLineCharIndex(ByVal href As HandleRef, ByVal lineNumber As Int32) As Int32
         Return SendMessageW(href, EM_LINEINDEX, New IntPtr(lineNumber), 0).ToInt32
      End Function
 
 
 
 
      Private Declare Unicode Function SendMessageW Lib "user32" (ByVal hWnd As HandleRef, ByVal msg As Int32, ByVal wParam As IntPtr, ByRef lparam As tom.ITextDocument) As IntPtr
      Private Declare Unicode Function SendMessageW Lib "user32" (ByVal hWnd As HandleRef, ByVal msg As Int32, ByVal wParam As IntPtr, ByVal lparam As StringBuilder) As IntPtr
      Private Declare Unicode Function SendMessageW Lib "user32" (ByVal hWnd As HandleRef, ByVal msg As Int32, ByVal wParam As IntPtr, ByRef lparam As Int32) As IntPtr
      Private Declare Unicode Function SendMessageW Lib "user32" (ByVal hWnd As HandleRef, ByVal msg As Int32, ByVal wParam As IntPtr, ByRef lparam As CharRange) As IntPtr
 
 
      Private Const WM_USER As Int32 = &H400
      Private Const EM_EXGETSEL As Int32 = (WM_USER + 52)
      Private Const EM_EXSETSEL As Int32 = (WM_USER + 55)
      Private Const EM_GETOLEINTERFACE As Int32 = (WM_USER + 60)
      Private Const EM_GETLINE As Int32 = &HC4
      Private Const EM_LINEFROMCHAR As Int32 = &HC9
      Private Const EM_LINELENGTH As Int32 = &HC1
      Private Const EM_LINEINDEX As Int32 = &HBB
      Private Const EM_SETTABSTOPS As Int32 = &HCB
      Private Const WM_GETTEXT As Int32 = &HD
      Private Const WM_GETTEXTLENGTH As Int32 = &HE
 
      Friend Structure CharRange
         Public Min As Int32
         Public Max As Int32
      End Structure
 
   End Class
 
 
#End Region
------------------------------------------------------------------------
oOOoo mince il m'a semblé avoir vu dans code ce que je vous demandait au débutt loooooll (trouver position ligne courante richtextbox)
rooooo loooll

bon c'est vrai chui un peu feignant la lool mais jai po envie de chercher svp

merkii
++