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] - mvp@spam.guard.caspershouse.com [quoted text, click to view] "Philip Carnstam" <philip@carnstam.net> wrote in message news:ON8wtZdFEHA.3980@TK2MSFTNGP12.phx.gbl... > 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] - mvp@spam.guard.caspershouse.com [quoted text, click to view] "Philip Carnstam" <philip@carnstam.net> wrote in message news:eYksindFEHA.3980@TK2MSFTNGP12.phx.gbl... > 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]" <mvp@spam.guard.caspershouse.com> wrote in > message news:OTup7fdFEHA.696@TK2MSFTNGP12.phx.gbl... > > 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] > > - mvp@spam.guard.caspershouse.com > > > > "Philip Carnstam" <philip@carnstam.net> wrote in message > > news:ON8wtZdFEHA.3980@TK2MSFTNGP12.phx.gbl... > > > 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] - mvp@spam.guard.caspershouse.com [quoted text, click to view] "Philip Carnstam" <philip@carnstam.net> wrote in message news:uaX1gxdFEHA.2732@tk2msftngp13.phx.gbl... > 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 [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in > message news:uqQ$SqdFEHA.1368@TK2MSFTNGP11.phx.gbl... > > 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] > > - mvp@spam.guard.caspershouse.com > > > > "Philip Carnstam" <philip@carnstam.net> wrote in message > > news:eYksindFEHA.3980@TK2MSFTNGP12.phx.gbl... > > > 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]" <mvp@spam.guard.caspershouse.com> wrote > > in > > > message news:OTup7fdFEHA.696@TK2MSFTNGP12.phx.gbl... > > > > 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] > > > > - mvp@spam.guard.caspershouse.com > > > > > > > > "Philip Carnstam" <philip@carnstam.net> wrote in message > > > > news:ON8wtZdFEHA.3980@TK2MSFTNGP12.phx.gbl... > > > > > 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 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
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
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]" <mvp@spam.guard.caspershouse.com> wrote in message news:OTup7fdFEHA.696@TK2MSFTNGP12.phx.gbl... [quoted text, click to view] > 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] > - mvp@spam.guard.caspershouse.com > > "Philip Carnstam" <philip@carnstam.net> wrote in message > news:ON8wtZdFEHA.3980@TK2MSFTNGP12.phx.gbl... > > 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 > > > > > >
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 [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in message news:uqQ$SqdFEHA.1368@TK2MSFTNGP11.phx.gbl... [quoted text, click to view] > 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] > - mvp@spam.guard.caspershouse.com > > "Philip Carnstam" <philip@carnstam.net> wrote in message > news:eYksindFEHA.3980@TK2MSFTNGP12.phx.gbl... > > 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]" <mvp@spam.guard.caspershouse.com> wrote > in > > message news:OTup7fdFEHA.696@TK2MSFTNGP12.phx.gbl... > > > 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] > > > - mvp@spam.guard.caspershouse.com > > > > > > "Philip Carnstam" <philip@carnstam.net> wrote in message > > > news:ON8wtZdFEHA.3980@TK2MSFTNGP12.phx.gbl... > > > > 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 [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in message news:O2Qtp2dFEHA.3132@TK2MSFTNGP12.phx.gbl... [quoted text, click to view] > 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] > - mvp@spam.guard.caspershouse.com > > "Philip Carnstam" <philip@carnstam.net> wrote in message > news:uaX1gxdFEHA.2732@tk2msftngp13.phx.gbl... > > 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 [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote > in > > message news:uqQ$SqdFEHA.1368@TK2MSFTNGP11.phx.gbl... > > > 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] > > > - mvp@spam.guard.caspershouse.com > > > > > > "Philip Carnstam" <philip@carnstam.net> wrote in message > > > news:eYksindFEHA.3980@TK2MSFTNGP12.phx.gbl... > > > > 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]" <mvp@spam.guard.caspershouse.com> > wrote > > > in > > > > message news:OTup7fdFEHA.696@TK2MSFTNGP12.phx.gbl... > > > > > 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] > > > > > - mvp@spam.guard.caspershouse.com > > > > > > > > > > "Philip Carnstam" <philip@carnstam.net> wrote in message > > > > > news:ON8wtZdFEHA.3980@TK2MSFTNGP12.phx.gbl... > > > > > > 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 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
Don't see what you're looking for? Try a search.
|