Usman
Usman

Reputation: 2890

What does lPram and wParam means and context each time? I am using PostMessage API from C#

I am forwarding messages to some actual process controls from other process (This other process have simulated all controls of that actual process after hooking). I need to forward all clicks to the actual controls from these simulated controls.

For that reason I am using PostMessage API.

I have all clearence about all the parameters about PostMessage except lParam and wParam. What actual values do I need to pass for these PostMessage containing wParam and lParams.

For now I am using CheckedListBox and on its ItemChecked event, I need to pass this item checked to actual CheckedListBox those contained on actual process of whome controls hooked and drawn on other process.

Code:

    CheckedListBox ListBoxCh;

    ListBoxCh.ItemCheck+=new ItemCheckEventHandler(TAKOCheckedListBox_ItemCheck);

    public void TestCheckedListBox_ItemCheck(Object sender, ItemCheckEventArgs a_Args)
    {
        PostMessage(hWnd,(int)Win32.WindowMessages.WM_LBUTTONDOWN,(IntPtr)0,(IntPtr)0); ?? 
        PostMessage(hWnd, (int)Win32.WindowMessages.WM_LBUTTONUP, (IntPtr)0, (IntPtr)0); ??
    }

Now here, for each click on each control(in this case, CheckedListBox, and for all rest of controls), What values do we need to pass for wParam and lParam for achieving exact clicking and exact message passing from one process (i.e having simulated controls from simulated process to actual process).

Regards Usman

Upvotes: 2

Views: 816

Answers (1)

Michael Edenfield
Michael Edenfield

Reputation: 28338

The names wParam and lParam mean "word parameter" and "long parameter" and are holdovers from Win16, when those parameters actually were 2- and 4-byte values, though both of them are 4-byte integer values in Win32. The exact values needed are specific to the message you are sending. You'll have to look up the messages in the Win32 API documentation to figure it out, for example:

WM_LBUTTONDOWN and WM_LBUTTONUP

In this case, you're lucky in that neither parameter has to be a complex structure, so you just need to construct the proper 32-bit value with your coordinates in them with the & and << operators.

It's not uncommon for one of the parameters to be a pointer to a structure, in which case you'll have to resort to using the Marshal class (specifically, AllocHGlobal, StructureToPtr, and FreeHGlobal) to coerce the data into a usable format.

EDIT:

Note that most of the Windows common controls, like ListBox, have special messages that map to the events exposed by .NET. Unfortunately, in this specific case, CheckedListBox isn't a standard Windows API control; I haven't actually checked but I would guess it's an owner-drawn ListBox control. You could probably check/uncheck the items in the control with the LB_SETITEMDATA event, but unless the obvious values for lParam (1/0) actually work, you'd have to do some digging with Spy++ or something similar to figure that out.

Upvotes: 4

Related Questions