Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. using lparam parameter of SendMessage function

using lparam parameter of SendMessage function

Scheduled Pinned Locked Moved C#
tutorialjsonhelp
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sandeep Kalra
    wrote on last edited by
    #1

    Hi All I have send keys to the application(other) which i have started using my windows form . By using API and managed code SetForeGroundWindow.. and SendKeys.Send... This is working fine.But while my application sends keys if a user click on any other window then that(window on which user clicked) get the keys not the window for which it was meant. So i had to chose other way. Now I am using SendMeassage API and I want to send a Key to that application [DllImport("User32.dll", EntryPoint = "SendMessage")] public static extern int SendMessage(int hWnd, int Msg, int wParam,int lParam); I have got the handle(hwnd) of the window to which i want to send a key(for here say F1 key) public const WM_KEYDOWN =0x100; /which is one of the possible value of msg /Here It is for keydown event. public const VK_F1=0x70; // it is a virtual key code for F1 to be passed in wparam For lparam i have following inf lParam Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table. 0-15 Specifies the repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative. 16-23 Specifies the scan code. The value depends on the OEM. 24 Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0. 25-28 Reserved; do not use. 29 Specifies the context code. The value is always 0 for a WM_KEYDOWN message. 30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up. 31 Specifies the transition state. The value is always zero for a WM_KEYDOWN message. Return Value An application should return zero if it processes this message. I do not know how to pass lparam to the function. Note:I have set 0x00 for lparam and i am gettingreturn value 0 which i had stored in a variable.This means the message was processed by the window according to return value condition above.But I did not saw any Help window of that application. Please guide in using lparam particularly for case of KeyDown msg of F1 Thanks THE SK (Sandeep Kalra) "I am the One"

    S realJSOPR 2 Replies Last reply
    0
    • S Sandeep Kalra

      Hi All I have send keys to the application(other) which i have started using my windows form . By using API and managed code SetForeGroundWindow.. and SendKeys.Send... This is working fine.But while my application sends keys if a user click on any other window then that(window on which user clicked) get the keys not the window for which it was meant. So i had to chose other way. Now I am using SendMeassage API and I want to send a Key to that application [DllImport("User32.dll", EntryPoint = "SendMessage")] public static extern int SendMessage(int hWnd, int Msg, int wParam,int lParam); I have got the handle(hwnd) of the window to which i want to send a key(for here say F1 key) public const WM_KEYDOWN =0x100; /which is one of the possible value of msg /Here It is for keydown event. public const VK_F1=0x70; // it is a virtual key code for F1 to be passed in wparam For lparam i have following inf lParam Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table. 0-15 Specifies the repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative. 16-23 Specifies the scan code. The value depends on the OEM. 24 Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0. 25-28 Reserved; do not use. 29 Specifies the context code. The value is always 0 for a WM_KEYDOWN message. 30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up. 31 Specifies the transition state. The value is always zero for a WM_KEYDOWN message. Return Value An application should return zero if it processes this message. I do not know how to pass lparam to the function. Note:I have set 0x00 for lparam and i am gettingreturn value 0 which i had stored in a variable.This means the message was processed by the window according to return value condition above.But I did not saw any Help window of that application. Please guide in using lparam particularly for case of KeyDown msg of F1 Thanks THE SK (Sandeep Kalra) "I am the One"

      S Offline
      S Offline
      Simon P Stevens
      wrote on last edited by
      #2

      In this case, lparam is a 32 bit value that contains a 16 bit int, an 8 bit int, a 1 bit bool, a 4 bit reserved block, then 3 1 bit bools.

        0-15          16-23      24     25-28      29    30    31
      

      [16 bit int] [8 bit int] [bool] [reserved] [bool][bool][bool]
      0000000000000000 00000000 0 0000 0 0 0

      Combined to form a 32 bit (binary) value. 00000000000000000000000000000000 If you want to pass something into one of these you need to work out where in the bit string the value needs to go, and then combine it to form a 32 bit value you can pass. But I don't think you need to be passing anything on the lparam. none of them look like they are needed. I would instead suggest that you probably need to send a wm_keyup message aftwards. A lot of apps only respond to keydown when it is followed by a keyup message.

      Simon

      S 1 Reply Last reply
      0
      • S Simon P Stevens

        In this case, lparam is a 32 bit value that contains a 16 bit int, an 8 bit int, a 1 bit bool, a 4 bit reserved block, then 3 1 bit bools.

          0-15          16-23      24     25-28      29    30    31
        

        [16 bit int] [8 bit int] [bool] [reserved] [bool][bool][bool]
        0000000000000000 00000000 0 0000 0 0 0

        Combined to form a 32 bit (binary) value. 00000000000000000000000000000000 If you want to pass something into one of these you need to work out where in the bit string the value needs to go, and then combine it to form a 32 bit value you can pass. But I don't think you need to be passing anything on the lparam. none of them look like they are needed. I would instead suggest that you probably need to send a wm_keyup message aftwards. A lot of apps only respond to keydown when it is followed by a keyup message.

        Simon

        S Offline
        S Offline
        Sandeep Kalra
        wrote on last edited by
        #3

        Hi Now I have used SendMessage API for both WM_KEYDOWN and WM_KEYUP . But still nothing happens. I have also included SecurityPermission for unmanaged code. I am not getting any warning or errors.I have already tried 0 as value for lparam but nothing happens no exception no warning etc. Please guide THE SK (Sandeep Kalra) "I am the One"

        S 1 Reply Last reply
        0
        • S Sandeep Kalra

          Hi All I have send keys to the application(other) which i have started using my windows form . By using API and managed code SetForeGroundWindow.. and SendKeys.Send... This is working fine.But while my application sends keys if a user click on any other window then that(window on which user clicked) get the keys not the window for which it was meant. So i had to chose other way. Now I am using SendMeassage API and I want to send a Key to that application [DllImport("User32.dll", EntryPoint = "SendMessage")] public static extern int SendMessage(int hWnd, int Msg, int wParam,int lParam); I have got the handle(hwnd) of the window to which i want to send a key(for here say F1 key) public const WM_KEYDOWN =0x100; /which is one of the possible value of msg /Here It is for keydown event. public const VK_F1=0x70; // it is a virtual key code for F1 to be passed in wparam For lparam i have following inf lParam Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table. 0-15 Specifies the repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative. 16-23 Specifies the scan code. The value depends on the OEM. 24 Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0. 25-28 Reserved; do not use. 29 Specifies the context code. The value is always 0 for a WM_KEYDOWN message. 30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up. 31 Specifies the transition state. The value is always zero for a WM_KEYDOWN message. Return Value An application should return zero if it processes this message. I do not know how to pass lparam to the function. Note:I have set 0x00 for lparam and i am gettingreturn value 0 which i had stored in a variable.This means the message was processed by the window according to return value condition above.But I did not saw any Help window of that application. Please guide in using lparam particularly for case of KeyDown msg of F1 Thanks THE SK (Sandeep Kalra) "I am the One"

          realJSOPR Offline
          realJSOPR Offline
          realJSOP
          wrote on last edited by
          #4

          To make a lParam integer, try this:

          public int MakeLParam(int loWord, int hiWord)
          {
          return ((hiWord << 16) + loWord);
          }
          public int MakeWParam(int loWord, int hiWord)
          {
          return ((hiWord << 16) + loWord);
          }

          Now, all you have to do is construct the two parts of the lParam value, and pass them into one of those functions. You may also want to look at this page: http://www.pinvoke.net/default.aspx/user32/SendInput.html[^] As usual, a little googling would have saved you *and us* HOURS of time. [EDIT] and the univoter strikes again. I provide an answer and get 1'd. How fucking pathetic.

          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

          modified on Tuesday, October 14, 2008 7:06 AM

          1 Reply Last reply
          0
          • S Sandeep Kalra

            Hi Now I have used SendMessage API for both WM_KEYDOWN and WM_KEYUP . But still nothing happens. I have also included SecurityPermission for unmanaged code. I am not getting any warning or errors.I have already tried 0 as value for lparam but nothing happens no exception no warning etc. Please guide THE SK (Sandeep Kalra) "I am the One"

            S Offline
            S Offline
            Simon P Stevens
            wrote on last edited by
            #5

            Then you are doing something wrong. Does the app you are sending the key two definitely handle F1 key presses? Are you sending the correct code for the F1 key? Try writing your own app to receive a key down/up message for the F1 and check it works. That will check that you are doing the sending correctly. If you are, then maybe the receiving app isn't handling keyup/down messages.

            Simon

            S 1 Reply Last reply
            0
            • S Simon P Stevens

              Then you are doing something wrong. Does the app you are sending the key two definitely handle F1 key presses? Are you sending the correct code for the F1 key? Try writing your own app to receive a key down/up message for the F1 and check it works. That will check that you are doing the sending correctly. If you are, then maybe the receiving app isn't handling keyup/down messages.

              Simon

              S Offline
              S Offline
              Sandeep Kalra
              wrote on last edited by
              #6

              Hi Thats the Internet Explorer to which I am sending F1 key.It responds to F1 key if i press it on keyboard. Is it really the case that IE donot responds to WM_KEYUP or WM_KEYDOWN events.I have tried for WM_CLOSE and for quit too but it did not worked. I am trying to find. THE SK (Sandeep Kalra) "I am the One"

              S M 2 Replies Last reply
              0
              • S Sandeep Kalra

                Hi Thats the Internet Explorer to which I am sending F1 key.It responds to F1 key if i press it on keyboard. Is it really the case that IE donot responds to WM_KEYUP or WM_KEYDOWN events.I have tried for WM_CLOSE and for quit too but it did not worked. I am trying to find. THE SK (Sandeep Kalra) "I am the One"

                S Offline
                S Offline
                Simon P Stevens
                wrote on last edited by
                #7

                Sandeep Kalra wrote:

                I have tried for WM_CLOSE and for quit too but it did not worked

                Then like I said. You are doing something wrong.

                Simon

                1 Reply Last reply
                0
                • S Sandeep Kalra

                  Hi Thats the Internet Explorer to which I am sending F1 key.It responds to F1 key if i press it on keyboard. Is it really the case that IE donot responds to WM_KEYUP or WM_KEYDOWN events.I have tried for WM_CLOSE and for quit too but it did not worked. I am trying to find. THE SK (Sandeep Kalra) "I am the One"

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  How do you know you're sending the messages to the right window?

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  S 1 Reply Last reply
                  0
                  • M Mark Salsbery

                    How do you know you're sending the messages to the right window?

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    S Offline
                    S Offline
                    Sandeep Kalra
                    wrote on last edited by
                    #9

                    I have the handle of that window to which i wanted to send the message. I have also found that the PostMessage API which has same parameters as that of SendMessage ,is working fine. Declared this above in code [DllImport("user32.dll",EnteryPoint="PostMessage"] public static extern bool PostMessage(int hwnd,int msg,int wparam,int lparam) [DllImport("user32.dll",EnteryPoint="SendMessage"] public static extern int SendMessage(int hwnd,int msg,int wparam,int lparam) I am transferribg same parameters to the PostMessage and SendMessage by declaring them public ,on two different button_click event on my form Button with a PostMessage is working fine.But button_click with SendMessage is not working at all.I am not getting any warning, error or runtime errror. Also found that WM_KILLFOCUS,WM_QUIT are not working on PostMessage.However WM_CLOSE ,WM_KEYDOWN,WM_KEYUP worked fine. I do not know whats wrong(sure not coding).Please suggest. And I also want to know whic among SendMessage and PostMessage is more reliable

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups