[VB6] - about sendmessage() api function-VBForums
Results 1 to 3 of 3

Thread: [VB6] - about sendmessage() api function

  1. #1

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

    [VB6] - about sendmessage() api function

    Code:
    Option Explicit
    
    
    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)
    Public UsercontrolHandle As Long
    Private Const WM_PAINT = &HF
    Private Const WM_KEYDOWN = &H100
    Private Const WM_CLOSE = &H10
    Private Const WM_DESTROY = &H2
    
    
    Private Function Proc2(ByVal HWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        
        
        
        If Msg = WM_PAINT Then
            
            
            SendMessage HWnd, WM_KEYDOWN, 1000, 0
            'Debug.Print "hi"
            
        ElseIf Msg = WM_DESTROY Then
            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
    why sendmessage() crashes my VB6?(instead use the sendmessage(), i use the debug, the VB6 don't crashes)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    3,142

    Re: [VB6] - about sendmessage() api function

    Probably because you're not suppose to send the WM_KEYDOWN message, especially if the wParam and lParam parameters are incorrect. It should also be paired with the corresponding WM_KEYUP message. If you really wanted to send a keystroke, then why not use SendKeys or the APIs keybd_event or SendInput?
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

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

    Re: [VB6] - about sendmessage() api function

    Quote Originally Posted by Bonnie West View Post
    Probably because you're not suppose to send the WM_KEYDOWN message, especially if the wParam and lParam parameters are incorrect. It should also be paired with the corresponding WM_KEYUP message. If you really wanted to send a keystroke, then why not use SendKeys or the APIs keybd_event or SendInput?
    in these case, i can use any
    is for catch the Paint message
    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.