Attribute VB_Name = "Module1" Option Explicit Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Public 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 Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public Declare Function ReleaseCapture Lib "user32" () As Long Public Declare Function GetInputState Lib "user32" () As Long Public mWndProcNext As Long Public Const GWL_WNDPROC = (-4) Public Const GWL_USERDATA = (-21) Public Const WM_RBUTTONUP = &H205 Private Const EM_SETREADONLY = &HCF Public Const BM_SETSTATE = &HF3 Public Type tagInitCommonControlsEx lngSize As Long lngICC As Long End Type Public Declare Function InitCommonControlsEx Lib "comctl32.dll" (iccex As tagInitCommonControlsEx) As Boolean Public Const ICC_USEREX_CLASSES = &H200 Public frm1 As Form1 Public Sub Main() On Error Resume Next Dim iccex As tagInitCommonControlsEx iccex.lngSize = LenB(iccex) iccex.lngICC = ICC_USEREX_CLASSES InitCommonControlsEx iccex On Error GoTo 0 Set frm1 = New Form1 Load frm1 frm1.Show End Sub Public Function SubWndProc(ByVal Wnd As Long, ByVal uMsg As Long, _ ByVal wParam As Long, ByVal lParam As Long) As Long ' This sub will redirect all messages to the WindowProc ' function in Form1. You might want to redo this. SubWndProc = Form1.WindowProc(Wnd, uMsg, wParam, lParam) End Function Public Sub SetReadOnly(ByRef ObjX As Object, ObjBool As Boolean) Dim hwndEdit As Long ' Get edit field handle hwndEdit = FindWindowEx(ObjX.hwnd, 0&, vbNullString, vbNullString) If hwndEdit <> 0 Then ' Set or remove the ReadOnly flag (ES_ReadOnly) SendMessage hwndEdit, EM_SETREADONLY, ObjBool, 0& End If End Sub