• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

Determine if textbox is multilined

Language:  VB6

Scenario:  I have a handle to a textbox.  I need to determine if that textbox is multi-lined or not.  I've looked here but could not find anything:  http://msdn2.microsoft.com/en-us/library/aa924582.aspx

I'm guessing it would go something like this, if I only knew what flag to us instead of [???].
------------------------------------------------------------------------
Dim lngResult As Long

lngResult = SendMessage(hwndTextbox,  [???], ByVal CLng(0), ByVal CLng(0))
------------------------------------------------------------------------

500 points for a quick answer - thanks!
0
enable99
Asked:
enable99
  • 8
  • 7
1 Solution
 
mvidasCommented:
Couldnt you just look for a carriage return or line feed?
 If InStr(1, Textbox1.Text, vbCr) > 0 Or InStr(1, Textbox1.Text, vbLf) Then
  'multiline
 Else
  'not multiline
 End If

Or am I missing something?
Matt
0
 
EDDYKTCommented:
if (TextWidth(Text1.Text)>Text1.Width) then
msgbox "it is multi-line"
end if
0
 
enable99Author Commented:
Matt,

A textbox has a 'Multilined" property.  If this is set to TRUE, the textbox is a multi-lined textbox (even if it contains zero or one line of text).  So although your suggestion works sometime, it will now work all the time.

My goal is to determine if the textbox's Multilined property is true or false.  Any ideas?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
enable99Author Commented:
EDDYKT,

Thanks for your post, please see my response to Matt.  (As you notice, I am actively watching this post.)  500 points to the first person to give me a solid answer!  Thanks Experts!
0
 
mvidasCommented:
Can I assume you ONLY have the handle for the textbox?
If not, couldn't you just use:
 If TextBox1.MultiLine Then

If so, then using your sendmessage api, you should be able to use EM_GETLINECOUNT:

Const EM_GETLINECOUNT As Long = &HBA

'...

If SendMessage(hwndTextbox,  [???], ByVal CLng(0), ByVal CLng(0)) > 1 Then
 'multiline
Else
 'one-line
End if

Matt
0
 
mvidasCommented:
Ok, after looking up a bit on this, using EM_GETLINECOUNT in place of [???] won't do anything, since using EM_GETLINECOUNT only works on multiline textboxes anyways, and a return value of 1 would just mean there is only 1 line in that multiline textbox (as it won't return 0 if not multiline or anything).
I'm sorry, I think I will have to bow out of this question, I'm sure EDDYKT or someone else will be able to help. I'll take a look further, but if you can't just test the object's .multiline property then I'm not sure how I'd be able to help.
0
 
enable99Author Commented:
mvidas,

Thanks for your posts.  Yes, I only have the handle because the textbox resides in another application (not in mine).  Perhaps theres a call to get some property from a multi-lined textbox that FAILS if it is NOT a multi-lined textbox.  This failure/error could be used to determine if the textbox is multi-lined.

Still needing help from someone!  500 points is a-wait-'in!  Thanks Experts!
0
 
mvidasCommented:
As I don't have VB6 where I am now I cannot test this (I only have VBA here), perhaps you could make 2 simple exe's with forms, one with multiline=true and the other with multiline=false, and see what gets returned using SendMessage from both?
Matt
0
 
enable99Author Commented:
mvidas,

That is exactly what I've tried (good suggestion) but everything returns the same regardless of wether the textbox is multi-lined or not.  

AH:  Check this out:  http://msdn2.microsoft.com/en-us/library/aa930492.aspx

How would I get the ES_MULTILINE style?  I bet this is the answer...  500 points to someone who can give me the code - I can't seem to get it to work using SendMessage().  Perhaps I need a different API call??
0
 
mvidasCommented:
I thought about that too, but without testing all I can do is guess at what to do with the code. What about something like:

'declarations:
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
  ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE As Long = -16&
Private Const ES_MULTILINE = &H4

'then use the code
 Dim WStyle As Long
 WStyle = GetWindowLong(hwndTextbox, GWL_STYLE)
 MsgBox WStyle And ES_MULTILINE

Try using that on your two text forms/textboxes? Again, just a guess, but trying to get an answer for you
0
 
enable99Author Commented:
mvidas,

Let me try that now and I'll report back...
0
 
enable99Author Commented:
<b>Ding!  Ding!  Ding!   We have a winner!</b>

<b>Thanks for your persistance mvidas!</b>
0
 
mvidasCommented:
Great! I had read tons of things about using setwindowlong to create a new multiline textbox (since the property is readonly at runtime), so I hoped getwindowlong would work for it. The syntax was my only issue. Glad to help!
I really need vb6 at work :(
0
 
enable99Author Commented:
0
 
mvidasCommented:
I'm afraid I'd have even less of an idea what to do there. EDDYKT is pretty clever, so if he is still subscribed here hopefully he'll check it out (at least I've always assumed EDDYKT was a he)
Matt
0
 
enable99Author Commented:
mvidas,

Thanks anyways.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now