cbtext.cpp

来自「VC++写的ping 的原码。」· C++ 代码 · 共 31 行

CPP
31
字号
#include "stdafx.h"
#include "cbtext.h"
#include <memory.h>

/* Code snippet to set clipboard text.
 * From "Developing Professional Applications for Windows 95
 * and Windows NT Using MFC" by Marshall Brain/ Lance Lovette */

BOOL CBText::SetText(CString s)
{
	HGLOBAL temp;
	CWinApp *app=AfxGetApp();
	CFrameWnd *fw=(CFrameWnd *)app->m_pMainWnd;
	LPTSTR str;

	if (!::OpenClipboard(fw->m_hWnd))
		return FALSE;
	::EmptyClipboard();
	temp = GlobalAlloc(GHND, s.GetLength()+1);
	if (temp == NULL)
	{
		CloseClipboard();
		return FALSE;
	}
	str=(char *)GlobalLock(temp);
	memcpy(str,LPCTSTR(s), s.GetLength()+1);
	GlobalUnlock((void *)temp);
	SetClipboardData(CF_TEXT,temp);
	CloseClipboard();
	return TRUE;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?