Microsoft KB Archive/303319

= BUG: CTRL+C Does Not Copy Inside ActiveX Control =

Article ID: 303319

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer 5.5
 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Explorer 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 &quot;user32&quot; Alias &quot;PostMessageA&quot; _ (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.



Steps to Reproduce Behavior
 Create a new ActiveX Control project in Visual Basic 6.0. Add a TextBox control from the ToolBox to your UserControl. Compile the control. Open OLE VIEW. Under Controls, click the ProgID of your UserControl, click Object, and then click Copy CLSID to Clipboard. The ProgID is . (namely, Project1.UserControl1 in this example).</li>  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=&quot;CLSID:AB155E5E-EBF9-4485-9479-3A6308DE7CB6&quot; Width=&quot;300&quot; Height=&quot;300&quot;> </OBJECT>

</BODY>

</HTML> </li> 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.</li></ol>

<div class="references_section">