[RESOLVED] [VB6] - using SendMessage() with no event arguments(like Paint)-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] [VB6] - using SendMessage() with no event arguments(like Paint)

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,916

    Resolved [RESOLVED] [VB6] - using SendMessage() with no event arguments(like Paint)

    i'm trying using the SendMessage() api function for call the Paint event:
    Code:
    Private PrevWin2 As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal HWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal HWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private 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
    Private Const GWL_WNDPROC = (-4)
    Private Const WM_PAINT = &HF
    
    Private Function Proc2(ByVal HWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        
        ' Pass mouse wheel as arrow keys to a window handle(user controls).
        If IsCodeWindowActivated = False Then
            SendMessage HWnd, WM_PAINT, vbNull, vbNull
            Unhook2 HWnd
        End If
        Proc2 = CallWindowProc(PrevWin2, HWnd, Msg, wParam, lParam)
    End Function
    
    Public Sub Hook2(Handle As Long)
        If PrevWin2 = 0 Then
            PrevWin2 = SetWindowLong(Handle, GWL_WNDPROC, AddressOf Proc2)
        End If
    End Sub
    
    Public Sub Unhook2(Handle As Long)
        If PrevWin2 Then
            Call SetWindowLong(Handle, GWL_WNDPROC, PrevWin2)
            PrevWin2 = 0
        End If
    End Sub
    when i use the SendMessage() the VB6 program is closed
    i belive that my problem is here:
    Code:
    SendMessage HWnd, WM_PAINT, vbNull, vbNull
    how can i use the SendMessage() without arguments event?
    (like Paint event, because don't have arguments)
    (what i need is call the Paint event)
    Last edited by joaquim; Apr 11th, 2012 at 03:48 PM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,938

    Re: [VB6] - using SendMessage() with no event arguments(like Paint)

    If you read the MSDN documentation on WM_Paint, you will see you should not call it directly unless you are trying to have the target draw to a DC passed in the wParam parameter.

    To force a window to repaint, consider one of these APIs: UpdateWindow or RedrawWindow

    P.S. vbNull = 1, not zero. You are telling the destination to paint to a DC value of 1; could be reason for lock/crash.
    Code:
    SendMessage HWnd, WM_PAINT, 0&, ByVal 0&
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,916

    Re: [VB6] - using SendMessage() with no event arguments(like Paint)

    Quote Originally Posted by LaVolpe View Post
    If you read the MSDN documentation on WM_Paint, you will see you should not call it directly unless you are trying to have the target draw to a DC passed in the wParam parameter.

    To force a window to repaint, consider one of these APIs: UpdateWindow or RedrawWindow

    P.S. vbNull = 1, not zero. You are telling the destination to paint to a DC value of 1; could be reason for lock/crash.
    Code:
    SendMessage HWnd, WM_PAINT, 0&, ByVal 0&
    sorry not working. i just need call the Paint or Show event(because they activate the timer)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,916

    Re: [VB6] - using SendMessage() with no event arguments(like Paint)

    yes... thanks
    Code:
    RedrawWindow hwnd, ByVal 0&, ByVal 0&, RDW_INVALIDATE
    instead SendMessage() i use that function. thanks for everything
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.