Results 1 to 2 of 2

Thread: wm_paint for specific window.

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    60
    Hi , I am currently creating a program which deals with subclassing . I was wondering can I detect wm_paint for a particular window ?
    There is assuming I know the caption of the window.

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Well, it doesn't seem to work with programs outside your thread:

    In a Module
    Code:
    Option Explicit
    
    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) 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
    
    Public Const WM_PAINT = &HF
    Public Const GWL_WNDPROC = (-4)
    Dim OldProc As Long
    Public Sub SubClass(hWnd As Long)
        OldProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
        MsgBox "SubClassed"
    End Sub
    Public Sub unSubClass(hWnd As Long)
        SetWindowLong hWnd, GWL_WNDPROC, OldProc
    End Sub
    Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        If uMsg = WM_PAINT Then
            Debug.Print "PAINTED"
        End If
        WindowProc = CallWindowProc(OldProc, hWnd, uMsg, wParam, lParam)
    End Function
    In a form:
    Code:
    Option Explicit
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Dim lNoteP&
    Private Sub Form_Load()
    lNoteP = FindWindow("Notepad", vbNullString)
    If lNoteP <> 0 Then SubClass lNoteP: MsgBox lNoteP
    'SubClass Me.hWnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    unSubClass lNoteP
    'unSubClass Me.hWnd
    End Sub
    If you uncomment the SubClass Me.Hwnd & UnSubClass Me.Hwnd you'll see it works, so I'm afraid it only works on your progs

    Have Fun Though
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

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