More Interop

  • Thread starter Thread starter Philip Carnstam
  • Start date Start date
P

Philip Carnstam

Hi,

I am trying desperately to get the RedrawWindow function in the User32 lib
to work. But it just does'nt seem to do that. Why?

[DllImport("User32", CharSet=CharSet.Unicode)] //Do'nt know why I would set
CharSet to Unicode, just testing stuff!
private static extern int RedrawWindow(IntPtr hWnd, Rectangle Re, long H,
long Fl);

{
bool T = RedrawWindow(this.Handle, new Rectangle(0,0,100,100), 0, 1);
}

But T is always returned as false. I have tried to make use of a couple of
examples, but still nothing!

Thanks,
Philip
 
Philip,

Your declaration should be as follows:

[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool RedrawWindow(
IntPtr hWnd,
ref Rectangle lprcUpdate,
IntPtr hrgnUpdate,
[MarshalAs(UnmanagedType.U4)]
int flags);

In your previous declaration, there were a number of things wrong:

1) You should declare the return type as bool. The marshaller by default
marshals this as a BOOL type in C++.
2) You need to pass the Rectangle structure by reference, since it is
declared as a pointer in the API
3) You were declaring the handle to the region as a long. On 32 bit
systems, the handle length is 32 bits, and a long is 64 bits, meaning you
bump the flags parameter out of the picture.

Hope this helps.
 
Well, at least now it returns true, but it doesn't do anything...

private void button1_Click(object sender, System.EventArgs e)
{
Rectangle Me = new Rectangle(0,0,this.Width, this.Height);
bool T = RedrawWindow(this.Handle, ref Me, IntPtr.Zero, 1);
this.Text = "" + T;
}

According to me, this should invalidate the form. But still, nothing
happens.
Any more suggestions?

Thanks!

Nicholas Paldino said:
Philip,

Your declaration should be as follows:

[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool RedrawWindow(
IntPtr hWnd,
ref Rectangle lprcUpdate,
IntPtr hrgnUpdate,
[MarshalAs(UnmanagedType.U4)]
int flags);

In your previous declaration, there were a number of things wrong:

1) You should declare the return type as bool. The marshaller by default
marshals this as a BOOL type in C++.
2) You need to pass the Rectangle structure by reference, since it is
declared as a pointer in the API
3) You were declaring the handle to the region as a long. On 32 bit
systems, the handle length is 32 bits, and a long is 64 bits, meaning you
bump the flags parameter out of the picture.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Philip Carnstam said:
Hi,

I am trying desperately to get the RedrawWindow function in the User32 lib
to work. But it just does'nt seem to do that. Why?

[DllImport("User32", CharSet=CharSet.Unicode)] //Do'nt know why I would set
CharSet to Unicode, just testing stuff!
private static extern int RedrawWindow(IntPtr hWnd, Rectangle Re, long H,
long Fl);

{
bool T = RedrawWindow(this.Handle, new Rectangle(0,0,100,100), 0, 1);
}

But T is always returned as false. I have tried to make use of a couple of
examples, but still nothing!

Thanks,
Philip
 
Philip,

I would think that nothing happens either, and that should be correct.
The event handler for the button which calls the RedrawWindow API is doing
nothing that would seem to affect the state of the window.

What does your override for the OnPaint method look like (or your event
handler for the Paint event).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Philip Carnstam said:
Well, at least now it returns true, but it doesn't do anything...

private void button1_Click(object sender, System.EventArgs e)
{
Rectangle Me = new Rectangle(0,0,this.Width, this.Height);
bool T = RedrawWindow(this.Handle, ref Me, IntPtr.Zero, 1);
this.Text = "" + T;
}

According to me, this should invalidate the form. But still, nothing
happens.
Any more suggestions?

Thanks!

message news:[email protected]...
Philip,

Your declaration should be as follows:

[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool RedrawWindow(
IntPtr hWnd,
ref Rectangle lprcUpdate,
IntPtr hrgnUpdate,
[MarshalAs(UnmanagedType.U4)]
int flags);

In your previous declaration, there were a number of things wrong:

1) You should declare the return type as bool. The marshaller by default
marshals this as a BOOL type in C++.
2) You need to pass the Rectangle structure by reference, since it is
declared as a pointer in the API
3) You were declaring the handle to the region as a long. On 32 bit
systems, the handle length is 32 bits, and a long is 64 bits, meaning you
bump the flags parameter out of the picture.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Philip Carnstam said:
Hi,

