Solved

Determine if textbox is multilined

Posted on 2007-03-30
16
275 Views
Last Modified: 2010-08-05
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
Comment
Question by:enable99
  • 8
  • 7
16 Comments
 
LVL 35

Expert Comment

by:mvidas
ID: 18825268
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 18825344
if (TextWidth(Text1.Text)>Text1.Width) then
msgbox "it is multi-line"
end if
0
 

Author Comment

by:enable99
ID: 18825347
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
 

Author Comment

by:enable99
ID: 18825354
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
 
LVL 35

Expert Comment

by:mvidas
ID: 18825567
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
 
LVL 35

Expert Comment

by:mvidas
ID: 18825684
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
 

Author Comment

by:enable99
ID: 18825861
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
 
LVL 35

Expert Comment

by:mvidas
ID: 18825939
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:enable99
ID: 18826052
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
 
LVL 35

Accepted Solution

by:
mvidas earned 500 total points
ID: 18826154
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
 

Author Comment

by:enable99
ID: 18826440
mvidas,

Let me try that now and I'll report back...
0
 

Author Comment

by:enable99
ID: 18826485
<b>Ding!  Ding!  Ding!   We have a winner!</b>

<b>Thanks for your persistance mvidas!</b>
0
 
LVL 35

Expert Comment

by:mvidas
ID: 18826498
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
 

Author Comment

by:enable99
ID: 18826505
0
 
LVL 35

Expert Comment

by:mvidas
ID: 18826525
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
 

Author Comment

by:enable99
ID: 18826602
mvidas,

Thanks anyways.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual Basic Excel Formatting error 4 67
MsgBox 2 36
How to debug this code 7 49
control image tags in a string ? 12 59
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about problems I had with the new location API and permissions in Marshmallow
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

709 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now