본문 바로가기
개발언어/C++

GetWindowText 함수의 용도

by 엔돌슨 2010. 5. 26.
반응형
GetWindowText 함수

사용의 예)

1 const nBuffSize = 512;                              // 버퍼의 사이즈를 정한다.
2 char szBuff[nBuffSize], buf2[nBuffSize];   // 버퍼공간을 선언한다.
3 m_wndResiNo1Edit.GetWindowText(szBuff, nBuffSize); //해당컨트롤 변수의 메소드로 가지고 있는 문자열을 받는다.
4 m_wndResiNo2Edit.GetWindowText(buf2, nBuffSize);   //컨트롤변수로 해당 버퍼로 문자열을 가져온다.

영어로 된거 읽어라. MSDN  보다 좋은거는 없다. 영어공부도 하고 얼마나 좋냐~


CWnd::GetWindowText

This method copies the CWnd caption title into the buffer pointed to by lpszStringBuf or into the destination string rString. If the CWnd object is a control, the GetWindowText method copies the text within the control instead of copying the caption.

This method causes the WM_GETTEXT message to be sent to the CWnd object.

int GetWindowText( 
LPTSTR lpszStringBuf, 
int nMaxCount ) 
const; 

void GetWindowText( 
CString& rString ) 
const; 

Parameters

lpszStringBuf
Points to the buffer that is to receive the copied string of the window title.
nMaxCount
Specifies the maximum number of characters to be copied to the buffer. If the string is longer than the number of characters specified in nMaxCount, it is truncated.
rString
Specifies a CString object that is to receive the copied string of the window title.

Return Value

Specifies the length, in bytes, of the copied string, not including the terminating null character. It is 0 if CWnd has no caption or if the caption is empty.

Example

This is the example from the CWnd::SetWindowText method.

// Set the text in IDC_MYEDIT.
CWnd* pWnd = GetDlgItem(IDC_MYEDIT);
pWnd->SetWindowText(_T("Hockey is best!"));

// Get the text back. CString is convenient, because MFC
// will automatically allocate enough memory to hold the
// text--no matter how large it is.

CString str;
pWnd->GetWindowText(str);
ASSERT(str == _T("Hockey is best!"));

// The LPTSTR override works, too, but it might be too short.
// If we supply a buffer that is too small, we will only get those
// characters that fit.

TCHAR sz[10];
int nRet = pWnd->GetWindowText(sz, 10);

// Nine characters, plus terminating null.
ASSERT(lstrcmp(sz, _T("Hockey is")) == 0);
ASSERT(nRet == 9);

// You can query the length of the text without the length of
// the string using CWnd::GetWindowTextLength().
nRet = pWnd->GetWindowTextLength();
ASSERT(nRet == 15);

Requirements

  Windows CE versions: 1.0 and later
  Header file: Declared in Afxwin.h
  Platform: H/PC Pro, Palm-size PC, Pocket PC

See Also

CWnd::SetWindowText, CWnd::GetWindowTextLength