Re: VB - Refresh the desktop
Quote:
Originally Posted by
manavo11
Add a command button (Command1) to your form and add the following code :
VB Code:
Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As Long, ByVal bErase As Long) As Long
Private Sub Command1_Click()
InvalidateRect 0&, 0&, False
End Sub
Just curious, why did you use
Code:
Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As Long, ByVal bErase As Long) As Long
for the declaration instead of
Code:
Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, Byval lpRect As Long, ByVal bErase As Long) As Long
You should know that what you used is incorrect.
When using lpRect as RECT it must be done as ByRef (or including nothing before the variable name). However, when using lpRect as Long (so you can pass it a NULL), you must use ByVal before the variable name. Then supply a value of 0. This is sending it the memory address of 0x00000000 which is an invalid memory address, and therefore it corresponds to no RECT structure, and therefore it is passing a NULL to it. If you do ByRef with the "as Long" then it will pass it a valid memory pointer pointing to the Long number. Since the Long number is a Long, not a RECT, it is giving it a pointer to a variable of a type that it was not expecting, and therefore it will try futilely to try to treat it as a RECT which it is certainly not. This will result in the program glitching or even crashing.