This sample illustrates autocomplete.
The source code is located at C:\Program Files (x86)\Softelvdm\SftMask OCX 8.0\Samples\VC++\Sample2\Sample2Dlg.cpp.
// Sample2Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Sample2.h"
#include "Sample2Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSample2Dlg dialog
CSample2Dlg::CSample2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CSample2Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSample2Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSample2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSample2Dlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSample2Dlg, CDialog)
//{{AFX_MSG_MAP(CSample2Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSample2Dlg message handlers
BOOL CSample2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
SftDarkMode_ApplyToDialog(m_hWnd);
for (CWnd* pWnd = GetWindow(GW_CHILD); pWnd != NULL; pWnd = pWnd->GetWindow(GW_HWNDNEXT)) {
ISftMaskPtr pMask(pWnd->GetControlUnknown());
if (pMask != NULL) {
pMask->DarkMode = darkSftMaskAuto; // follow the Windows dark mode setting
pMask->HighContrastMode = highContrastSftMaskAuto; // follow the Windows High Contrast setting
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_vMask1 = GetDlgItem(IDC_SFTMASK1)->GetControlUnknown();
ASSERT(m_vMask1 != NULL);
m_vMask2 = GetDlgItem(IDC_SFTMASK2)->GetControlUnknown();
ASSERT(m_vMask2 != NULL);
m_vMask3 = GetDlgItem(IDC_SFTMASK3)->GetControlUnknown();
ASSERT(m_vMask3 != NULL);
m_vMaskFiles1 = GetDlgItem(IDC_SFTMASKFILES1)->GetControlUnknown();
ASSERT(m_vMaskFiles1 != NULL);
m_vMaskFiles2 = GetDlgItem(IDC_SFTMASKFILES2)->GetControlUnknown();
ASSERT(m_vMaskFiles2 != NULL);
// Offer city names the first time the sample runs. The "-" prefix stores the file in the user's application data folder.
SeedCities(m_vMask1, L"-\\Softelvdm\\SftMask OCX 8.0\\Sample2\\Cities1.autocomplete");
SeedCities(m_vMask2, L"-\\Softelvdm\\SftMask OCX 8.0\\Sample2\\Cities2.autocomplete");
SeedCities(m_vMask3, L"-\\Softelvdm\\SftMask OCX 8.0\\Sample2\\Cities3.autocomplete");
return TRUE; // return TRUE unless you set the focus to a control
}
void CSample2Dlg::SeedCities(ISftMaskPtr pMask, LPCWSTR lpszFile)
{
static LPCWSTR aCities[] = {
L"Albuquerque", L"Atlanta", L"Austin", L"Baltimore", L"Boston", L"Charlotte", L"Chicago", L"Dallas", L"Denver", L"Detroit",
L"Houston", L"Las Vegas", L"Los Angeles", L"Miami", L"Nashville", L"New Orleans", L"New York", L"Oakland", L"Ocala",
L"Oklahoma City", L"Omaha", L"Orange Park", L"Oregon City", L"Orlando", L"Oxford", L"Philadelphia", L"Phoenix", L"Portland",
L"San Diego", L"San Francisco", L"Seattle", L"Tampa"
};
const long count = (long) (sizeof(aCities) / sizeof(aCities[0]));
// the Seed method takes a one-dimensional array of strings
COleSafeArray saCities;
saCities.CreateOneDim(VT_BSTR, count);
for (long i = 0; i < count; ++i) {
BSTR bstr = ::SysAllocString(aCities[i]);
saCities.PutElement(&i, bstr);
::SysFreeString(bstr);
}
_variant_t vCities;
vCities.Attach(saCities.Detach());
ISftMaskAutoCompletePtr pAutoComplete = pMask->GetAutoComplete();
pAutoComplete->File = lpszFile;
pAutoComplete->Seed(vCities); // entries already saved are left unchanged
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSample2Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSample2Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSample2Dlg::OnEllipseClickedSftMaskFiles1()
{
CFileDialog dlg(TRUE);
if (dlg.DoModal() == IDOK)
m_vMaskFiles1->Text = _bstr_t(dlg.GetPathName()) ;
}
BEGIN_EVENTSINK_MAP(CSample2Dlg, CDialog)
//{{AFX_EVENTSINK_MAP(CSample2Dlg)
ON_EVENT(CSample2Dlg, IDC_SFTMASKFILES1, 39 /* EllipseClicked */, OnEllipseClickedSftMaskFiles1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
BOOL CSample2Dlg::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
INT_PTR dmResult;
if (SftDarkMode_HandleDialogMessage(m_hWnd, message, wParam, lParam, &dmResult)) {
if (pResult) *pResult = dmResult;
return TRUE;
}
return CDialog::OnWndMsg(message, wParam, lParam, pResult);
}