I need to create unfocusable form in C#. On that form there will be button. After pressing that button I want to paste content of System.Clipboard to the place where the cursot is. This is what I have till now:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const int WS_EX_NOACTIVATE = 0x08000000;
const int WS_EX_TOPMOST = 0x00000008;
const int WS_EX_TOOLWINDOW = 0x00000080;
const int WM_MOUSEACTIVATE = 0x0021;
const int WS_EX_WINDOWEDGE = 0x00000100;
const int MA_NOACTIVATEANDEAT = 4;
const int WM_NCHITTEST = 0x0084;
//const int WM_ACTIVATEAPP = 0x001C;
const int WS_THICKFRAME = 0x00040000;
const int WS_CHILD = 0x40000000;
const int WS_BORDER = 0x00800000;
const int WS_DLGFRAME = 0x00400000;
const int WS_CAPTION = WS_BORDER | WS_DLGFRAME;
const int WS_SYSMENU = 0x00080000;
protected override bool ShowWithoutActivation { get { return true; } }
protected override CreateParams CreateParams
{
get
{
CreateParams ret = base.CreateParams;
ret.Style = WS_THICKFRAME |
WS_CHILD |
WS_CAPTION |
WS_SYSMENU;
ret.ExStyle |= WS_EX_NOACTIVATE |
WS_EX_TOOLWINDOW |
WS_EX_TOPMOST |
WS_EX_WINDOWEDGE;
ret.X = this.Location.X;
ret.Y = this.Location.Y;
return ret;
}
}
private void simpleButton1_Click(object sender, EventArgs e)
{
Clipboard.SetText("text1 text2");
SendKeys.SendWait("^v");
}
}
The form is not the main form of my application. The code works only if the focus is in my application. If I focus notepad or any other program clipboard content is not pasted to it. Any one can help with this?