Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
inet
active_desktop
active_scrptng
asp.components
asp.db
asp.general
comctl32
comp.packaging
components.dev
dbweb
dhtml_editing
docobjects
html_authoring
html_objmodel
iis
iis.ftp
iis.security
iis.smtp_nntp
indexserver
misc
mshtml_hosting
scripting.jscript
scripting.vbscript
sdk_setup
shell_objmodel
urlmonikers
webbrowser_ctl
wininet
  
 
date: Tue, 23 Oct 2007 11:54:01 -0700,    group: microsoft.public.inetsdk.programming.scripting.jscript        back       


changing textbox size dynamically   
I have a textbox that I would like to change the size dynamically as the user 
types and it word wraps.  I have used the following vb code (pasted below) 
but what I need is to do it in javascript.   So I ask if anyone out there has 
done this in javascript and willing to share how it was done?  My javascript 
is very very weak so be kind.

Thanks to anyone who responds.

... John


Option Explicit

Private Declare Function SendMessageLong Lib _
    "User32" Alias "SendMessageA" _
     (ByVal hwnd As Long, _
     ByVal wMsg As Long, _
     ByVal wParam As Long, _
     ByVal lParam As Long) As Long

Const EM_FMTLINES = &HC8
Const EM_LINEFROMCHAR = &HC9

Dim MinWidth As Long
Dim MaxWidth As Long
Dim MaxHeight As Long
Dim LastCursor As Long
Dim LastText As String
Dim SingleLineOnly As Boolean

Private Sub Form_Load()
  With Text1
    Set Me.Font = .Font
    MaxHeight = .Container.ScaleHeight - .Top
    MaxWidth = .Container.ScaleWidth - .Left
    MinWidth = Me.TextWidth("XX")
    .Height = Me.TextHeight("X")
    .Width = MinWidth
  End With
End Sub

Private Sub Text1_Change()
  Dim RequiredHeight As Long
  Dim LinesHigh As Long
  With Text1
    .Width = Me.TextWidth(.Text) + Me.ScaleX(2 + _
             6 * .BorderStyle, vbPixels, Me.ScaleMode)
    If .Width < MinWidth Then
      .Width = MinWidth
    ElseIf .Width > MaxWidth Then
      .Width = MaxWidth
    End If
    SendMessageLong .hwnd, EM_FMTLINES, 1, 0#
    LinesHigh = 1 + UBound(Split(Replace$(.Text, _
                vbCr & vbCrLf, vbNewLine), vbNewLine))
    SendMessageLong .hwnd, EM_FMTLINES, 0, 0#
    RequiredHeight = LinesHigh * Me.TextHeight("X") + _
                     Me.ScaleY(6 * .BorderStyle, _
                     vbPixels, Me.ScaleMode)
    If RequiredHeight < MaxHeight Then
      .Height = RequiredHeight
    Else
      .Text = LastText
      .SelStart = LastCursor
    End If
    .Refresh
  End With
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
  If SingleLineOnly Then
    If KeyAscii = 13 Then KeyAscii = 0
  End If
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
  LastText = Text1.Text
  LastCursor = Text1.SelStart
End Sub

Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, _
                          X As Single, Y As Single)
  LastCursor = Text1.SelStart
End Sub
date: Tue, 23 Oct 2007 11:54:01 -0700   author:   JohnE

