Results 1 to 8 of 8

Thread: [RESOLVED] [VB6] - instead api_doevents

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Resolved [RESOLVED] [VB6] - instead api_doevents

    can i let the events being used\activated without using:
    Code:
    Option Explicit
    
    Private Const PM_REMOVE = &H1&
    Private Type Msg
        hwnd As Long
        message As Long
        wParam As Long
        lParam As Long
        time As Long
        ptX As Long
        ptY As Long
    End Type
    Private Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
    Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
    Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, _
                                                      ByVal hwnd As Long, _
                                                      ByVal wMsgFilterMin As Long, _
                                                      ByVal wMsgFilterMax As Long, _
                                                     ByVal wRemoveMsg As Long) As Long
    
    Public Sub API_DoEvents(ByVal hwnd As Long)
       
       Dim TMsg As Msg
       Do While PeekMessage(TMsg, hwnd, 0&, 0&, PM_REMOVE)
            TranslateMessage TMsg
            DispatchMessage TMsg
            
      Loop
      
    End Sub
    ????
    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
    4,060

    Re: [VB6] - instead api_doevents

    This is functionally similar to DoEvents but it only yields to the OS when there is actually something to process.

    Code:
    Private Declare Function GetInputState Lib "user32.dll" () As Long
    Private Declare Function GetQueueStatus Lib "user32.dll" (ByVal Flags As Long) As Long
    
    'Yields execution only when a message has arrived so that the operating system can process other events.
    Public Function DoEventsEx() As Integer
        #Const Keyboard_and_Mouse_Messages_Only = False
        Const QS_ALLINPUT = &H4FF&
    
        #If Keyboard_and_Mouse_Messages_Only Then
            If GetInputState Then DoEventsEx = DoEvents
           'GetInputState returns TRUE (nonzero) if either a keyboard or mouse message is in the application's
           'input queue. If the application must distinguish between a mouse and a keyboard message, GetInputState
           'returns the value 2 for a keyboard and the value 1024 for a mouse message.
        #Else
            If GetQueueStatus(QS_ALLINPUT) And &HFFFF0000 Then DoEventsEx = DoEvents
           'The high-order word of GetQueueStatus' return value indicates the types of messages currently in the
           'queue. The low-order word indicates the types of messages that have been added to the queue and that
           'are still in the queue since the last call to the GetQueueStatus, GetMessage, or PeekMessage function.
        #End If
    End Function
    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
    3,904

    Re: [VB6] - instead api_doevents

    Quote Originally Posted by Bonnie West View Post
    This is functionally similar to DoEvents but it only yields to the OS when there is actually something to process.

    Code:
    Private Declare Function GetInputState Lib "user32.dll" () As Long
    Private Declare Function GetQueueStatus Lib "user32.dll" (ByVal Flags As Long) As Long
    
    'Yields execution only when a message has arrived so that the operating system can process other events.
    Public Function DoEventsEx() As Integer
        #Const Keyboard_and_Mouse_Messages_Only = False
        Const QS_ALLINPUT = &H4FF&
    
        #If Keyboard_and_Mouse_Messages_Only Then
            If GetInputState Then DoEventsEx = DoEvents
           'GetInputState returns TRUE (nonzero) if either a keyboard or mouse message is in the application's
           'input queue. If the application must distinguish between a mouse and a keyboard message, GetInputState
           'returns the value 2 for a keyboard and the value 1024 for a mouse message.
        #Else
            If GetQueueStatus(QS_ALLINPUT) And &HFFFF0000 Then DoEventsEx = DoEvents
           'The high-order word of GetQueueStatus' return value indicates the types of messages currently in the
           'queue. The low-order word indicates the types of messages that have been added to the queue and that
           'are still in the queue since the last call to the GetQueueStatus, GetMessage, or PeekMessage function.
        #End If
    End Function
    thanks for all
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,254

    Re: [RESOLVED] [VB6] - instead api_doevents

    Thanks Bonnie - that's very useful...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  5. #5
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,730

    Re: [RESOLVED] [VB6] - instead api_doevents

    sorry to resurrect this thread, but its actually important.
    I did have a problem with flickering, the form would from time to time flicker from a mouse click,
    i thought first that is was a form_paint or form_resize issue, but after a lot of testing I found out that the problem is DoEvents.
    two different DoEvents alternatives:
    the simple: If GetQueueStatus(&HFF&) Then DoEvents
    and the one Bonnie West posted,
    but both gave me this flickering (a black background color that from time to time would flicker for a short moment, like it was white for a millisecond)
    using DoEvents would not cause this.

    so, well, DoEvents fixed it, but the question is, Why would it flicker at all.
    its like using the alternative DoEvents, would push in a queue messages and after a while would get released and cause a flicker.

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [RESOLVED] [VB6] - instead api_doevents

    baka: normaly the flicker only happens when you draw, on form, 2 or more colors\figures(even with backcolor) at same time.
    the best is draw everything in a bitmap memory and then draw all the image in form... these is the best way for avoid flickers
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,730

    Re: [RESOLVED] [VB6] - instead api_doevents

    Im suing direct2d and theres no bitmap memory there, and the entire picture is created in "memory" before rendered.
    the problem is not that, but the doevents that causes something to flicker, not the rendering itself, but the form/picturebox do something.

    using DoEvents will not cause this, only if using the API GetQueueStatus
    thats the reason I posted.
    something is wrong with GetQueueStatus.

  8. #8

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [RESOLVED] [VB6] - instead api_doevents

    to be 100% honest, for now, i use C++ and not VB6. but i know about flickers, i said to you
    but maybe the GetQueueStatus() is more slow than Do_Events()?
    maybe is there another function more faster
    Moderator: Evertytime that i post i get the error that i must wait 30 seconds before post again... but the post is applied
    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
  •  



Click Here to Expand Forum to Full Width