Send Message


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: Send Message

  1. #1
    Howard Kaikow Guest

    Send Message

    I know how to use SendMessage with, say, EM_FMTLINES, but what is the API
    for checking the current value of EM_FMTLINES?

    --
    Please post your response to the newsgroup. Do not email me a copy of the
    message.

    http://www.standards.com/ipusers/standards; Word macros, including
    converting from WordBasic to VBA; Technical writing and reviewing; Standards
    ------------------------------------------------



  2. #2
    Howard Kaikow Guest

    Re: Send Message

    The only way to check would be to test the length of a string, I guess
    during the Load event.

    Should be a way to check directly so that the setting can be left as it was
    at the start of execution.
    This capability is needed for any sticky setting, be it mere True/False or
    knot.

    P.S. I'd like to also use SendMessage in VBA, but have not yet figured out
    to get the handle for a control on a VBA Userform. Text1.hWnd is not valid
    in VBA.

    --
    Please post your response to the newsgroup. Do not email me a copy of the
    message.

    http://www.standards.com/ipusers/standards; Word macros, including
    converting from WordBasic to VBA; Technical writing and reviewing; Standards
    ------------------------------------------------
    "L.J. Johnson" <LJJohnson@SlightlyTiltedSoftware.com> wrote in message
    news:3b6989c6$1@news.devx.com...
    > Howard,
    >
    > > I know how to use SendMessage with, say, EM_FMTLINES, but what is the

    API
    > > for checking the current value of EM_FMTLINES?

    >
    > Well, worst case, you could look for a soft line-break character (two
    > carriage returns and a line feed) . Of course, at the beginning of entry,
    > you won't have any. Obviously, MS didn't think this would be needed --

    that
    > you would set/unset it programmatically in your program (and thus not need
    > to check for the state).
    >
    > --
    > L.J. Johnson, Slightly Tilted Software
    > Microsoft MVP (Visual Basic)
    > LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
    > <http://www.SlightlyTiltedSoftware.com>
    > Ask The NT Pro at <http://www.devx.com/gethelp>
    >
    >
    >




  3. #3
    L.J. Johnson Guest

    Re: Send Message

    Howard,

    > I know how to use SendMessage with, say, EM_FMTLINES, but what is the API
    > for checking the current value of EM_FMTLINES?


    Well, worst case, you could look for a soft line-break character (two
    carriage returns and a line feed) . Of course, at the beginning of entry,
    you won't have any. Obviously, MS didn't think this would be needed -- that
    you would set/unset it programmatically in your program (and thus not need
    to check for the state).

    --
    L.J. Johnson, Slightly Tilted Software
    Microsoft MVP (Visual Basic)
    LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
    <http://www.SlightlyTiltedSoftware.com>
    Ask The NT Pro at <http://www.devx.com/gethelp>




  4. #4
    L.J. Johnson Guest

    Re: Send Message

    Howard,

    > Should be a way to check directly so that the setting can be left as it

    was
    > at the start of execution.
    > This capability is needed for any sticky setting, be it mere True/False or
    > knot.


    I agree, but apparently MS thought of it as only something programmer would
    set (to sent to another app or to print), then unset -- their examples show
    this mindset.

    > P.S. I'd like to also use SendMessage in VBA, but have not yet figured out
    > to get the handle for a control on a VBA Userform. Text1.hWnd is not valid
    > in VBA.


    Don't know, don't use VBA (outside of VB much). Why not repost this on
    another thread, like "How do I get Control Handle for VBA UserForm". Maybe
    that will get someone's interest.

    --
    L.J. Johnson, Slightly Tilted Software
    Microsoft MVP (Visual Basic)
    LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
    <http://www.SlightlyTiltedSoftware.com>
    Ask The NT Pro at <http://www.devx.com/gethelp>




  5. #5
    Howard Kaikow Guest

    Re: Send Message

    I know how to get the handle of a VBA Userform.
    See the VBA Snippets example at my web site below.

    I am hoping that given that handle, I could find the handle of each control,
    but I have not yet ventured there.

    --
    Please post your response to the newsgroup. Do not email me a copy of the
    message.

    http://www.standards.com/ipusers/standards; Word macros, including
    converting from WordBasic to VBA; Technical writing and reviewing; Standards
    ------------------------------------------------
    "L.J. Johnson" <LJJohnson@SlightlyTiltedSoftware.com> wrote in message
    news:3b69ac00$1@news.devx.com...
    > Howard,
    >
    > > Should be a way to check directly so that the setting can be left as it

    > was
    > > at the start of execution.
    > > This capability is needed for any sticky setting, be it mere True/False

    or
    > > knot.

    >
    > I agree, but apparently MS thought of it as only something programmer

    would
    > set (to sent to another app or to print), then unset -- their examples

    show
    > this mindset.
    >
    > > P.S. I'd like to also use SendMessage in VBA, but have not yet figured

    out
    > > to get the handle for a control on a VBA Userform. Text1.hWnd is not

    valid
    > > in VBA.

    >
    > Don't know, don't use VBA (outside of VB much). Why not repost this on
    > another thread, like "How do I get Control Handle for VBA UserForm". Maybe
    > that will get someone's interest.
    >
    > --
    > L.J. Johnson, Slightly Tilted Software
    > Microsoft MVP (Visual Basic)
    > LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
    > <http://www.SlightlyTiltedSoftware.com>
    > Ask The NT Pro at <http://www.devx.com/gethelp>
    >
    >
    >




  6. #6
    Howard Kaikow Guest

    Re: Send Message

    Assuming that GetFocus is actually returning a handle in VBA, it appears
    that using EM_FMTLINES has no effect in VBA. I can use the following code in
    VB and change the arg for EM_FMTLINES and it has an effect. Not so in VBA.

    Using:

    Const EM_FMTLINES = &HC8
    Private lngtxtEncryptedHandle As Long
    Private Declare Function GetFocus Lib "user32" () As Long
    Private Declare Function SendMessageBynum Lib "user32" Alias "SendMessageA"
    (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
    As Long) As Long

    With:
    '-- Copy the encrypted data to the display control
    MsgBox "HKBefore: " & Len(csCrypt.OutBuffer)
    txtEncrypted.Text = csCrypt.OutBuffer

    txtEncrypted.SetFocus

    lngtxtEncryptedHandle = GetFocus()
    Dim lc%

    ' Set next to last arg to True to return soft line breaks
    ' False to return just string data
    ' lc% = SendMessageBynum(txtEncrypted.hwnd, EM_FMTLINES, 0, 0&)
    lc% = SendMessageBynum(lngtxtEncryptedHandle, EM_FMTLINES, 0, 0&)
    MsgBox "HKAfter: " & Len(txtEncrypted.Text)

    So the solution to using the examples in the book I cited would be to recode
    the examples to not use text boxes as a means for passing encrypted text,
    rather use a variable with appropriate scope or a class property. This
    likely should be done anyway, but it may have been easier to just insert
    the messages.

    --
    Please post your response to the newsgroup. Do not email me a copy of the
    message.

    http://www.standards.com/ipusers/standards; Word macros, including
    converting from WordBasic to VBA; Technical writing and reviewing; Standards
    ------------------------------------------------
    "Howard Kaikow" <kaikow@standards.com> wrote in message
    news:u5TjulxGBHA.948@tkmsftngp02...
    > I've confirmed the problem below.
    > If I use EM_FMTLINES to change VB's default behavior, VB produces the

    same
    > error as VBA.
    >
    > --
    > Please post your response to the newsgroup. Do not email me a copy of the
    > message.
    >
    > http://www.standards.com/ipusers/standards; Word macros, including
    > converting from WordBasic to VBA; Technical writing and reviewing;

    Standards
    > ------------------------------------------------
    > "Howard Kaikow" <kaikow@standards.com> wrote in message
    > news:#15wANkGBHA.1880@tkmsftngp03...
    > > Dan Appleman points out on page 1344 of his big Win32 API book, "soft

    line
    > > breaks" may be inserted to make the text fit in the text box. He adds

    that
    > > NORMALLY the added soft line breaks are not returned to the program,
    > > however, there is an EM_FMTLINES message that can be used with an Edit
    > > Control to control the behavior.
    > >
    > > He's talking about VB. It would appear that VB and VBA default to

    > different
    > > behavior with returning the added soft line breaks.
    > >
    > > I've not yet tried to figure out how to (ab)use EM_FMTLINES in either VB

    > or
    > > VBA.
    > >
    > > In any case, the example that I was running from a book was

    ill-designed.
    > > There is a Class that has an Output buffer for the encrypted text.

    > However,
    > > the example sticks the text into a text box and then retrieves the text

    > from
    > > a text box for decryption. That causes the byte count to change.
    > >
    > > Sticking the string in the textbox for display is OK, but processing

    > should
    > > use the already stored internal Class variables.
    > > --
    > > Please post your response to the newsgroup. Do not email me a copy of

    the
    > > message.
    > >
    > > http://www.standards.com/ipusers/standards; Word macros, including
    > > converting from WordBasic to VBA; Technical writing and reviewing;

    > Standards
    > > ------------------------------------------------
    > > "Howard Kaikow" <kaikow@standards.com> wrote in message
    > > news:eFvKnZUGBHA.2092@tkmsftngp03...
    > > > I found the problem:
    > > >
    > > > '-- Copy the encrypted data to the display control
    > > > MsgBox "HKBefore: " & Len(csCrypt.OutBuffer)
    > > > txtEncrypted.Text = csCrypt.OutBuffer
    > > > MsgBox "HKAfter: " & Len(txtEncrypted.Text)
    > > >
    > > > In both VB and VBA, the length of csCrypt.OutBuffer is 48 and correct.
    > > > In VBA, the assignment causes txtEncrypted.Text to have a length of

    50.
    > > > In VB, the assignment causes txtEncrypted.Text to have the correct

    > length
    > > of
    > > > 48.
    > > >
    > > > Is there some property of the text box I need to set in VBA?
    > > >
    > > > Apparently VB is "smarter" than VBA. This is a rather significant

    > > difference
    > > > between VB and VBA. Also, VBA uses quite a different font in a text

    > box,
    > > so
    > > > unless one assigns the font, it's hard to tell whether VB and VBA are
    > > > displaying the same stuff.
    > > >
    > > > Of course, in this example, there's no reason to put the encrypted

    stuff
    > > in
    > > > a text box. I was just running an example from the book I am now

    > reading.
    > > >
    > > > This issue pops up in other examples in the book, so I will now be

    alert
    > > for
    > > > them.
    > > > Easiest, for now, I guess is just to run then in VB, not in VBA.





  7. #7
    mrfelis Guest

    Re: Send Message

    Howard Kaikow <kaikow@standards.com> wrote in message
    news:3b69e182@news.devx.com...
    > I know how to get the handle of a VBA Userform.


    Try Enuming child windows. You might get some interesting results.

    When I was working w/ Excel VBA, I tried to pass VBA "textbox" as a Textbox,
    only to be told the control isn't a textbox.

    --
    ~~~
    !ti timda I ,KO
    ..em deppals nocaeB sivaM
    !draH
    ~~
    C'Ya,
    mrfelis@yahoo!com



  8. #8
    Howard Kaikow Guest

    Re: Send Message

    All I had to do was text1.setfocus and then use GetFocus to get the handle.
    Alas, VBA seems to ignore the message.

    --
    Please post your response to the newsgroup. Do not email me a copy of the
    message.

    http://www.standards.com/ipusers/standards; Word macros, including
    converting from WordBasic to VBA; Technical writing and reviewing; Standards
    ------------------------------------------------
    "mrfelis" <mrfelis@yahoo.NOSPAM.com> wrote in message
    news:3b6ab7ba@news.devx.com...
    > Howard Kaikow <kaikow@standards.com> wrote in message
    > news:3b69e182@news.devx.com...
    > > I know how to get the handle of a VBA Userform.

    >
    > Try Enuming child windows. You might get some interesting results.
    >
    > When I was working w/ Excel VBA, I tried to pass VBA "textbox" as a

    Textbox,
    > only to be told the control isn't a textbox.
    >
    > --
    > ~~~
    > !ti timda I ,KO
    > .em deppals nocaeB sivaM
    > !draH
    > ~~
    > C'Ya,
    > mrfelis@yahoo!com
    >
    >




  9. #9
    mrfelis Guest

    Re: Send Message

    Howard Kaikow <kaikow@standards.com> wrote in message
    news:3b6b37be@news.devx.com...
    > All I had to do was text1.setfocus and then use GetFocus to get the

    handle.
    > Alas, VBA seems to ignore the message.

    VBA could be processing the message specifically (and ignoring), and not
    passing it to the defwindowproc.

    The reason why I suggested enuming child windows was that I believe the
    Textbox of a userform wraps a standard windows textbox. If it does you might
    be able to find the real textbox window, which you can send messages to.
    This might get you around the message being ignored.


    --
    Richard Morrison
    Programming and Design
    Redleif International
    www.redleif.com



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center