I need to capture the wm_paint event from a window other than a visual basic window, anyone got any idea's how to do it???
Printable View
I need to capture the wm_paint event from a window other than a visual basic window, anyone got any idea's how to do it???
I've wondered that to, and I know it's definatley possible, but maybe not with VB as such, cause all them Spy Utilities do it.
Anyway, anyone with info please share :)
SubClass your window.
Add to a Module
Add to a FormCode:Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const GWL_WNDPROC = (-4)
Const WM_PAINT = &HF
Global WndProcOld As Long
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = WM_PAINT Then Debug.Print "PRINT MESSAGE SENT"
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
WndProcOld& = 0
End Sub
Code:Private Sub Form_Load()
SubClassWnd hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd hwnd
End Sub
Subclassing works with everything right, as long as you have the hWnd?
That is cool, I could subclass games to stop redrawing, that would be creepy :)
Yes, Subclassingworks as long as you have the hWnd, and as long as it has it's in the same thread as yours.
To subclass windows that are not in your thread, you need to place you routine in a standard DLL.
yeah cheers for all your help, I found out it can only be placed in a dll, but I also found out you can't wrtie the dll in vb, you have to do it in c++. Oh well better get me C++ manual out...lol
Well, it doesn't really have to be written in C++. C++ is just the idle language to do it in. The DLL can be written in any environment that can create standard DLLs, e.g: Delphi.