Results 1 to 16 of 16

Thread: How do I allow subclassing messages to occur during Do Loop without using DoEvents?

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    760

    How do I allow subclassing messages to occur during Do Loop without using DoEvents?

    Hello!

    I am using Ctrl + C to copy the currently selected text from an external application.

    I am using subclassing to be notified when the clipboard contents has changed and the text is present in the clipboard.

    Once WM_CHANGECBCHAIN is received, I check the clipboard's content.

    My current approach looks like this:

    Code:
    Call SendCtrlC()
    
    Dim lStart&
    lStart = GetTickCount()
    
    Do
        Dim lTaken&
        lTaken = GetTickCount() - lStart
    
        If lTaken > 3000 Then '3 seconds have passed. something must have gone wrong. Stop waiting for the clipboard change event
            Exit Do
        End If
    
        If (m_bCBChangeOccured) Then 'Does not work!
           'The problem is that m_bCBChangeOccured never becomes True in this loop! Because during the loop, we are not notified of the clipboard changes. Only if I use DoEvents, but I may not use DoEvents
           s = Clipboard.GetText()
           Exit Do
        End If
     
        'I can NOT use DoEvents() due to restrictions in coding standards which I have to follow
        'However, if I don't use DoEvents, I don't get the WM_CHANGECBCHAIN message
        'What could I do to let WM messages to occur within this loop?
    
    Loop
    And here in my form I have:

    Code:
    Private Sub iSubclass_WndProc(ByVal bBefore As Boolean, bHandled As Boolean, lReturn As Long, ByVal lng_hWnd As Long, ByVal uMsg As eMsg, ByVal wParam As Long, ByVal lParam As Long, lParamUser As Long)
       Select Case uMsg
       Case WM_CHANGECBCHAIN
          ' If the next viewer window is closing, repair the chain:
          m_hWndNextViewer = lParam
          If (m_hWndNextViewer <> 0) Then
             ' Otherwise if there is a next window, pass the message on:
             SendMessageByLong m_hWndNextViewer, uMsg, wParam, lParam
          End If
          lReturn = 0 'ISubclass_WindowProc = 0
            
       Case WM_DRAWCLIPBOARD
          ' the content of the clipboard has changed.
          ' We raise a ClipboardChanged message and pass the message on:
          m_bCBChangeOccured = True
          RaiseEvent ClipboardChanged
    
    (...)
    End Sub
    Last edited by tmighty2; Apr 21st, 2022 at 10:51 PM.

Tags for this Thread

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