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.
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. 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: | Major | Last Reviewed: | 5/11/2006 |
---|
Keywords: | kbbug kbCtrl kbnofix KB303319 |
---|
|