Results 1 to 7 of 7

Thread: How to convert this (so it works)?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Location
    Perth, Western Australia
    Posts
    1,404

    Default How to convert this (so it works)?

    We have a method to process certain messages in the windows queue using PeekMessage. The original source was from a package published by Christian Berkhout and later modified by Garret Mott.

    Since it uses GetBuff we decided to update it for 19.1. However, the new code will eventually crash triggering an 'Access violation error.' Not sure what have missed but does anyone know how to fix it?

    Old Code.
    Code:
    TYPE tMsg
        Field tMsg.hwnd    As Handle
        Field tMsg.message As Integer
        Field tMsg.wParam  As Integer
        Field tMsg.lParam  As Integer
        Field tMsg.Time    As DWord
        Field tMsg.pt      As Pointer
    END_TYPE
    
    Function ProcessMessage GLOBAL Returns Boolean
        Boolean bMessageFound bTemp
        Pointer pMsg
        Integer iPendingMessage
        String sMsg
    
        Move (False) To bMessageFound
        ZeroType tMsg To sMsg
        Move (AddressOf(sMsg)) To pMsg
        If (PeekMessage(pMsg, 0, 0, 0, PM_REMOVE)) Begin
            GetBuff From sMsg at tMsg.message To iPendingMessage
            If (iPendingMessage = WM_PAINT) Begin
                Move (True) To bMessageFound
                Move (TranslateMessage(pMsg)) To bTemp
                Move (DispatchMessage(pMsg)) To bTemp
            End
        End
    
        Function_Return bMessageFound
    End_Function // ProcessMessage
    New Code.
    Code:
    Use tWinStructs.pkg
    
    Struct tMsg
        Handle  hWndOwner
        Integer iMessage
        Integer wParam
        Integer lParam
        DWord   dwTime
        tWinPoint ltPoint
        DWord   dwPrivate
    End_Struct
    
    Function ProcessMessage GLOBAL Returns Boolean
        tMsg ltMsg
        Boolean bMessageFound bTemp
        Pointer pMsg
    
        Move (False) To bMessageFound
        Move (AddressOf(ltMsg)) To pMsg
        If (PeekMessage(pMsg, 0, 0, 0, PM_REMOVE)) Begin
            If (ltMsg.iMessage = WM_PAINT) Begin
                Move (True) To bMessageFound
                Move (TranslateMessage(pMsg)) To bTemp
                Move (DispatchMessage(pMsg)) To bTemp
            End
        End
    
        Function_Return bMessageFound
    End_Function
    Last edited by Clive Richmond; 5-Sep-2018 at 02:10 AM. Reason: Update the new code with the correct Struct definition as per Raveen's post.
    Kind regards,

    Clive Richmond
    Triumph Business Systems Pty Ltd
    www.triumph.com.au

Posting Permissions

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