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:
And here in my form I have: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
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




Reply With Quote
