473,322 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to redraw screen in VB.Net?

Hi guys

I am developing a program which draws stuff on the screen (outside of the
form).
For this I use the GetDC function of user32.dll to get a handle to the
desktop, and then use GDI+ to draw. So far so good.
The problem is that before drawing, I have to erase what I had previously
drawn. I tried using the InvalidateRect API function, without luck.
I get this error when I run the program:

A call to PInvoke function 'WindowsApplication1.Form1::InvalidateRect' has
unbalanced the stack. This is likely because the managed PInvoke signature
does not match the unmanaged target signature. Check that the calling
convention and parameters of the PInvoke signature match the target
unmanaged signature.

This is what I have in my code:

Private Declare Function InvalidateRect Lib "user32" (ByVal hWnd As
System.IntPtr, ByVal lpRect As RECT, ByVal bErase As Boolean) As Boolean

Private Structure RECT

Dim Left As Long

Dim Top As Long

Dim Right As Long

Dim Bottom As Long

End Structure

And then in my function:

Dim ii As New RECT

ii.Bottom = 1280

ii.Top = 0

ii.Left = 100

ii.Right = 700

Dim DesktopHandle As System.IntPtr = GetDC(System.IntPtr.Zero)

InvalidateRect(DesktopHandle, ii, True)

Any ideas? I've tried to google it, but to no avail. I'm new in the Windows
API world, so... It's kinda hard for me to get anywhere.

Thank you for any help you might give me!

Andre Nogueira
Feb 27 '06 #1
3 5448
Long is Integer in VB.NET.

Also I believe this is also available in GDI+. I would use managed class
whenever using COM interop is not required... Similarly the System.Drawing
namespace should allow to retrieve the desktop without having to use interop
(IMO, not tested).

--
Patrice

"Andre Nogueira" <an**@nospam.pt> a écrit dans le message de
news:ux**************@TK2MSFTNGP09.phx.gbl...
Hi guys

I am developing a program which draws stuff on the screen (outside of the
form).
For this I use the GetDC function of user32.dll to get a handle to the
desktop, and then use GDI+ to draw. So far so good.
The problem is that before drawing, I have to erase what I had previously
drawn. I tried using the InvalidateRect API function, without luck.
I get this error when I run the program:

A call to PInvoke function 'WindowsApplication1.Form1::InvalidateRect' has
unbalanced the stack. This is likely because the managed PInvoke signature
does not match the unmanaged target signature. Check that the calling
convention and parameters of the PInvoke signature match the target
unmanaged signature.

This is what I have in my code:

Private Declare Function InvalidateRect Lib "user32" (ByVal hWnd As
System.IntPtr, ByVal lpRect As RECT, ByVal bErase As Boolean) As Boolean

Private Structure RECT

Dim Left As Long

Dim Top As Long

Dim Right As Long

Dim Bottom As Long

End Structure

And then in my function:

Dim ii As New RECT

ii.Bottom = 1280

ii.Top = 0

ii.Left = 100

ii.Right = 700

Dim DesktopHandle As System.IntPtr = GetDC(System.IntPtr.Zero)

InvalidateRect(DesktopHandle, ii, True)

Any ideas? I've tried to google it, but to no avail. I'm new in the Windows API world, so... It's kinda hard for me to get anywhere.

Thank you for any help you might give me!

Andre Nogueira

Feb 27 '06 #2
Hi,

I tried to change "Long" to "Integer" in the RECT struct, but the same error
occurs...

I did try to find managed replacements for these two functions, but couldn't
find any... I'm using VB.Net 2005.

Any other ideas?

Thanks,

Andre

"Patrice" <a@bc.c> wrote in message
news:On**************@TK2MSFTNGP14.phx.gbl...
Long is Integer in VB.NET.

Also I believe this is also available in GDI+. I would use managed class
whenever using COM interop is not required... Similarly the System.Drawing
namespace should allow to retrieve the desktop without having to use
interop
(IMO, not tested).

--
Patrice

"Andre Nogueira" <an**@nospam.pt> a écrit dans le message de
news:ux**************@TK2MSFTNGP09.phx.gbl...
Hi guys

I am developing a program which draws stuff on the screen (outside of the
form).
For this I use the GetDC function of user32.dll to get a handle to the
desktop, and then use GDI+ to draw. So far so good.
The problem is that before drawing, I have to erase what I had previously
drawn. I tried using the InvalidateRect API function, without luck.
I get this error when I run the program:

A call to PInvoke function 'WindowsApplication1.Form1::InvalidateRect'
has
unbalanced the stack. This is likely because the managed PInvoke
signature
does not match the unmanaged target signature. Check that the calling
convention and parameters of the PInvoke signature match the target
unmanaged signature.

This is what I have in my code:

Private Declare Function InvalidateRect Lib "user32" (ByVal hWnd As
System.IntPtr, ByVal lpRect As RECT, ByVal bErase As Boolean) As Boolean

Private Structure RECT

Dim Left As Long

Dim Top As Long

Dim Right As Long

Dim Bottom As Long

End Structure

And then in my function:

Dim ii As New RECT

