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
| Option Explicit
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, _
ByVal Hwnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal Hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Const GWL_WNDPROC = -4
Private Const WM_SIZE = &H5
Private Const WM_PAINT = &HF
Private LngPrevWndProc As Long
Private IsHooked As Boolean
Private HookedHWND As Long
Public Sub Hook(Hwnd As Long)
'Mise en place du hook s'il n'est pas déjà actif
If IsHooked = False Then
HookedHWND = Hwnd
LngPrevWndProc = SetWindowLong(HookedHWND, GWL_WNDPROC, AddressOf WindowProc)
IsHooked = True
End If
End Sub
Public Sub Unhook()
'Suppression du hook s'il est actif
Dim LngTemp As Long
If IsHooked = True Then
LngTemp = SetWindowLong(HookedHWND, GWL_WNDPROC, LngPrevWndProc)
IsHooked = False
End If
End Sub
Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
WindowProc = CallWindowProc(LngPrevWndProc, hw, uMsg, wParam, lParam)
If uMsg = WM_SIZE Or uMsg = WM_PAINT Then
'Si les evenements Size ou paint arrive
If frmMain.TextSaisie.Visible = True Then
'Si la textbox est visible donc en mode édition...
If (frmMain.TextSaisie.Left <> frmMain.MSFlexGrid1.CellLeft + frmMain.MSFlexGrid1.Left) Or _
(frmMain.TextSaisie.Top <> frmMain.MSFlexGrid1.CellTop + frmMain.MSFlexGrid1.Top) Then
'Si la cellule active c'est déplacée par rapport au texte à éditer
'Remise en place
frmMain.CheckTexte
End If
frmMain.TextSaisie.Width = frmMain.MSFlexGrid1.CellWidth
End If
End If
End Function |
Partager