Hi everyone,
We are having issues with getting a "paste" event being sent up a hierarchy to the parent form.
Using WinXP Sp3,VS 2005 Professional, and .NET 2.0 for development.
We have an application that comprised of multiple solution files which we've inherited. Solution #2 houses all our custom controls. When built, the dll is used as a reference in Solution #4 so those controls can be placed on our multiple forms.
We have a special DoPaste Method in solution #4 which we call whenever a "paste" event happens from a form within Solution #4. This functions perfectly whenever we select "Edit | Paste" from the menu, or use CTRL-V (we just call the menu's paste event).
However, there's also a context menu which allows a user to right-click and paste text into the custom controls. Unfortunately, it's pasting "blanks".
What we want to do is when a user right-clicks to paste, have that bubble up to the forms in Solution #4.
In the custom textbox control in Solution #2, we have the following code:
private const int WM_PASTE = 0x0302;
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SendMessage(
int hWnd, // handle to destination window
uint Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);
/// <summary>
/// Override WndProc Method : Capture pasting
/// </summary>
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_PASTE:
{
SendMessage((int)Parent.Handle, Convert.ToUInt32(WM_PASTE), WM_PASTE, WM_PASTE);
//Have also tried sending to this.Handle instead of Parent.Handle
SendMessage((int)Parent.Handle, Convert.ToUInt32(WM_PASTE), WM_PASTE, WM_PASTE);
break;
}
default:
{
base.WndProc(ref m);
break;
}
}
}
This seems to work as tracing through it the SendMessage routine is called.
In Solution #4, we have the following code, which doesn't seem to ever receive the WM_PASTE message if we step through it message by message:
// Pasting
private const int WM_PASTE = 0x0302;
/// <summary>
/// Override WndProc Method : Capture Pasting into ABC123 Text Box
/// </summary>
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_PASTE:
{
DoPaste();
break;
}
default:
{
base.WndProc(ref m);
break;
}
}
}
Questions are:
1) Is this the correct way to do it?
2) If not, what is the correct (or better) way?
3) If so, why wouldthis not be working?
Thanks!