Click here to Skip to main content
15,896,154 members
Articles / Desktop Programming / WTL

AutoCompleteML - auto completion for multiline edit box

Rate me:
Please Sign up or sign in to vote.
3.80/5 (6 votes)
14 Oct 20044 min read 50.4K   1.6K   29  
COM object for easy user input in multiline edit boxes
#include "stdafx.h"
#include "resource.h"
#include "maindlg.h"

BOOL CMainDlg::UpdateACMLSettings(BOOL bLoad)
{
	BOOL bres = FALSE;

	CButton chkEnable(GetDlgItem(IDC_CHKENABLE));
	CButton chkAA(GetDlgItem(IDC_CHKAA));
	CButton chkAS(GetDlgItem(IDC_CHKAS));
	CButton chkAdd(GetDlgItem(IDC_CHKADD));
	CButton chkDel(GetDlgItem(IDC_CHKDEL));
	CButton chkUpdn(GetDlgItem(IDC_CHKUPDN));
	CButton chkTT(GetDlgItem(IDC_CHKTT));
	CEdit editLines(GetDlgItem(IDC_EDITLINES));

	try {

		if (bLoad) {

			if (m_spac->Enabled == VARIANT_TRUE) chkEnable.SetCheck(1); else chkEnable.SetCheck(0);

			ACMPLLib::ACMLFlags acmlopts = m_spac->Options;
			chkAA.SetCheck(acmlopts & ACMPLLib::ACML_AutoAppend);
			chkAS.SetCheck(acmlopts & ACMPLLib::ACML_AutoSuggest);
			chkAdd.SetCheck(acmlopts & ACMPLLib::ACML_EnableUserAutoAdd);
			chkDel.SetCheck(acmlopts & ACMPLLib::ACML_EnableUserDelete);
			chkUpdn.SetCheck(acmlopts & ACMPLLib::ACML_UpDownKeyDropList);
			chkTT.SetCheck(acmlopts & ACMPLLib::ACML_ToolTip);

			CString slines;
			slines.Format( "%d", m_spac->ItemMaxLines );
			editLines.SetWindowText(slines);

		} else {

			m_spac->Enabled = chkEnable.GetCheck() ? VARIANT_TRUE : VARIANT_FALSE;

			long acmlopts=0;
			acmlopts |= chkAA.GetCheck() ? ACMPLLib::ACML_AutoAppend : 0;
			acmlopts |= chkAS.GetCheck() ? ACMPLLib::ACML_AutoSuggest : 0;
			acmlopts |= chkAdd.GetCheck() ? ACMPLLib::ACML_EnableUserAutoAdd : 0;
			acmlopts |= chkDel.GetCheck() ? ACMPLLib::ACML_EnableUserDelete : 0;
			acmlopts |= chkUpdn.GetCheck() ? ACMPLLib::ACML_UpDownKeyDropList : 0;
			acmlopts |= chkTT.GetCheck() ? ACMPLLib::ACML_ToolTip : 0;
			m_spac->Options = (ACMPLLib::ACMLFlags)acmlopts;

			CString slines;
			editLines.GetWindowText( slines.GetBuffer(10), 11 );
			slines.ReleaseBuffer();
			if (slines.GetLength() > 0) {
				long llines = _ttol(slines);
				m_spac->ItemMaxLines = llines;
			}

		}

		bres = TRUE;
	}
	catch (_com_error&) {}

	return bres;
}


LRESULT CMainDlg::OnClickedBtninit(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	try {

		USES_CONVERSION;

		const char* crlf = "\r\n";

		m_spStrings->Clear();

		// generate multiline items
		CString str;
		for (int i=0; i<10; i++) {
			int ilines = 1 + 6 * rand() / RAND_MAX;

			CString strSublines, strSubline;
			for (int il=1; il<ilines; il++) {
				//strSubline = CString( _T('a'), il );
				strSubline.Format("line number %d", il+1 );
				strSublines += crlf;
				strSublines += strSubline;
			}

			CString strx( _T('a'), i+1 );
			str.Format("%s (%d lines)%s%s", strx, ilines, "", strSublines );

			m_spStrings->Add((LPCTSTR)str, 0);

		}

	}
	catch (_com_error&) {}
	return 0;
}

LRESULT CMainDlg::OnClickedBtnload(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	try {
		m_spStrings->LoadXML(L"acml.xml");
	}
	catch (_com_error&) {}
	return 0;
}

LRESULT CMainDlg::OnClickedBtnsave(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	try {
		m_spStrings->SaveXML(L"acml.xml");
		::ShellExecute( 0, "open", "acml.xml", 0,0,SW_SHOW );
	}
	catch (_com_error&) {}
	return 0;
}

LRESULT CMainDlg::OnClickedBtnload2(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	try {
		_variant_t vsrc((LPDISPATCH)m_spdoc->documentElement);
		m_spStrings->LoadXML(vsrc);
	}
	catch (_com_error&) {}
	return 0;
}

LRESULT CMainDlg::OnClickedBtnsave2(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	try {
		_variant_t vdst((LPDISPATCH)m_spdoc->documentElement);
		_bstr_t bsdoc = m_spdoc->xml;
		m_spStrings->SaveXML(vdst);
		bsdoc = m_spdoc->xml;
		MessageBox(bsdoc, "autocompletion strings");
	}
	catch (_com_error&) {}
	return 0;
}

LRESULT CMainDlg::OnClickedBtnload3(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	try {
		m_spStrings->LoadPrivateProfile( L".\\acml.ini", L"field1" );
	}
	catch (_com_error&) {}
	return 0;
}

LRESULT CMainDlg::OnClickedBtnsave3(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	try {
		m_spStrings->SavePrivateProfile( L".\\acml.ini", L"field1" );
		::ShellExecute( 0, "open", "acml.ini", 0,0,SW_SHOW );
	}
	catch (_com_error&) {}
	return 0;
}

LRESULT CMainDlg::OnHScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	if (LOWORD(wParam) == TB_THUMBTRACK) {
		WORD wPos = HIWORD(wParam);
		CRect rc;
		m_editml.GetWindowRect(rc);
		ScreenToClient(rc);
		rc.right = rc.left + wPos;
		m_editml.SetWindowPos( 0, rc, SWP_NOZORDER|SWP_NOMOVE );
	}
	return 0;
}

LRESULT CMainDlg::OnVScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	if (LOWORD(wParam) == TB_THUMBTRACK) {
		WORD wPos = HIWORD(wParam);
		CRect rc;
		m_editml.GetWindowRect(rc);
		ScreenToClient(rc);
		rc.bottom = rc.top + wPos;
		m_editml.SetWindowPos( 0, rc, SWP_NOZORDER|SWP_NOMOVE );
	}
	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions