Read-Only TextBox help 
Author Message
 Read-Only TextBox help

I need to set a TextBox to read-only.  Can anyone explain why this sample
code is failing with VB5?
What are some of the conditions that might cause this API call to fail?

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd
As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long)
As Long
Const WM_USER = &H400
Const EM_SETREADONLY = (WM_USER + 31)

Private Sub Command1_Click()
    Dim RetVal As Long
    RetVal = SendMessage(Text1.hwnd, EM_SETREADONLY, True, ByVal 0&)
    If RetVal = 0 Then    ' Check the return value for error
         MsgBox "Could Not Set Text Box to Read-Only."
    End If
End Sub



Mon, 05 Jun 2000 03:00:00 GMT  
 Read-Only TextBox help

I found out the api works with Windows 95 but not NT 4.0( SP3).  I wonder
what other Windows api's work under W95 but not NT?

Quote:
>What are some of the conditions that might cause this API call to fail?

>Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd
>As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long)
>As Long
>Const WM_USER = &H400
>Const EM_SETREADONLY = (WM_USER + 31)



Mon, 05 Jun 2000 03:00:00 GMT  
 Read-Only TextBox help

Your function call is failing because you're using the 32-bit function
declaration with a 16-bit constant definition.  Change the constant definition
to:  Const EM_SETREADONLY = &HCF    and you should be OK.

Lee Weiner
weiner AT fuse DOT net


Quote:

>I need to set a TextBox to read-only.  Can anyone explain why this sample
>code is failing with VB5?
>What are some of the conditions that might cause this API call to fail?

>Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd
>As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long)
>As Long
>Const WM_USER = &H400
>Const EM_SETREADONLY = (WM_USER + 31)

>Private Sub Command1_Click()
>    Dim RetVal As Long
>    RetVal = SendMessage(Text1.hwnd, EM_SETREADONLY, True, ByVal 0&)
>    If RetVal = 0 Then    ' Check the return value for error
>         MsgBox "Could Not Set Text Box to Read-Only."
>    End If
>End Sub



Mon, 05 Jun 2000 03:00:00 GMT  
 Read-Only TextBox help

Why not just use the Locked Property?
--
Have a good day.
Don

Programming has a multitude of CORRECT solutions
for each problem.


Quote:
> Your function call is failing because you're using the 32-bit function
> declaration with a 16-bit constant definition.  Change the constant definition
> to:  Const EM_SETREADONLY = &HCF    and you should be OK.

> Lee Weiner
> weiner AT fuse DOT net



> >I need to set a TextBox to read-only.  Can anyone explain why this sample
> >code is failing with VB5?
> >What are some of the conditions that might cause this API call to fail?

> >Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd
> >As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long)
> >As Long
> >Const WM_USER = &H400
> >Const EM_SETREADONLY = (WM_USER + 31)

> >Private Sub Command1_Click()
> >    Dim RetVal As Long
> >    RetVal = SendMessage(Text1.hwnd, EM_SETREADONLY, True, ByVal 0&)
> >    If RetVal = 0 Then    ' Check the return value for error
> >         MsgBox "Could Not Set Text Box to Read-Only."
> >    End If
> >End Sub



Mon, 05 Jun 2000 03:00:00 GMT  
 Read-Only TextBox help

Why not just trap the keypress event and change keyascii to 0? Wouldn't
this achieve the same end?



Quote:
> I need to set a TextBox to read-only.  Can anyone explain why this sample
> code is failing with VB5?
> What are some of the conditions that might cause this API call to fail?

> Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hwnd
> As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As
Long)
> As Long
> Const WM_USER = &H400
> Const EM_SETREADONLY = (WM_USER + 31)

> Private Sub Command1_Click()
>     Dim RetVal As Long
>     RetVal = SendMessage(Text1.hwnd, EM_SETREADONLY, True, ByVal 0&)
>     If RetVal = 0 Then    ' Check the return value for error
>          MsgBox "Could Not Set Text Box to Read-Only."
>     End If
> End Sub



Tue, 06 Jun 2000 03:00:00 GMT  
 Read-Only TextBox help

Quote:

> I need to set a TextBox to read-only.  Can anyone explain why this sample
> code is failing with VB5?
> What are some of the conditions that might cause this API call to fail?

> Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd
> As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long)
> As Long
> Const WM_USER = &H400
> Const EM_SETREADONLY = (WM_USER + 31)

> Private Sub Command1_Click()
>     Dim RetVal As Long
>     RetVal = SendMessage(Text1.hwnd, EM_SETREADONLY, True, ByVal 0&)
>     If RetVal = 0 Then    ' Check the return value for error
>          MsgBox "Could Not Set Text Box to Read-Only."
>     End If
> End Sub

  If it's always read-only you could use a Label control instead of a text box.

Tony



Tue, 06 Jun 2000 03:00:00 GMT  
 Read-Only TextBox help

Try
Text1.Locked = True
Text1.Enabled = False

You can still access the default .Text property for setting and retrieval,
but end users cannot edit it, although they can select (and copy to
clipboard) the data within.



Quote:


> > I need to set a TextBox to read-only.  

> > < Funky method using API Call Here >



Tue, 06 Jun 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Help please with read/write from textbox control - VB4

2. VB4 newbie help: Reading a real into a textbox

3. HELP!:Read-only textbox & Autoexec File Icons

4. How to read characters in a textbox

5. Reading textboxes and textframes

6. TextBox readonly without gray background?

7. readonly or disabled textbox without dimming or backcolor change

8. changing textbox readonly property using a collection.

9. Read Only TextBox

10. Why the TextBox.Font.size is readonly?

11. Read a MultiLine textbox line by line?

12. Read only textbox

 

 
Powered by phpBB® Forum Software