I am trying desperately to get the RedrawWindow function in the User32 lib
to work. But it just does'nt seem to do that. Why?

[DllImport("User32", CharSet=CharSet.Unicode)] //Do'nt know why I
would
set
CharSet to Unicode, just testing stuff!
private static extern int RedrawWindow(IntPtr hWnd, Rectangle Re, long H,
long Fl);

{
bool T = RedrawWindow(this.Handle, new Rectangle(0,0,100,100), 0, 1);
}

But T is always returned as false. I have tried to make use of a
couple
 
The actual problem lies not on the form, but to order the screen to redraw.
I was just using the form for testing. Of course I can redraw the form using
Invalidate(), but how to I go about doing this for the entire screen.

I have obtained a handle to the screen by GetDC (User32), I draw a line, but
how do I erase it?

Thanks!

Nicholas Paldino said:
Philip,

I would think that nothing happens either, and that should be correct.
The event handler for the button which calls the RedrawWindow API is doing
nothing that would seem to affect the state of the window.

What does your override for the OnPaint method look like (or your event
handler for the Paint event).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Philip Carnstam said:
Well, at least now it returns true, but it doesn't do anything...

private void button1_Click(object sender, System.EventArgs e)
{
Rectangle Me = new Rectangle(0,0,this.Width, this.Height);
bool T = RedrawWindow(this.Handle, ref Me, IntPtr.Zero, 1);
this.Text = "" + T;
}

According to me, this should invalidate the form. But still, nothing
happens.
Any more suggestions?

Thanks!

message news:[email protected]...
Philip,

Your declaration should be as follows:

[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool RedrawWindow(
IntPtr hWnd,
ref Rectangle lprcUpdate,
IntPtr hrgnUpdate,
[MarshalAs(UnmanagedType.U4)]
int flags);

In your previous declaration, there were a number of things wrong:

1) You should declare the return type as bool. The marshaller by default
marshals this as a BOOL type in C++.
2) You need to pass the Rectangle structure by reference, since it is
declared as a pointer in the API
3) You were declaring the handle to the region as a long. On 32 bit
systems, the handle length is 32 bits, and a long is 64 bits, meaning you
bump the flags parameter out of the picture.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

I am trying desperately to get the RedrawWindow function in the
User32
lib
to work. But it just does'nt seem to do that. Why?

[DllImport("User32", CharSet=CharSet.Unicode)] //Do'nt know why I would
set
CharSet to Unicode, just testing stuff!
private static extern int RedrawWindow(IntPtr hWnd, Rectangle Re,
long
H,
long Fl);

{
bool T = RedrawWindow(this.Handle, new Rectangle(0,0,100,100), 0, 1);
}

But T is always returned as false. I have tried to make use of a
couple
of
examples, but still nothing!

Thanks,
Philip
 
Philip,

Why not call the InvalidateRect API function? The declaration is as
follows:

[DllImport("user32.dll", SetLastError=true)]
public static extern bool InvalidateRect(
IntPtr hWnd,
ref Rectangle lpRect,
bool bErase);

It should do what you want, and cause a screen refresh.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Philip Carnstam said:
The actual problem lies not on the form, but to order the screen to redraw.
I was just using the form for testing. Of course I can redraw the form using
Invalidate(), but how to I go about doing this for the entire screen.

I have obtained a handle to the screen by GetDC (User32), I draw a line, but
how do I erase it?

Thanks!

message news:[email protected]...
Philip,

I would think that nothing happens either, and that should be correct.
The event handler for the button which calls the RedrawWindow API is doing
nothing that would seem to affect the state of the window.

What does your override for the OnPaint method look like (or your event
handler for the Paint event).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Philip Carnstam said:
Well, at least now it returns true, but it doesn't do anything...

private void button1_Click(object sender, System.EventArgs e)
{
Rectangle Me = new Rectangle(0,0,this.Width, this.Height);
bool T = RedrawWindow(this.Handle, ref Me, IntPtr.Zero, 1);
this.Text = "" + T;
}

According to me, this should invalidate the form. But still, nothing
happens.
Any more suggestions?

