|
-
Mar 20th, 2003, 07:52 PM
#1
Thread Starter
Fanatic Member
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:
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Not wMsg = WM_PAINT Then
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End If
Debug.Print wMsg, Now
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.
-
Mar 21st, 2003, 05:36 AM
#2
Thread Starter
Fanatic Member
-
Mar 21st, 2003, 05:38 AM
#3
Retired VBF Adm1nistrator
Can you post all of your code related to the subclassing ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Mar 21st, 2003, 05:48 AM
#4
Frenzied Member
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:
Declare Function ValidateRectByLong Lib "user32" Alias "ValidateRect" (ByVal hwnd As Long,Byval lpRect As Long) As Long
'...
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Not wMsg = WM_PAINT Then
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
Else
Call ValidateRect(hwnd,0)
End If
End Function
-
Mar 21st, 2003, 05:57 AM
#5
Retired VBF Adm1nistrator
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:
Declare Function ValidateRectByLong Lib "user32" Alias "ValidateRect" (ByVal hwnd As Long,Byval lpRect As Long) As Long
'...
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Not wMsg = WM_PAINT Then
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
Else
Call ValidateRect(hwnd,0)
End If
End Function
What a coincidence. I just about to say that with the exact same code.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Mar 21st, 2003, 01:47 PM
#6
Thread Starter
Fanatic Member
great stuff! thanks alot
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|