MFC Clipboard

From Mesdoc

http://netez.com/2xExplorer/shellFAQ/adv_clip.html

Here is a MFC example using these functions from tutorial: BOOL SetClipboardText(LPCTSTR pszText) int GetClipboardText(LPTSTR pszBuf, int nLength)

1. Create 2 push button controls IDC_PUT; // push button control IDC_GET; // push button control

2. Create 3 edit box controls IDC_EDIT_PUT; // edit box control IDC_EDIT_GET; // edit box control IDC_EDIT_STATUS; // edit box control

3. Create 3 Member Variables for edit box controls CString m_get; // string associated with IDC_EDIT_GET edit box CString m_put; // string associated with IDC_EDIT_PUT edit box CString m_status; // string associated with IDC_EDIT_STATUS edit box

4. Test the program a. Type text into IDC_EDIT_PUT edit box b. Click on IDC_PUT push button c. Status appears in IDC_EDIT_STATUS edit box d. Click on IDC_GET push button e. Status appears in IDC_EDIT_STATUS edit box f. Text from clipboard appears in IDC_EDIT_GET edit box

// Function for clicking on IDC_PUT push button void CTestClipboardDlg::OnPut() { BOOL success; UpdateData(TRUE); success = SetClipboardText(LPCTSTR(m_put));

if (success) m_status = "Put Success"; else m_status = "Put Failure"; UpdateData(FALSE); }

// Function for clicking on IDC_GET push button void CTestClipboardDlg::OnGet() { int result; char buf[80]; int len = 80; result = GetClipboardText(buf, len); if (result>0) { m_status = "Get Success"; m_get = CString(buf); } else m_status = "Get Failure"; UpdateData(FALSE); }

Personal tools