CEdit::SetHandle

Call this function to set the handle to the local memory that will be used by a multiple-line edit control.

void SetHandle(
   HLOCAL hBuffer 
);

Parameters

  • hBuffer
    Contains a handle to the local memory. This handle must have been created by a previous call to the LocalAlloc Windows function using the LMEM_MOVEABLE flag. The memory is assumed to contain a null-terminated string. If this is not the case, the first byte of the allocated memory should be set to 0.

Remarks

The edit control will then use this buffer to store the currently displayed text instead of allocating its own buffer.

This member function is processed only by multiple-line edit controls.

Before an application sets a new memory handle, it should use the GetHandle member function to get the handle to the current memory buffer and free that memory using the LocalFree Windows function.

SetHandle clears the undo buffer (the CanUndo member function then returns 0) and the internal modification flag (the GetModify member function then returns 0). The edit-control window is redrawn.

You can use this member function in a multiple-line edit control in a dialog box only if you have created the dialog box with the DS_LOCALEDIT style flag set.

Note

GetHandle will not work with Windows 95/98. If you call GetHandle in Windows 95/98, it will return NULL. GetHandle will work as documented under Windows NT, versions 3.51 and later.

For more information, see EM_SETHANDLE, LocalAlloc, and LocalFree in the Windows SDK.

Example

// The string to set in the edit control.
CString strString(_T("George Frideric"));

// Initialize the new local handle.
size_t cbSize = (strString.GetLength() + 1) * sizeof(TCHAR);
HLOCAL h = ::LocalAlloc(LHND, cbSize);
LPTSTR lpszText = (LPTSTR) ::LocalLock(h);
_tcsncpy_s(lpszText, cbSize / sizeof(TCHAR), strString, _TRUNCATE);
::LocalUnlock(h);

// Free the current text handle of the edit control.
::LocalFree(m_myEdit.GetHandle());

// Set the new text handle.
m_myEdit.SetHandle(h);

Requirements

Header: afxwin.h

See Also

Reference

CEdit Class

Hierarchy Chart

CEdit::CanUndo

CEdit::GetHandle

CEdit::GetModify

Other Resources

CEdit Members