Thanks!

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Philip,

Your declaration should be as follows:

[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool RedrawWindow(
IntPtr hWnd,
ref Rectangle lprcUpdate,
IntPtr hrgnUpdate,
[MarshalAs(UnmanagedType.U4)]
int flags);

In your previous declaration, there were a number of things wrong:

1) You should declare the return type as bool. The marshaller by default
marshals this as a BOOL type in C++.
2) You need to pass the Rectangle structure by reference, since it is
declared as a pointer in the API
3) You were declaring the handle to the region as a long. On 32 bit
systems, the handle length is 32 bits, and a long is 64 bits,
meaning
you
bump the flags parameter out of the picture.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

I am trying desperately to get the RedrawWindow function in the User32
lib
to work. But it just does'nt seem to do that. Why?

[DllImport("User32", CharSet=CharSet.Unicode)] //Do'nt know why I would
set
CharSet to Unicode, just testing stuff!
private static extern int RedrawWindow(IntPtr hWnd, Rectangle Re, long
H,
long Fl);

{
bool T = RedrawWindow(this.Handle, new Rectangle(0,0,100,100), 0, 1);
}

But T is always returned as false. I have tried to make use of a couple
of
examples, but still nothing!

Thanks,
Philip
 
It should, but it does'nt...

Have you tried?
I get a handle to the screen by using
GetDC(0), Primary screen, guess you knew that!
Then I create a Graphics object using the hdc from the GetDC call.
The Graphics object can then draw as much as it likes on the screen, but for
some reason, it cannot erase.


Anyway, this kid is going to bed! Look forward to discussing this problem
more tomorrow, if you're up to it! :-)

Thanks,
Philip



Nicholas Paldino said:
Philip,

Why not call the InvalidateRect API function? The declaration is as
follows:

[DllImport("user32.dll", SetLastError=true)]
public static extern bool InvalidateRect(
IntPtr hWnd,
ref Rectangle lpRect,
bool bErase);

It should do what you want, and cause a screen refresh.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Philip Carnstam said:
The actual problem lies not on the form, but to order the screen to redraw.
I was just using the form for testing. Of course I can redraw the form using
Invalidate(), but how to I go about doing this for the entire screen.

I have obtained a handle to the screen by GetDC (User32), I draw a line, but
how do I erase it?

Thanks!

message news:[email protected]...
Philip,

I would think that nothing happens either, and that should be correct.
The event handler for the button which calls the RedrawWindow API is doing
nothing that would seem to affect the state of the window.

What does your override for the OnPaint method look like (or your event
handler for the Paint event).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Well, at least now it returns true, but it doesn't do anything...

private void button1_Click(object sender, System.EventArgs e)
{
Rectangle Me = new Rectangle(0,0,this.Width, this.Height);
bool T = RedrawWindow(this.Handle, ref Me, IntPtr.Zero, 1);
this.Text = "" + T;
}

According to me, this should invalidate the form. But still, nothing
happens.
Any more suggestions?

Thanks!

in
message Philip,

Your declaration should be as follows:

[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool RedrawWindow(
IntPtr hWnd,
ref Rectangle lprcUpdate,
IntPtr hrgnUpdate,
[MarshalAs(UnmanagedType.U4)]
int flags);

In your previous declaration, there were a number of things wrong:

1) You should declare the return type as bool. The marshaller by
default
marshals this as a BOOL type in C++.
2) You need to pass the Rectangle structure by reference, since it is
declared as a pointer in the API
3) You were declaring the handle to the region as a long. On 32 bit
systems, the handle length is 32 bits, and a long is 64 bits, meaning
you
bump the flags parameter out of the picture.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

I am trying desperately to get the RedrawWindow function in the User32
lib
to work. But it just does'nt seem to do that. Why?

[DllImport("User32", CharSet=CharSet.Unicode)] //Do'nt know why I
would
set
CharSet to Unicode, just testing stuff!
private static extern int RedrawWindow(IntPtr hWnd, Rectangle
Re,
long
H,
long Fl);

{
bool T = RedrawWindow(this.Handle, new Rectangle(0,0,100,100),
0,
1);
}

But T is always returned as false. I have tried to make use of a
couple
of
examples, but still nothing!

Thanks,
Philip
 
Back
Top