Results 1 to 2 of 2

Thread: VB - Refresh the desktop

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    VB - Refresh the desktop

    Add a command button (Command1) to your form and add the following code :

    VB Code:
    1. Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As Long, ByVal bErase As Long) As Long
    2.  
    3. Private Sub Command1_Click()
    4.  InvalidateRect 0&, 0&, False
    5. End Sub


    Has someone helped you? Then you can Rate their helpful post.

  2. #2
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,238

    Re: VB - Refresh the desktop

    Quote Originally Posted by manavo11 View Post
    Add a command button (Command1) to your form and add the following code :

    VB Code:
    1. Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As Long, ByVal bErase As Long) As Long
    2.  
    3. Private Sub Command1_Click()
    4.  InvalidateRect 0&, 0&, False
    5. 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width