BUG: CTRL+C Does Not Copy Inside ActiveX Control (303319)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 5.5
  • Microsoft Internet Explorer (Programming) 5
  • Microsoft Internet Explorer (Programming) 5.01

This article was previously published under Q303319

SYMPTOMS

When you use the CTRL+C key combination to copy text inside of a TextBox control that is hosted on a Microsoft Visual Basic ActiveX control, no text is copied to the Clipboard. Other key combinations, such as CTRL+X (Cut), CTRL+Z (Undo), and CTRL+V (Paste), work as expected.

This problem is intermittent and may not always reproduce. Often, it does not reproduce if there are two or more ActiveX controls on the page. It also does not reproduce if you start Internet Explorer from the Visual Basic Integrated Development Environment (IDE). To reproduce this problem more consistently, delete Temporary Internet Files, and browse to the page.

CAUSE

When running under Internet Explorer, the TextBox control receives separate CTRL and C WM_KEYDOWN messages but never receives the WM_CHAR message for the control character (ASCII code 3).

RESOLUTION

To work around this problem, use the following code to simulate a button click on the container:

NOTE: This solution has only been verified to work with Internet Explorer and Visual Basic 6.0.
Option Explicit 

Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
   (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As _ 
Any) As Long  

Private Const WM_LBUTTONDOWN = &H201 
Private Const WM_LBUTTONUP = &H202  
Dim f As Boolean  

Private Sub UserControl_EnterFocus()    
    Dim h As Long    
    Dim i As Long    
    Dim hLast As Long    

    If f = False Then        
        h = UserControl.ContainerHwnd  ' Does not work with Visual Basic 5.0.  
        Call PostMessage(h, WM_LBUTTONDOWN, 0, ByVal 0)        
        Call PostMessage(h, WM_LBUTTONUP, 0, ByVal 0)       
        f = True    
    End If 
End Sub  

Private Sub UserControl_Show()    
    UserControl.Text1.SetFocus 
End Sub
				
NOTE: This workaround calls a Windows32 Application Programming Interface (API) in a Visual Basic application. If you use this API incorrectly, the application may stop responding (crash). Please make sure you save your project before you run and test your programs.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new ActiveX Control project in Visual Basic 6.0.
  2. Add a TextBox control from the ToolBox to your UserControl.
  3. Compile the control.
  4. Open OLE VIEW. Under Controls, click the ProgID of your UserControl, click Object, and then click Copy CLSID to Clipboard. The ProgID is <projectname>.<classname> (namely, Project1.UserControl1 in this example).
  5. Replace the CLSID in the <OBJECT> tag of the following HTML file, and save the file as testControlCopy.htm to your Web server. Alternatively, you can use the Package and Deployment Wizard (PDW) to package the control for you and then copy both the created .cab and .htm files to your Web server.
    <HTML>
    
    <BODY>
    
    <OBJECT CLASSID="CLSID:AB155E5E-EBF9-4485-9479-3A6308DE7CB6" Width="300" Height="300">
    </OBJECT>
    
    </BODY>
    
    </HTML>
    					
  6. In Internet Explorer, browse to this HTML page. Type some text, and then press CTRL+C to copy a portion of the text. Try to paste the copied text into the TextBox or into an open instance of Notepad. Notice that the text that you tried to copy does not paste.

REFERENCES

For more information about the PostMessage function, see the following Microsoft Web site: For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbbug kbCtrl kbnofix KB303319