SendMessage in VB.Net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Necromis

    SendMessage in VB.Net

    Ok, I am really losing it. I cannot seem to wrap my head around the
    SendMessage function/method. What I am trying to do is send text/data
    to an instance of a window that I know the handle of from within a
    vb.net application. Can someone give me a decent example of the code
    I
    would need to create to process this using the sample data below.

    Windows hwnd = 0xB0484
    String text = "NM*14*ACCTNO*M MDDYY"


    I have been looking at it both in the local and online help and
    searching the web all over and I am not getting it. Either I am not
    understanding it right or am missing something. I really right now
    just need a good code example. I am trying to pull data from a text
    file and send it in strings to another application w/o having to call
    focus to the window. This way I can run a batch of transactions on
    this other program.


    Oh and one other bit of info I am using MS VB 2005 Express Edition as
    my coding environment.

  • rowe_newsgroups

    #2
    Re: SendMessage in VB.Net

    On May 18, 12:38 pm, Necromis <tflem...@pscuf s.comwrote:
    Ok, I am really losing it. I cannot seem to wrap my head around the
    SendMessage function/method. What I am trying to do is send text/data
    to an instance of a window that I know the handle of from within a
    vb.net application. Can someone give me a decent example of the code
    I
    would need to create to process this using the sample data below.
    >
    Windows hwnd = 0xB0484
    String text = "NM*14*ACCTNO*M MDDYY"
    >
    I have been looking at it both in the local and online help and
    searching the web all over and I am not getting it. Either I am not
    understanding it right or am missing something. I really right now
    just need a good code example. I am trying to pull data from a text
    file and send it in strings to another application w/o having to call
    focus to the window. This way I can run a batch of transactions on
    this other program.
    >
    Oh and one other bit of info I am using MS VB 2005 Express Edition as
    my coding environment.
    I don't think your can use the SendMessage API to send string
    messages. The function only accepts integer values for the message and
    lparam and wparam.

    Thanks,

    Seth Rowe

    Comment

    • Mattias Sjögren

      #3
      Re: SendMessage in VB.Net

      >Ok, I am really losing it. I cannot seem to wrap my head around the
      >SendMessage function/method. What I am trying to do is send text/data
      >to an instance of a window that I know the handle of from within a
      >vb.net application.
      What kind of window is the target? If it's a standard Windows control
      then the WM_SETTEXT message is probably the one you want.


      Mattias

      --
      Mattias Sjögren [C# MVP] mattias @ mvps.org
      http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
      Please reply only to the newsgroup.

      Comment

      • Mattias Sjögren

        #4
        Re: SendMessage in VB.Net

        >I don't think your can use the SendMessage API to send string
        >messages. The function only accepts integer values for the message and
        >lparam and wparam.
        Both lparam and wparam can be any pointer-sized value, including
        string pointers etc. What you actually should pass as arguments
        depends on the message.


        Mattias

        --
        Mattias Sjögren [C# MVP] mattias @ mvps.org
        http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
        Please reply only to the newsgroup.

        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: SendMessage in VB.Net

          "Necromis" <tfleming@pscuf s.comschrieb;
          Ok, I am really losing it. I cannot seem to wrap my head around the
          SendMessage function/method. What I am trying to do is send text/data
          to an instance of a window that I know the handle of from within a
          vb.net application.
          Depending on the exact situation, you may call 'SendMessage' + 'WM_SETTEXT'
          (see documentation for details). An alternative would be to call
          'SendKeys.Send' or 'keybd_event' or 'SendInput', if you do not have the
          window handle the text should be assigned to.

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

          Comment

          • Necromis

            #6
            Re: SendMessage in VB.Net

            On May 18, 1:29 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
            h...@gmx.atwrot e:
            "Necromis" <tflem...@pscuf s.comschrieb;
            >
            Ok, I am really losing it. I cannot seem to wrap my head around the
            SendMessage function/method. What I am trying to do is send text/data
            to an instance of a window that I know the handle of from within a
            vb.net application.
            >
            Depending on the exact situation, you may call 'SendMessage' + 'WM_SETTEXT'
            (see documentation for details). An alternative would be to call
            'SendKeys.Send' or 'keybd_event' or 'SendInput', if you do not have the
            window handle the text should be assigned to.
            >
            --
            M S Herfried K. Wagner
            M V P <URL:http://dotnet.mvps.org/>
            V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
            Well the window is similar to a dos based application. The
            applications name is "Extra - For Netware." It is software used by
            FDR. We use it in house for transaction processing and I need to key
            large batches of transactions to it real time rather than sending them
            out to the processor to run.

            Comment

            • Newbie Coder

              #7
              Re: SendMessage in VB.Net

              Necromis,

              Don't use SendKeys because if you take focus off the window it will fail

              To get the window handle then use the FindWindow function to return the
              IntPtr (for 64 bit compatibility) or just Int32 for no 64 bit ones is fine

              The WM_SETTEXT is just a constant to use but

              What control are you trying to paste to? You mention strings, but for
              example Dim strText As String = TextBox1.Text.. .

              --
              Newbie Coder
              (It's just a name)


              "Necromis" <tfleming@pscuf s.comwrote in message
              news:1179512482 .126621.74310@l 77g2000hsb.goog legroups.com...
              On May 18, 1:29 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
              h...@gmx.atwrot e:
              "Necromis" <tflem...@pscuf s.comschrieb;
              Ok, I am really losing it. I cannot seem to wrap my head around the
              SendMessage function/method. What I am trying to do is send text/data
              to an instance of a window that I know the handle of from within a
              vb.net application.
              Depending on the exact situation, you may call 'SendMessage' +
              'WM_SETTEXT'
              (see documentation for details). An alternative would be to call
              'SendKeys.Send' or 'keybd_event' or 'SendInput', if you do not have the
              window handle the text should be assigned to.

              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
              >
              Well the window is similar to a dos based application. The
              applications name is "Extra - For Netware." It is software used by
              FDR. We use it in house for transaction processing and I need to key
              large batches of transactions to it real time rather than sending them
              out to the processor to run.
              >

              Comment

              • Newbie Coder

                #8
                Re: SendMessage in VB.Net

                Herfried,

                [OP QUOTE]:

                I am trying to pull data from a text file and send it in strings to another
                application w/o having to call focus to the window. This way I can run a
                batch of transactions on this other program.

                [END OP QUOTE]

                [HERFRIED QUOTE]:

                An alternative would be to call
                'SendKeys.Send' ...

                [END HERFRIED QUOTE]

                How do you use SendKeys to paste text in a window that doesn't have focus?



                Look at the definition of SEND in the Public Methods which says:

                'Sends keystrokes to the active application'

                Notice the 'ACTIVE' application

                SendKeys Methods & Examples:



                Where in there does SendKeys pass the handle to send the keystrokes to an
                application without focus? There isn't as it only is used for ACTIVE
                applications, which the OP didn't want

                You're wrong, Herfried

                Where's your code examples on using the other information?

                You say see WM_SETTEXT constant, but you haven't even supplied simple info
                like for example:

                Private Const WM_SETTEXT = &HC

                ----------------------------------------

                Sorry, but this proves you shouldn't be a MVP, giving incorrect information
                & no code samples

                --
                Newbie Coder
                (It's just a name)




                "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message
                news:ekY%23fIXm HHA.1240@TK2MSF TNGP04.phx.gbl. ..
                "Necromis" <tfleming@pscuf s.comschrieb;
                Ok, I am really losing it. I cannot seem to wrap my head around the
                SendMessage function/method. What I am trying to do is send text/data
                to an instance of a window that I know the handle of from within a
                vb.net application.
                >
                Depending on the exact situation, you may call 'SendMessage' +
                'WM_SETTEXT'
                (see documentation for details). An alternative would be to call
                'SendKeys.Send' or 'keybd_event' or 'SendInput', if you do not have the
                window handle the text should be assigned to.
                >
                --
                M S Herfried K. Wagner
                M V P <URL:http://dotnet.mvps.org/>
                V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
                >

                Comment

                • Michel Posseth  [MCP]

                  #9
                  Re: SendMessage in VB.Net

                  why so offensive and rude Newbie Coder ?

                  Do you have a bad day ? .... I notice this from more people nowadays in
                  these groups , don`t forget that

                  Herfried mentioned this as a option , so maybe he means that the OP could
                  take a alternative aproach
                  maybe give the app focus send the keystrokes and then set the focus back to
                  the previous focused app maybe this would become a option for the OP if he
                  wasn`t aware of this posibility

                  And well we all have sometimes a bad day ( no bad hairdays for me as i am
                  bald :-)

                  regards

                  Michel





                  "Newbie Coder" <newbiecoder@sp ammeplease.coms chreef in bericht
                  news:%2361L33am HHA.2296@TK2MSF TNGP03.phx.gbl. ..
                  Herfried,
                  >
                  [OP QUOTE]:
                  >
                  I am trying to pull data from a text file and send it in strings to
                  another
                  application w/o having to call focus to the window. This way I can run a
                  batch of transactions on this other program.
                  >
                  [END OP QUOTE]
                  >
                  [HERFRIED QUOTE]:
                  >
                  An alternative would be to call
                  'SendKeys.Send' ...
                  >
                  [END HERFRIED QUOTE]
                  >
                  How do you use SendKeys to paste text in a window that doesn't have focus?
                  >

                  >
                  Look at the definition of SEND in the Public Methods which says:
                  >
                  'Sends keystrokes to the active application'
                  >
                  Notice the 'ACTIVE' application
                  >
                  SendKeys Methods & Examples:
                  >

                  >
                  Where in there does SendKeys pass the handle to send the keystrokes to an
                  application without focus? There isn't as it only is used for ACTIVE
                  applications, which the OP didn't want
                  >
                  You're wrong, Herfried
                  >
                  Where's your code examples on using the other information?
                  >
                  You say see WM_SETTEXT constant, but you haven't even supplied simple info
                  like for example:
                  >
                  Private Const WM_SETTEXT = &HC
                  >
                  ----------------------------------------
                  >
                  Sorry, but this proves you shouldn't be a MVP, giving incorrect
                  information
                  & no code samples
                  >
                  --
                  Newbie Coder
                  (It's just a name)
                  >
                  >
                  >
                  >
                  "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message
                  news:ekY%23fIXm HHA.1240@TK2MSF TNGP04.phx.gbl. ..
                  >"Necromis" <tfleming@pscuf s.comschrieb;
                  Ok, I am really losing it. I cannot seem to wrap my head around the
                  SendMessage function/method. What I am trying to do is send text/data
                  to an instance of a window that I know the handle of from within a
                  vb.net application.
                  >>
                  >Depending on the exact situation, you may call 'SendMessage' +
                  'WM_SETTEXT'
                  >(see documentation for details). An alternative would be to call
                  >'SendKeys.Send ' or 'keybd_event' or 'SendInput', if you do not have the
                  >window handle the text should be assigned to.
                  >>
                  >--
                  > M S Herfried K. Wagner
                  >M V P <URL:http://dotnet.mvps.org/>
                  > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
                  >>
                  >
                  >

                  Comment

                  • Herfried K. Wagner [MVP]

                    #10
                    Re: SendMessage in VB.Net

                    "Newbie Coder" <newbiecoder@sp ammeplease.coms chrieb:
                    Don't use SendKeys because if you take focus off the window it will fail
                    Whereas the latter is true, I believe that 'SendKeys' serves its purpose.
                    To get the window handle then use the FindWindow function to return the
                    IntPtr (for 64 bit compatibility) or just Int32 for no 64 bit ones is fine
                    >
                    The WM_SETTEXT is just a constant to use but
                    >
                    What control are you trying to paste to? You mention strings, but for
                    example Dim strText As String = TextBox1.Text.. .
                    'WM_SETTEXT' won't work for all controls/windows, that's why I mentioned
                    'SendKeys' as an alternative for those cases. Well, yes, I know about the
                    disadvantages of this approach very well.

                    --
                    M S Herfried K. Wagner
                    M V P <URL:http://dotnet.mvps.org/>
                    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                    Comment

                    • Herfried K. Wagner [MVP]

                      #11
                      Re: SendMessage in VB.Net

                      "Michel Posseth [MCP]" <MSDN@posseth.c omschrieb:
                      why so offensive and rude Newbie Coder ?
                      Don't feed the trolls.
                      Herfried mentioned this as a option
                      Yes, I mentioned it as an option for the case that "all else fails".

                      --
                      M S Herfried K. Wagner
                      M V P <URL:http://dotnet.mvps.org/>
                      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                      Comment

                      • Cor Ligthert [MVP]

                        #12
                        Re: SendMessage in VB.Net

                        Herfried,

                        With one short sentence you destroy the work from Michel.

                        You should know that Newbie Coder is no troll any more but a welcome
                        contributer.

                        I think with this I have enough written,

                        Cor


                        Comment

                        • Herfried K. Wagner [MVP]

                          #13
                          Re: SendMessage in VB.Net

                          "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb:
                          With one short sentence you destroy the work from Michel.
                          >
                          You should know that Newbie Coder is no troll any more but a welcome
                          contributer.
                          If somebody acts like a troll, he is a troll.

                          Nevertheless, constructive and helpful contributions are always welcome and
                          valuable.

                          --
                          M S Herfried K. Wagner
                          M V P <URL:http://dotnet.mvps.org/>
                          V B <URL:http://classicvb.org/petition/>

                          Comment

                          • Necromis

                            #14
                            Re: SendMessage in VB.Net

                            Thank you all, the help is appreciated, and hopefully in the end we
                            will have the answer I need. The application is MS-Dos based, it
                            utilizes ODS as well. Also the main window I am sending the text
                            string to is similar in function to cmd prompt screen. I have the
                            handle of the window which I included in my earlier post.

                            Comment

                            • Newbie Coder

                              #15
                              Re: SendMessage in VB.Net

                              Necromis,

                              The handle isn't static & will change at each run or boot

                              So, you need to pass a string to a console app. How many command line
                              arguments are there?

                              In the first app, where is the text coming from? A textbox or another
                              control or another?

                              Does it have to destroy the data after its sent?

                              --
                              Newbie Coder
                              (It's just a name)







                              "Necromis" <tfleming@pscuf s.comwrote in message
                              news:1179765882 .061687.276850@ 36g2000prm.goog legroups.com...
                              Thank you all, the help is appreciated, and hopefully in the end we
                              will have the answer I need. The application is MS-Dos based, it
                              utilizes ODS as well. Also the main window I am sending the text
                              string to is similar in function to cmd prompt screen. I have the
                              handle of the window which I included in my earlier post.
                              >

                              Comment

                              Working...