SendMessage

  • Thread starter Thread starter Mike Devine
  • Start date Start date
M

Mike Devine

I am trying to change the margins on a TextBox control
using the SendMessage method. I have declared the method
in my class as below:-

[DllImport("user32")]
public static extern int SendMessage(IntPtr handle,
long messageID,
long wParam,
long lParam);

and created some constants as:-

private const long EM_SETMARGINS = 0x00D3;
private const long EC_LEFTMARGIN = 0x0001;
private const long EC_RIGHTMARGIN = 0x0002;
private long margin;

I then invoke the method as:-

SendMessage(this.textBox.Handle,
EM_SETMARGINS,
EC_LEFTMARGIN,
margin);

Whatever I set the margin to I get no change to the left
margin in the textbox. Has anyone any idea what I am
doing wrong?

Regards

Mike
 
Hi Mike!

Mike Devine said:
I am trying to change the margins on a TextBox control
using the SendMessage method. I have declared the method
in my class as below:-

[DllImport("user32")]
public static extern int SendMessage(IntPtr handle,
long messageID,
long wParam,
long lParam);

Your problem is, that long in 64-bits in C#, so you should use int (32-bits)
for the messageID, and preferably IntPtr (platform specific) for the wParam
and lParam and write some wrappers to convert other values to these.

I prefer code like this (untested):
[DllImport("user32")] public static extern IntPtr SendMessage(IntPtr hWnd,
int uMsg, IntPtr wParam, IntPtr lParam);

public static int SendMessage(IntPtr hWnd, int uMsg, int wParam, int lParam)
{
return (int) SendMessage(hWnd, uMsg, (IntPtr) wParam, (IntPtr) lParam);
}
and created some constants as:-

private const long EM_SETMARGINS = 0x00D3;
private const long EC_LEFTMARGIN = 0x0001;
private const long EC_RIGHTMARGIN = 0x0002;
private long margin;

I then invoke the method as:-

SendMessage(this.textBox.Handle,
EM_SETMARGINS,
EC_LEFTMARGIN,
margin);

Whatever I set the margin to I get no change to the left
margin in the textbox. Has anyone any idea what I am
doing wrong?

As mentioned above, the problem seems to be in wrong parameter size.
Regards

Mike

Hope this helps

Stefan
 
Hi Stefan,

That worked fine. Thanks very much for the solution, it's
much appreciated.

Regards

Mike
-----Original Message-----
Hi Mike!

I am trying to change the margins on a TextBox control
using the SendMessage method. I have declared the method
in my class as below:-

[DllImport("user32")]
public static extern int SendMessage(IntPtr handle,
long messageID,
long wParam,
long lParam);

Your problem is, that long in 64-bits in C#, so you should use int (32-bits)
for the messageID, and preferably IntPtr (platform specific) for the wParam
and lParam and write some wrappers to convert other values to these.

I prefer code like this (untested):
[DllImport("user32")] public static extern IntPtr SendMessage(IntPtr hWnd,
int uMsg, IntPtr wParam, IntPtr lParam);

public static int SendMessage(IntPtr hWnd, int uMsg, int wParam, int lParam)
{
return (int) SendMessage(hWnd, uMsg, (IntPtr) wParam, (IntPtr) lParam);
}
and created some constants as:-

private const long EM_SETMARGINS = 0x00D3;
private const long EC_LEFTMARGIN = 0x0001;
private const long EC_RIGHTMARGIN = 0x0002;
private long margin;

I then invoke the method as:-

SendMessage(this.textBox.Handle,
EM_SETMARGINS,
EC_LEFTMARGIN,
margin);

Whatever I set the margin to I get no change to the left
margin in the textbox. Has anyone any idea what I am
doing wrong?

As mentioned above, the problem seems to be in wrong parameter size.
Regards

Mike

Hope this helps

Stefan


.
 
Back
Top