Re: changing textbox size dynamically   
"JohnE"  wrote in message 
news:DA91C993-9771-4767-92BE-7400BBBA557F@microsoft.com...
>I have a textbox that I would like to change the size dynamically as the 
>user
> types and it word wraps.  I have used the following vb code (pasted below)
> but what I need is to do it in javascript.   So I ask if anyone out there 
> has
> done this in javascript and willing to share how it was done?  My 
> javascript
> is very very weak so be kind.
>
> Thanks to anyone who responds.
>
> ... John
>
>
> Option Explicit
>
> Private Declare Function SendMessageLong Lib _
>    "User32" Alias "SendMessageA" _
>     (ByVal hwnd As Long, _
>     ByVal wMsg As Long, _
>     ByVal wParam As Long, _
>     ByVal lParam As Long) As Long
>
> Const EM_FMTLINES = &HC8
> Const EM_LINEFROMCHAR = &HC9
>
> Dim MinWidth As Long
> Dim MaxWidth As Long
> Dim MaxHeight As Long
> Dim LastCursor As Long
> Dim LastText As String
> Dim SingleLineOnly As Boolean
>
> Private Sub Form_Load()
>  With Text1
>    Set Me.Font = .Font
>    MaxHeight = .Container.ScaleHeight - .Top
>    MaxWidth = .Container.ScaleWidth - .Left
>    MinWidth = Me.TextWidth("XX")
>    .Height = Me.TextHeight("X")
>    .Width = MinWidth
>  End With
> End Sub
>
> Private Sub Text1_Change()
>  Dim RequiredHeight As Long
>  Dim LinesHigh As Long
>  With Text1
>    .Width = Me.TextWidth(.Text) + Me.ScaleX(2 + _
>             6 * .BorderStyle, vbPixels, Me.ScaleMode)
>    If .Width < MinWidth Then
>      .Width = MinWidth
>    ElseIf .Width > MaxWidth Then
>      .Width = MaxWidth
>    End If
>    SendMessageLong .hwnd, EM_FMTLINES, 1, 0#
>    LinesHigh = 1 + UBound(Split(Replace$(.Text, _
>                vbCr & vbCrLf, vbNewLine), vbNewLine))
>    SendMessageLong .hwnd, EM_FMTLINES, 0, 0#
>    RequiredHeight = LinesHigh * Me.TextHeight("X") + _
>                     Me.ScaleY(6 * .BorderStyle, _
>                     vbPixels, Me.ScaleMode)
>    If RequiredHeight < MaxHeight Then
>      .Height = RequiredHeight
>    Else
>      .Text = LastText
>      .SelStart = LastCursor
>    End If
>    .Refresh
>  End With
> End Sub
>
> Private Sub Text1_KeyPress(KeyAscii As Integer)
>  If SingleLineOnly Then
>    If KeyAscii = 13 Then KeyAscii = 0
>  End If
> End Sub
>
> Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
>  LastText = Text1.Text
>  LastCursor = Text1.SelStart
> End Sub
>
> Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, _
>                          X As Single, Y As Single)
>  LastCursor = Text1.SelStart
> End Sub
>
You can't run code like that from script, it has no facility to call into 
non COM libraries.
If the textbox is on a webpage then it's easy, just get a reference to the 
box and set its size property.
If the textbox is a textbox on a windows form then one approach would be 
wrap the code above in an ActiveX library and call that from script.

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name
date: Fri, 2 Nov 2007 09:21:04 -0000   author:   Joe Fawcett am

Re: changing textbox size dynamically   
"Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message 
news:unhwyGTHIHA.6068@TK2MSFTNGP05.phx.gbl...
> "JohnE"  wrote in message 
> news:DA91C993-9771-4767-92BE-7400BBBA557F@microsoft.com...
>>I have a textbox that I would like to change the size dynamically as the 
>>user
>> types and it word wraps.  I have used the following vb code (pasted 
>> below)
>> but what I need is to do it in javascript.   So I ask if anyone out there 
>> has
>> done this in javascript and willing to share how it was done?  My 
>> javascript
>> is very very weak so be kind.
>>
>> Thanks to anyone who responds.
>>
>> ... John
>>
>>
>> Option Explicit
>>
>> Private Declare Function SendMessageLong Lib _
>>    "User32" Alias "SendMessageA" _
>>     (ByVal hwnd As Long, _
>>     ByVal wMsg As Long, _
>>     ByVal wParam As Long, _
>>     ByVal lParam As Long) As Long
>>
>> Const EM_FMTLINES = &HC8
>> Const EM_LINEFROMCHAR = &HC9
>>
>> Dim MinWidth As Long
>> Dim MaxWidth As Long
>> Dim MaxHeight As Long
>> Dim LastCursor As Long
>> Dim LastText As String
>> Dim SingleLineOnly As Boolean
>>
>> Private Sub Form_Load()
>>  With Text1
>>    Set Me.Font = .Font
>>    MaxHeight = .Container.ScaleHeight - .Top
>>    MaxWidth = .Container.ScaleWidth - .Left
>>    MinWidth = Me.TextWidth("XX")
>>    .Height = Me.TextHeight("X")
>>    .Width = MinWidth
>>  End With
>> End Sub
>>
>> Private Sub Text1_Change()
>>  Dim RequiredHeight As Long
>>  Dim LinesHigh As Long
>>  With Text1
>>    .Width = Me.TextWidth(.Text) + Me.ScaleX(2 + _
>>             6 * .BorderStyle, vbPixels, Me.ScaleMode)
>>    If .Width < MinWidth Then
>>      .Width = MinWidth
>>    ElseIf .Width > MaxWidth Then
>>      .Width = MaxWidth
>>    End If
>>    SendMessageLong .hwnd, EM_FMTLINES, 1, 0#
>>    LinesHigh = 1 + UBound(Split(Replace$(.Text, _
>>                vbCr & vbCrLf, vbNewLine), vbNewLine))
>>    SendMessageLong .hwnd, EM_FMTLINES, 0, 0#
>>    RequiredHeight = LinesHigh * Me.TextHeight("X") + _
>>                     Me.ScaleY(6 * .BorderStyle, _
>>                     vbPixels, Me.ScaleMode)
>>    If RequiredHeight < MaxHeight Then
>>      .Height = RequiredHeight
>>    Else
>>      .Text = LastText
>>      .SelStart = LastCursor
>>    End If
>>    .Refresh
>>  End With
>> End Sub
>>
>> Private Sub Text1_KeyPress(KeyAscii As Integer)
>>  If SingleLineOnly Then
>>    If KeyAscii = 13 Then KeyAscii = 0
>>  End If
>> End Sub
>>
>> Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
>>  LastText = Text1.Text
>>  LastCursor = Text1.SelStart
>> End Sub
>>
>> Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, _
>>                          X As Single, Y As Single)
>>  LastCursor = Text1.SelStart
>> End Sub
>>
> You can't run code like that from script, it has no facility to call into 
> non COM libraries.
> If the textbox is on a webpage then it's easy, just get a reference to the 
> box and set its size property.
> If the textbox is a textbox on a windows form then one approach would be 
> wrap the code above in an ActiveX library and call that from script.


