когда я закрываю свою программу, она выполнит мой последний clipboard.gettext, когда я вставлю ее. Я хочу, когда я закрываю программу, которая больше не выполняет эту последнюю команду clipboard.gettext.
Я уже пытался закодировать этот код в моем wndproc, но это мне больше не помогло:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
ChangeClipboardChain(this.Handle, _clipboardViewerNext); // Removes our from the chain of clipboard viewers when the form closes.
}
А это код
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer);
private IntPtr _ClipboardViewerNext;
//Make some global variables so we can access them somewhere else later
//This will store all Questions and Answers
//In here will be the Questions and Answers
List<question> questionList = new List<question>();
// Demonstrates SetText, ContainsText, and GetText.
private void Form1_Load(object sender, EventArgs e)
{
//Set our application as a clipboard viewer
_ClipboardViewerNext = SetClipboardViewer(Handle);
this.FormClosing += Form1_FormClosing;
//Add question/answer to list
//hoofdstuk 3 it
question newQuestion = new question("wat is de hoofdstad van nederland?", "Amsterdam.*");
}
private void GetAnswer(string clipboardText)
{
//Loop through all questions and answers
foreach (question q in questionList)
{
//If we have found an answer that is exactly the same show an Notification
if (q._question == clipboardText)
{
ShowNotification(q._question, q._answer);
}
}
}
private void ShowNotification(string question, string answer)
{
notifyIcon1.Icon = SystemIcons.Exclamation;
notifyIcon1.BalloonTipTitle = question;
notifyIcon1.BalloonTipText = answer;
notifyIcon1.BalloonTipIcon = ToolTipIcon.Error;
Clipboard.Clear();
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
{
const int WM_DRAWCLIPBOARD = 0x308;
if (m.Msg == WM_DRAWCLIPBOARD)
{
GetAnswer(Clipboard.GetText(TextDataFormat.UnicodeText));
}
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Clipboard.Clear();
}
}
}
Заранее спасибо.