Ejemplo n.º 1
0
//=============================================================================	
int _cdecl CXListBox::Printf(Color tc, Color bc, UINT nID, LPCTSTR lpszFmt, ...)
//=============================================================================	
{
	AFX_MANAGE_STATE(AFXMANAGESTATE())

	TCHAR buf[2048], fmt[1024];
	va_list marker;

	// load format string from string resource if
	// a resource ID was specified
	if (nID)
	{
		CString s = _T("");
		if (!s.LoadString(nID))
		{
			_stprintf(s.GetBufferSetLength(80), _T("Failed to load string resource %u"),
				nID);
			s.ReleaseBuffer(-1);
		}
		_tcsncpy(fmt, s, sizeof(fmt)/sizeof(TCHAR)-1);
	}
	else
	{
		// format string was passed as parameter
		_tcsncpy(fmt, lpszFmt, sizeof(fmt)/sizeof(TCHAR)-1);
	}
	fmt[sizeof(fmt)/sizeof(TCHAR)-1] = 0;

	// combine output string and variables
	va_start(marker, lpszFmt);
	_vsntprintf(buf, (sizeof(buf)/sizeof(TCHAR))-1, fmt, marker);
	va_end(marker);
	buf[sizeof(buf)/sizeof(TCHAR)-1] = 0;

	return AddLine(tc, bc, buf);
}
//=============================================================================
// DoModal override copied mostly from MFC, with modification to use
// m_ofnEx instead of m_ofn.
INT_PTR CXFolderDialog::DoModal()
//=============================================================================
{
	TRACE(_T("in CXFolderDialog::DoModal\n"));

	ASSERT_VALID(this);
	ASSERT(m_ofn.Flags & OFN_ENABLEHOOK);
	ASSERT(m_ofn.lpfnHook != NULL); // can still be a user hook

	AFX_MANAGE_STATE(AFXMANAGESTATE())

	m_bFirstTime = TRUE;

	m_wndListView.Init(this);

	// zero out the file buffer for consistent parsing later
	TCHAR * pBuf = new TCHAR [m_ofn.nMaxFile + 100];
	memset(pBuf, 0, (m_ofn.nMaxFile + 100) * sizeof(TCHAR));
	if (m_ofn.lpstrFile)
	{
		// copy file buffer
		_tcsncpy(pBuf, m_ofn.lpstrFile, m_ofn.nMaxFile);
		// zero out file buffer in OPENFILENAME struct
		memset(m_ofn.lpstrFile, 0, m_ofn.nMaxFile*sizeof(TCHAR));
		// restore copied file buffer
		_tcsncpy(m_ofn.lpstrFile, pBuf, m_ofn.nMaxFile);
	}
	if (pBuf)
		delete [] pBuf;
	pBuf = NULL;

	// WINBUG: This is a special case for the file open/save dialog,
	// which sometimes pumps while it is coming up but before it has
	// disabled the main window.
	HWND hWndFocus = ::GetFocus();
	BOOL bEnableParent = FALSE;
	m_ofn.hwndOwner = PreModal();
	AfxUnhookWindowCreate();
	if (m_ofn.hwndOwner != NULL && ::IsWindowEnabled(m_ofn.hwndOwner))
	{
		bEnableParent = TRUE;
		::EnableWindow(m_ofn.hwndOwner, FALSE);
	}

	_AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
	ASSERT(pThreadState->m_pAlternateWndInit == NULL);

	if (m_ofn.Flags & OFN_EXPLORER)
		pThreadState->m_pAlternateWndInit = this;
	else
		AfxHookWindowCreate(this);

	memset(&m_ofnEx, 0, sizeof(m_ofnEx));
	memcpy(&m_ofnEx, &m_ofn, sizeof(m_ofn));
	if (m_ofnEx.hInstance == 0)
		m_ofnEx.hInstance = AfxGetInstanceHandle();

	m_ofnEx.Flags |= OFN_ENABLESIZING;

#if (_WIN32_WINNT >= 0x0500)

	TRACE(_T("_WIN32_WINNT=0x%X\n"), _WIN32_WINNT);

	#pragma message(__FILE__ "(" makestring(__LINE__) \
		") : OPENFILENAME is large size (3 extra items are included)")

	if (IsWin2000())
		m_ofnEx.lStructSize = sizeof(OPENFILENAME);				// OS >= 2000, force to large size
	else
		m_ofnEx.lStructSize = OPENFILENAME_SIZE_VERSION_400;	// use small size

#else	// _WIN32_WINNT < 0x0500, or isn't defined

	#pragma message(__FILE__ "(" makestring(__LINE__) \
		") : OPENFILENAME is small size (3 extra items are NOT included)")

	if (IsWin2000())
		m_ofnEx.lStructSize = sizeof(OPENFILENAMEEX_FOLDER);			// OS >= 2000, force to large size
	else
		m_ofnEx.lStructSize = OPENFILENAME_SIZE_VERSION_400;	// use small size

#endif

	m_ofnEx.lpstrInitialDir = m_strInitialFolder;
	//m_ofnEx.lpstrFilter = m_strFilter;

	int nResult = 0;
	if (m_bOpenFileDialog)
		nResult = ::GetOpenFileName((OPENFILENAME*)&m_ofnEx);
	else
		nResult = ::GetSaveFileName((OPENFILENAME*)&m_ofnEx);

	memcpy(&m_ofn, &m_ofnEx, sizeof(m_ofn));
	m_ofn.lStructSize = sizeof(m_ofn);

	if (nResult)
	{
		ASSERT(pThreadState->m_pAlternateWndInit == NULL);
	}
	pThreadState->m_pAlternateWndInit = NULL;

	// WINBUG: Second part of special case for file open/save dialog.
	if (bEnableParent)
		::EnableWindow(m_ofnEx.hwndOwner, TRUE);
	if (::IsWindow(hWndFocus))
		::SetFocus(hWndFocus);

	PostModal();

	return nResult ? nResult : IDCANCEL;
}