ii.Bottom = 1280

ii.Top = 0

ii.Left = 100

ii.Right = 700

Dim DesktopHandle As System.IntPtr = GetDC(System.IntPtr.Zero)

InvalidateRect(DesktopHandle, ii, True)

Any ideas? I've tried to google it, but to no avail. I'm new in the

Windows
API world, so... It's kinda hard for me to get anywhere.

Thank you for any help you might give me!

Andre Nogueira


Feb 27 '06 #3
Noticed also that that the RECT structure should be passed byref. Try
http://www.pinvoke.net for all the signatures you need...

System.Drawing.Graphics is basically the counterpart of a DeviceContext. IMO
you should be able to get access to the desktop using its FromHwnd. method.
I remember also to have seen an Invalidate method but this is one is likely
a bit harder to use for your intended usage (if I remember this is either
usable throught the painteventargs, likely available as a member of the
sender control).

--
Patrice

"Andre Nogueira" <an**@nospam.pt> a écrit dans le message de
news:uM**************@TK2MSFTNGP12.phx.gbl...
Hi,

I tried to change "Long" to "Integer" in the RECT struct, but the same error occurs...

I did try to find managed replacements for these two functions, but couldn't find any... I'm using VB.Net 2005.

Any other ideas?

Thanks,

Andre

"Patrice" <a@bc.c> wrote in message
news:On**************@TK2MSFTNGP14.phx.gbl...
Long is Integer in VB.NET.

Also I believe this is also available in GDI+. I would use managed class
whenever using COM interop is not required... Similarly the System.Drawing namespace should allow to retrieve the desktop without having to use
interop
(IMO, not tested).

--
Patrice

"Andre Nogueira" <an**@nospam.pt> a écrit dans le message de
news:ux**************@TK2MSFTNGP09.phx.gbl...
Hi guys

I am developing a program which draws stuff on the screen (outside of the form).
For this I use the GetDC function of user32.dll to get a handle to the
desktop, and then use GDI+ to draw. So far so good.
The problem is that before drawing, I have to erase what I had previously drawn. I tried using the InvalidateRect API function, without luck.
I get this error when I run the program:

A call to PInvoke function 'WindowsApplication1.Form1::InvalidateRect'
has
unbalanced the stack. This is likely because the managed PInvoke
signature
does not match the unmanaged target signature. Check that the calling
convention and parameters of the PInvoke signature match the target
unmanaged signature.

This is what I have in my code:

Private Declare Function InvalidateRect Lib "user32" (ByVal hWnd As
System.IntPtr, ByVal lpRect As RECT, ByVal bErase As Boolean) As Boolean
Private Structure RECT

Dim Left As Long

Dim Top As Long

Dim Right As Long

Dim Bottom As Long

End Structure

And then in my function:

Dim ii As New RECT

ii.Bottom = 1280

ii.Top = 0

ii.Left = 100

ii.Right = 700

Dim DesktopHandle As System.IntPtr = GetDC(System.IntPtr.Zero)

InvalidateRect(DesktopHandle, ii, True)

Any ideas? I've tried to google it, but to no avail. I'm new in the

Windows
API world, so... It's kinda hard for me to get anywhere.

Thank you for any help you might give me!

Andre Nogueira



Feb 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Peter | last post by:
I want to draw some lines on a widget. This works ok, but when I want to redraw, the old lines are still there. How do I clear or refresh the widget, so I can draw a new set of lines? Code...
0
by: PHH | last post by:
Help me, please, When I redraw a ListviewItem in Listview (redraw items with icon and text columms). I used SetStyle(ControlStyle.UserPaint, true) function. And I redraw finish and run...
0
by: WHITETIGER | last post by:
Help me, please, When I redraw a ListviewItem in Listview (redraw items with icon and text columms). I used SetStyle(ControlStyle.UserPaint, true) function. And I redraw finish and run...
2
by: ch424 | last post by:
Hi, Does anybody know the fastest way to trigger a DrawingArea redaw in pygtk? At the moment, I'm using a bit of a hack: def redraw(self): self.area.hide() self.area.show() Is there a...
2
by: Kevin Chandler | last post by:
I appologize in advance if this is a novice question. I don't have much ASP.Net experience. I have an NCAA tournment selection page that I use asp:button controls. The problem is that...
12
by: urs | last post by:
Hi, please look at the ASP.NET 2 site http://www.prismatest.ch/catalog/EM.ASPX (user=prismashop, password=minicooper). Use the ">" Button to go to the next pages. You will notice that the page...
0
by: Dean Earley | last post by:
Hi all. I have just added translucency to one of my applications using the layered windows API, but I have come across a redraw problem. Unfortunately, I cant reproduce this in a standalone...
2
by: diogoko | last post by:
I have some code like: try { someButton.disabled = true; cpuIntensiveCode(); } finally { someButton.disabled = false; } The problem is that someButton is never disabled, because the browser
2
by: Darcy | last post by:
I am trying to do the following: 1. set the contents of div "displayarea" to show a status update bar 2. process some data and format the result into HTML (this may take time, depending upon the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.