Results 1 to 6 of 6

Thread: Subclassing Question *Resolved*

  1. #1

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815

    Subclassing Question *Resolved*

    Hi,

    I havent used subclassing much before, but I'm trying to stop picturebox control from being painted (long story, dont think its relevent to the Q).

    I've subclassed the picturebox and when i receive a WM_PAINT message, can i just disguard it? I want all the other messages to work as normal. Ive tried this...
    VB Code:
    1. Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    2.    
    3.     If Not wMsg = WM_PAINT Then
    4.         WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    5.     End If
    6.     Debug.Print wMsg, Now
    7.    
    8. End Function

    ...but the debug window gets printed with loads of '15's over and over and over, which doesnt seem right. I'm a bit clueless here, can anyone point me in the right direction?

    Thanks,
    Illspirit
    Last edited by Illspirit; Mar 21st, 2003 at 01:48 PM.
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  2. #2

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815
    *bump*
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Can you post all of your code related to the subclassing ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    WM_PAINT is a special kind of message in that it is posted to a window whenever that window's message queue is empty and the window has been marked as needing repainting.

    Simply ignoring the message will have no effect because once you return from your subclassing function the queue will be empty and the window will still be marked as requiring painting, so another WM_PAINT message will be posted and so on ad infinitum.

    To mark the window as no longer needing painting you must call the ValidateRect API e.g.:

    VB Code:
    1. Declare Function ValidateRectByLong Lib "user32" Alias "ValidateRect" (ByVal hwnd As Long,Byval lpRect As Long) As Long
    2.  
    3. '...
    4. Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    5.    
    6.     If Not wMsg = WM_PAINT Then
    7.         WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    8.     Else
    9.        Call ValidateRect(hwnd,0)
    10.     End If
    11.        
    12. End Function
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Originally posted by MerrionComputin
    WM_PAINT is a special kind of message in that it is posted to a window whenever that window's message queue is empty and the window has been marked as needing repainting.

    Simply ignoring the message will have no effect because once you return from your subclassing function the queue will be empty and the window will still be marked as requiring painting, so another WM_PAINT message will be posted and so on ad infinitum.

    To mark the window as no longer needing painting you must call the ValidateRect API e.g.:

    VB Code:
    1. Declare Function ValidateRectByLong Lib "user32" Alias "ValidateRect" (ByVal hwnd As Long,Byval lpRect As Long) As Long
    2.  
    3. '...
    4. Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    5.    
    6.     If Not wMsg = WM_PAINT Then
    7.         WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    8.     Else
    9.        Call ValidateRect(hwnd,0)
    10.     End If
    11.        
    12. End Function
    What a coincidence. I just about to say that with the exact same code.



    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  6. #6

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815

    Thumbs up

    great stuff! thanks alot
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

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