Yet this code has a Declare for SendMessage (called SendMessageLong by the 
code). If that works then it is calling into a regular DLL. How is that 
possible? I assume it is not a script; I assume it is VB code.
date: Fri, 2 Nov 2007 12:40:34 -0700   author:   Sam Hobbs _change_social_to_socal

Re: changing textbox size dynamically   
"Sam Hobbs" <samuel@social.rr.com_change_social_to_socal> wrote in message 
news:%23$091gYHIHA.5208@TK2MSFTNGP04.phx.gbl...
> "Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message 
> news:unhwyGTHIHA.6068@TK2MSFTNGP05.phx.gbl...
>> "JohnE"  wrote in message 
>> news:DA91C993-9771-4767-92BE-7400BBBA557F@microsoft.com...
>>>I have a textbox that I would like to change the size dynamically as the 
>>>user
>>> types and it word wraps.  I have used the following vb code (pasted 
>>> below)
>>> but what I need is to do it in javascript.   So I ask if anyone out 
>>> there has
>>> done this in javascript and willing to share how it was done?  My 
>>> javascript
>>> is very very weak so be kind.
>>>
>>> Thanks to anyone who responds.
>>>
>>> ... John
>>>
>>>
>>> Option Explicit
>>>
>>> Private Declare Function SendMessageLong Lib _
>>>    "User32" Alias "SendMessageA" _
>>>     (ByVal hwnd As Long, _
>>>     ByVal wMsg As Long, _
>>>     ByVal wParam As Long, _
>>>     ByVal lParam As Long) As Long
>>>
>>> Const EM_FMTLINES = &HC8
>>> Const EM_LINEFROMCHAR = &HC9
>>>
>>> Dim MinWidth As Long
>>> Dim MaxWidth As Long
>>> Dim MaxHeight As Long
>>> Dim LastCursor As Long
>>> Dim LastText As String
>>> Dim SingleLineOnly As Boolean
>>>
>>> Private Sub Form_Load()
>>>  With Text1
>>>    Set Me.Font = .Font
>>>    MaxHeight = .Container.ScaleHeight - .Top
>>>    MaxWidth = .Container.ScaleWidth - .Left
>>>    MinWidth = Me.TextWidth("XX")
>>>    .Height = Me.TextHeight("X")
>>>    .Width = MinWidth
>>>  End With
>>> End Sub
>>>
>>> Private Sub Text1_Change()
>>>  Dim RequiredHeight As Long
>>>  Dim LinesHigh As Long
>>>  With Text1
>>>    .Width = Me.TextWidth(.Text) + Me.ScaleX(2 + _
>>>             6 * .BorderStyle, vbPixels, Me.ScaleMode)
>>>    If .Width < MinWidth Then
>>>      .Width = MinWidth
>>>    ElseIf .Width > MaxWidth Then
>>>      .Width = MaxWidth
>>>    End If
>>>    SendMessageLong .hwnd, EM_FMTLINES, 1, 0#
>>>    LinesHigh = 1 + UBound(Split(Replace$(.Text, _
>>>                vbCr & vbCrLf, vbNewLine), vbNewLine))
>>>    SendMessageLong .hwnd, EM_FMTLINES, 0, 0#
>>>    RequiredHeight = LinesHigh * Me.TextHeight("X") + _
>>>                     Me.ScaleY(6 * .BorderStyle, _
>>>                     vbPixels, Me.ScaleMode)
>>>    If RequiredHeight < MaxHeight Then
>>>      .Height = RequiredHeight
>>>    Else
>>>      .Text = LastText
>>>      .SelStart = LastCursor
>>>    End If
>>>    .Refresh
>>>  End With
>>> End Sub
>>>
>>> Private Sub Text1_KeyPress(KeyAscii As Integer)
>>>  If SingleLineOnly Then
>>>    If KeyAscii = 13 Then KeyAscii = 0
>>>  End If
>>> End Sub
>>>
>>> Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
>>>  LastText = Text1.Text
>>>  LastCursor = Text1.SelStart
>>> End Sub
>>>
>>> Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, _
>>>                          X As Single, Y As Single)
>>>  LastCursor = Text1.SelStart
>>> End Sub
>>>
>> You can't run code like that from script, it has no facility to call into 
>> non COM libraries.
>> If the textbox is on a webpage then it's easy, just get a reference to 
>> the box and set its size property.
>> If the textbox is a textbox on a windows form then one approach would be 
>> wrap the code above in an ActiveX library and call that from script.
>
>
> Yet this code has a Declare for SendMessage (called SendMessageLong by the 
> code). If that works then it is calling into a regular DLL. How is that 
> possible? I assume it is not a script; I assume it is VB code.
>
What's your question? The OP said it was VB, he wanted to do it in script. 
As I said it is not possible for script to access native DLL functions 
directly, they can only interact with COM DLLs.

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name
date: Sun, 4 Nov 2007 15:45:14 -0000   author:   Joe Fawcett am

