클립 보드를 잘못 생각한 것 같습니다. 그러나 이것을 구현하는 방법을 알고 싶거나 팁을 얻고 싶습니다. 이 프로그램을 백그라운드에서 실행시키고 싶을 때마다 프로그램에서 끝나는 무언가를 복사 할 때마다. 그렇게하면 10 분 전에 내가 뭘 복사했는지 시간에 맞추어 다시보고 싶으면 프로그램에서 찾을 것입니다. 그래서 나는 그것을 텍스트 파일에 저장해야한다고 생각한다. 어떻게 구현할 수 있습니까?ctrl + c를 눌러 texbox에 저장하십시오.
답변
클립 보드가 변경되면 일반적으로 C#이 이벤트를 발생시킬 수 없습니다. 클립 보드에서 데이터를 읽을 수 있으며, 클립 보드를 폴링하는 동안 기다릴 수는 있지만, 나에게 적합하지 않은 것으로 보입니다.
그러나 조금씩 extern
사용법을 사용하면 원하는 것을 얻을 수 있습니다. Form
을 하위 클래스 클래스에서 :
/// <summary>
/// Message id for data being copied to the clipboard
/// </summary>
/// <value>776</value>
private const int WM_DRAWCLIPBOARD = 0x0308;
/// <summary>
/// Message id for a window being removed from the viewer chain
/// </summary>
/// <value>781</value>
private const int WM_CHANGECBCHAIN = 0x030D;
/// <summary>
/// Message id for the window being destroyed
/// </summary>
/// <value>2</value>
private const int WM_DESTROY = 0x0002;
/// <summary>
/// The next window in the clipboard viewer chain
/// </summary>
private IntPtr nextClipboardViewer;
/// <summary>
/// Adds the specified window to the chain of clipboard viewers. Clipboard viewer windows receive a <c>WM_DRAWCLIPBOARD</c>
/// message whenever the content of the clipboard changes.
/// </summary>
/// <param name="hWnd">A handle to the window to be added to the clipboard chain.</param>
/// <returns>If the function succeeds, the return value identifies the next window in the clipboard viewer chain. If an
/// error occurs or there are no other windows in the clipboard viewer chain, the return value is <c>null</c>.</returns>
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SetClipboardViewer(IntPtr hWnd);
/// <summary>
/// Removes a specified window from the chain of clipboard viewers.
/// </summary>
/// <param name="hWndRemove">A handle to the window to be removed from the chain. The handle must have been passed to the
/// <see cref="SetClipboardViewer"/> function.</param>
/// <param name="hWndNewNext">A handle to the window that follows the <paramref name="hWndRemove"/> window in the clipboard
/// viewer chain. (This is the handle returned by <see cref="SetClipboardViewer"/>, unless the sequence was changed in response
/// to a <c>WM_CHANGECBCHAIN</c> message.)</param>
/// <returns>The return value indicates the result of passing the <c>WM_CHANGECBCHAIN</c> message to the windows in the
/// clipboard viewer chain. Because a window in the chain typically returns <c>false</c> when it processes <c>WM_CHANGECBCHAIN</c>,
/// the return value from <see cref="ChangeClipboardChain"/> is typically <c>false</c>. If there is only one window in the chain,
/// the return value is typically <c>true</c>.</returns>
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern bool ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);
/// <summary>
/// Sends the specified message to a window or windows. The <c>SendMessage</c> function calls the window
/// procedure for the specified window and does not return until the window procedure has processed the message.
/// </summary>
/// <param name="hwnd">A handle to the window whose window procedure will receive the message.</param>
/// <param name="wMsg">The message to be sent.</param>
/// <param name="wParam">Additional message-specific information.</param>
/// <param name="lParam">Additional message-specific information.</param>
/// <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
/// <inheritdoc/>
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_DRAWCLIPBOARD)
{
// The user copied something to the clipboard
IDataObject clipData = Clipboard.GetDataObject();
if (clipData.GetDataPresent(DataFormats.Text))
{
// Copied data is text
}
SendMessage(nextClipboardViewer, m.Msg, m.WParam, m.LParam);
}
// Handle necessary native clipboard stuff
else if (m.Msg == WM_DESTROY)
{
// Remove MyForm from the clipboard chain
ChangeClipboardChain(this.Handle, nextClipboardViewer);
}
else if (m.Msg == WM_CHANGECBCHAIN)
{
if (m.WParam == nextClipboardViewer)
{
nextClipboardViewer = m.LParam;
}
else
{
SendMessage(nextClipboardViewer, m.Msg, m.WParam, m.LParam);
}
}
else
{
base.WndProc(ref m);
}
}
private void MyForm_Load(object sender, EventArgs e)
{
// Include MyForm in the clipboard chain
nextClipboardViewer = SetClipboardViewer(this.Handle);
}
는 MyForm_Load
(대부분 쉽게 디자이너 창에서)을 Form
에 적절한 이벤트로 추가되어 있는지 확인합니다.
작은 메모. WndProc()에서 WM_DESTROY를 트래핑하고 거기에있는 체인에서 자신을 제거하면 FormClosing() 이벤트를 구독 할 필요가 없습니다. –
잘 알고 있습니다. 나는이 코드를 필자가 작성한 기존 응용 프로그램에서 가져와 관련없는 비트를 제거했다. 내 응용 프로그램에서는'_Load' 및'_FormClosing' _anyway_에서 다른 작업을하고 있습니다. WM_DESTROY의 가치는 무엇입니까? –
'private const int WM_DESTROY = 0x2;' –
- 1. ctrl-c를 무시합니다.
- 2. ctrl + c를 반복해서 누르는 지점이 있습니까?
- 3. PreTranslateMessage에서 Ctrl + C를 누르면 Ctrl + R 메시지 수신
- 4. Ctrl + C를 두 번 눌러야합니다 : w
- 5. 델파이에서 Ctrl + c를 시뮬레이트하는 방법
- 6. Simthon Ctrl-C를 파이썬 스크립트
- 7. Ctrl-C를 방해하지 않는 semaphore.acquire
- 8. 만들려면 Ctrl-C를, 인 IntelliJ
- 9. CTRL-C를 눌러 업데이트를 중지하고 GAE를 업데이트합니다. 지금 : 트랜잭션은 이미 진행 중이지만 롤백은 불가능합니다.
- 10. vba 엑셀 복사본 만 키를 눌렀을 때 표시되는 셀 Ctrl + c를 눌러 보호 된 시트
- 11. 사용자가 Ctrl + C를 눌러 종료하기 전에 명령을 수행하는 경우 일괄 처리 스크립트
- 12. ctrl-c를 잡고 사용자에게 확인하도록 요청하는 방법이 있습니까?
- 13. 프로그램을 종료하기 위해 Ctrl-c를 만드는 방법
- 14. 쉘 스크립트에서 Ctrl + C를 복제하는 방법은 무엇입니까?
- 15. Python : 결과를 얻으려면 Ctrl + C를 누르십시오.
- 16. 콘솔에서 Ctrl + C를 입력으로받을 수 있습니까?
- 17. C#은 자식 프로세스에 ctrl-c를 방지합니다.
- 18. 쉘 스크립트에서 ctrl + C를 제공하는 방법은 무엇입니까?
- 19. ctrl + c를 누를 때 스레드의 호출 취소
- 20. Java에서 열기 위해 Ctrl-C를 보내십시오.
- 21. Ctrl + C를 잡은 후 종료하는 방법은 무엇입니까?
- 22. ganymed SSH2를 사용하여 SIGINT CTRL-C를 보내시겠습니까?
- 23. scp 도중 CTRL-C를 비활성화하는 방법?
- 24. ZeroMQ : Windows에서 Ctrl-C를 처리하는 방법
- 25. Qt를 사용하여 Windows 및 Linux에서 Ctrl + C를 잡는 방법
- 26. 사용자가 CTRL C를 누르거나 키보드 Interupt를 사용하면 메시지를 표시하는 방법? 나는 그 다음이 실행 된 어떤 라인을 표시하고 프로그램을 실행하고 때 나는 CTRL-C를 눌러
- 27. 콘솔을 잃지 않고 ctrl C를 잡을 수있는 방법은 무엇입니까?
- 28. 바로 가기 키를 눌러 저장하고 인쇄하기위한 코드 활성화 ctrl + p
- 29. XML 파일 인 경우에도 Ctrl + F11을 눌러 Android 프로젝트를 시작하십시오.
- 30. 처음로드시 Firefox에서 이미지를 캔버스에 그리거나 Ctrl + F5를 눌러 다시로드하지 마십시오.
이 질문은 너무 지저분 :)) 자신을 삭제하는 것이 가장 좋은 방법이며, 두 번째로 좋은 방법은 그것을 개선하는 것입니다. –
그 프로그램은 클립 보드에있는 내용을 지속적으로 폴링해야합니다. 또한 비 텍스트 콘텐츠를 준비해야합니다. 가능해야합니다. –
이미 이렇게하는 일부 오픈 소스 프로그램을 확인하십시오. http://ditto-cp.sourceforge.net/ –