How to convert Message.LParam pointer to CREATESTRUCT to an object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm capturing WM_CREATE messages by overriding WndProc in C#/.NET.
How do I then convert the CREATESTRUCT* that GetLParam() would return to an
object that I can use in my code ?

protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg == Convert.ToInt32(WindowsMessages.WM_CREATE))
{
StringBuilder text = new StringBuilder("msg = " + m.Msg.ToString() +
"wParam=" + m.WParam.ToString() + ", lparam=" +
m.LParam.ToString());

// call m.GetLParam() - gets a pointer to CREATESTRUCT;
}

base.WndProc (ref m);
}
 
leightonr,

To get the CREATESTRUCT you first need to declare such a type with all the
fileds with proper types and propertly attributed for marshaling and then
call
*Marshal.PtrToStructure* to get the data from the unmanaged memory.
If you google you can probably find somewhere the .NET declaration of this
structure.

I don't know what your goal is, but take a look at the CreateParmas
protected virtual property. This property is called just before the native
windows is created and has to return the data that is going to be used when
calling CreateWindowEx to create the underlying native window. When you
override this poprerty first call the base implementation then tweak the
data and return the result.

What piece of info you are interested in from that structure? There might be
another way to get it.
 
Thanks Stoitcho,

the information I am trying to get is the name of the new window and its x
and y coordinates.
 
Why don't you just handle one of the events there and check the Text and
Location properties?
 
Back
Top