Re: changing textbox size dynamically   
"Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message 
news:%231DpymvHIHA.5544@TK2MSFTNGP02.phx.gbl...

> What's your question? The OP said it was VB, he wanted to do it in script. 
> As I said it is not possible for script to access native DLL functions 
> directly, they can only interact with COM DLLs.

I am not the person that asked the question, so please don't expect me to 
ask a question in someone else's thread.

I am sorry; thought that I did misunderstand. As you indicated, it is 
essentially not possible to do anything with Windows windows from script.

I am not familiar with the CLR/CLI/.Net/Windows Forms stuff enough to know 
if they can be used from a script without use of a HTML or HTA page. It 
would be very useful if that were possible.

So for a script-only solution, the only practical option is to use a HTML or 
HTA page.
date: Sun, 4 Nov 2007 17:59:41 -0800   author:   Sam Hobbs _change_social_to_socal

Re: changing textbox size dynamically   
"Sam Hobbs" <samuel@social.rr.com_change_social_to_socal> wrote in message 
news:%23Y1W890HIHA.5328@TK2MSFTNGP05.phx.gbl...
> "Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message 
> news:%231DpymvHIHA.5544@TK2MSFTNGP02.phx.gbl...
>
>> What's your question? The OP said it was VB, he wanted to do it in 
>> script. As I said it is not possible for script to access native DLL 
>> functions directly, they can only interact with COM DLLs.
>
> I am not the person that asked the question, so please don't expect me to 
> ask a question in someone else's thread.
>
> I am sorry; thought that I did misunderstand. As you indicated, it is 
> essentially not possible to do anything with Windows windows from script.
>
> I am not familiar with the CLR/CLI/.Net/Windows Forms stuff enough to know 
> if they can be used from a script without use of a HTML or HTA page. It 
> would be very useful if that were possible.
>
> So for a script-only solution, the only practical option is to use a HTML 
> or HTA page.
>
>
Okay, I misunderstood:
  "If that works then it is calling into a regular DLL. How is that 
possible?"
sounded like a question...

To re-iterate:
Calling functions decalerd in a Windows' style DLL, rather than a COM one is 
impossible from VBScript.
The workaround would be to wrap the original DLL inside a COM one and expose 
the necessary functions.

You can call a number of the .NET classes from script as they provide COM 
wrappers, look at System. in HKEY_Classes_Root via regedit for some 
examples.

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name
date: Tue, 6 Nov 2007 09:29:40 -0000   author:   Joe Fawcett am

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us