보관물

‘MFC’ 카테고리의 보관물

AfxExtractSubString

6월 11, 2010 댓글 남기기

This global function can be used to extract a substring from a given source string.

BOOL AFXAPI AfxExtractSubString (
   CString& rString,
   LPCTSTR lpszFullString,
   int iSubString,
   TCHAR chSep = '\n'
);

  • Parameters
    • rString
      • Reference to a CString object that will receive an individual substring.
    • lpszFullString
      • String containing the full text of the string to extract from.
    • iSubString
      • Zero-based index of the substring to extract from lpszFullString.
    • chSep
      • Separator character used to delimit substrings.
  • Return Value
    • TRUE if the function successfully extracted the substring at the provided index; otherwise, FALSE.
  • Remarks
    • This function is useful for extracting multiple substrings from a source string when a known single character separates each substring. This function searches from the beginning of the lpszFullString parameter each time it is called. This function will return FALSE if either lpszFullString is set to NULL or the function reaches the end of lpszFullString without finding iSubString+1 occurrences of the specified separator character. The rString parameter will not be modified from its original value if lpszFullString was set to NULL; otherwise, the rString parameter is set to the empty string if the substring could not be extracted for the specified index.
  • Example
  • // The following example extracts a series of name, value pairs from a
    // given source string:
    
    // Input string consisting of a number of name, value pairs
    LPCTSTR lpszSource = _T("\"Name\"=\"John Smith\"\n")
    _T("\"Company\"=\"Contoso, Ltd\"\n\"Salary\"=\"25,000\"");
    
    CString strNameValue; // an individual name, value pair
    
    int i = 0; // substring index to extract
    while (AfxExtractSubString(strNameValue, lpszSource, i))
    {
    // Prepare to move to the next substring
    i++;
    
    CString strName, strValue; // individual name and value elements
    
    // Attempt to extract the name element from the pair
    if (!AfxExtractSubString(strName, strNameValue, 0, _T('=')))
    {
    // Pass an error message to the debugger for display
    OutputDebugString(_T("Error extracting name\r\n"));
    continue;
    }
    
    // Attempt to extract the value element from the pair
    if (!AfxExtractSubString(strValue, strNameValue, 1, _T('=')))
    {
    // Pass an error message to the debugger for display
    OutputDebugString(_T("Error extracting value element\r\n"));
    continue;
    }
    
    // Pass the name, value pair to the debugger for display
    CString strOutput = strName + _T(" equals ") + strValue + _T("\r\n");
    OutputDebugString(strOutput);
    }
    
카테고리:MFC

nate remote – hook

4월 14, 2010 댓글 남기기
카테고리:MFC

Skins in a Dialog-Based Application

1월 18, 2009 댓글 남기기

header file

CBitmap m_bmpMainBG;
int m_nMainWidth;
int m_nMainHeight;

InitDialog

// Main 배경 화면
BITMAP bmpInfo;								// 비트맵 정보
m_bmpMainBG.LoadBitmap(IDB_UNSPYCURE_BG2);	// Main 배경 이미지 Load
m_bmpMainBG.GetBitmap(&bmpInfo);			// Main 배경 비트맵 정보 읽기
m_nMainWidth = bmpInfo.bmWidth;				// Main 윈도우 폭
m_nMainHeight = bmpInfo.bmHeight;			// Main 윈도우 높이
SetWindowPos(NULL, 0, 0, m_nMainWidth, m_nMainHeight, 
			SWP_NOZORDER | SWP_NOMOVE);

OnPaint

// Main 배경 그림 그리기
CDC cdc;
cdc.CreateCompatibleDC(&dc);
cdc.SelectObject(m_bmpMainBG);
dc.BitBlt(0, 0, m_nMainWidth, m_nMainHeight, &cdc, 0, 0, SRCCOPY);
cdc.DeleteDC();

카테고리:MFC 태그:

Disable OnOK() automatic call(enter, esc, space)

1월 16, 2009 댓글 남기기

BOOL CDlg::PreTranslateMessage(MSG* pMsg)
{
	if(pMsg->message == WM_KEYDOWN)
	{
		switch(pMsg->wParam)
		{
		case VK_RETURN:
		case VK_ESCAPE:
		case VK_SPACE:
			::TranslateMessage(pMsg);
			::DispatchMessage(pMsg);
            return TRUE;
		}
	}

	return CDialog::PreTranslateMessage(pMsg);
} 

카테고리:MFC 태그:

Modeless dialog

1월 6, 2009 댓글 남기기

Create

m_pModalessDlg = new CModalessDlg(this);
m_pModalessDlg->Create(CModeless::IDD, this);

// Modalless.h
CWnd * m_pParent

// Modalless.cpp 
// Constructor
m_pParent = pParent;

Show

m_pModalessDlg->MoveWindow(rect);
m_pModalessDlg->ShowWindow( SW_SHOW );

Destroy

//Modalless.cpp
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)

void CModeless::OnBnClickedCancel()
{
	DestroyWindow(); 
}

void CModeless::PostNcDestroy()
{
	CDialog::PostNcDestroy();
	if(m_pParent)
	{  
		((CParentDialog*)m_pParent)->m_pmodeless = NULL;  
	}
	delete this;
}

카테고리:MFC 태그:
팔로우

모든 새 글을 수신함으로 전달 받으세요.