Example #1
0
void AFXAPI DDX_FieldCBString(CDataExchange* pDX, int nIDC, CString& value,
                              CRecordset* pRecordset)
{
    ASSERT_VALID(pRecordset);

    HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
    if (pDX->m_bSaveAndValidate)
    {
        // just get current edit item text (or drop list static)
        int nLen = ::GetWindowTextLength(hWndCtrl);
        if (nLen != -1)
        {
            CString strTemp;
            ::GetWindowText(hWndCtrl, strTemp.GetBuffer(nLen), nLen+1);
            strTemp.ReleaseBuffer();
            nLen = strTemp.GetLength();
            if (nLen > value.GetAllocLength())
                AfxFailMaxChars(pDX, value.GetAllocLength());
            // get known length
            ::GetWindowText(hWndCtrl, value.GetBuffer(0), nLen+1);
        }
        else
        {
            // for drop lists GetWindowTextLength does not work - assume
            //  preallocated length
            ::GetWindowText(hWndCtrl, value.GetBuffer(0), value.GetAllocLength()+1);
        }
        value.ReleaseBuffer();
        if (value.GetLength() == 0)
        {
            if (pRecordset->IsFieldNullable(&value))
                pRecordset->SetFieldNull(&value, TRUE);
        }
        else
        {
            pRecordset->SetFieldNull(&value, FALSE);
        }
    }
    else
    {
        if (!pRecordset->IsOpen() || pRecordset->IsFieldNull(&value))
        {
            SendMessage(hWndCtrl, CB_SETCURSEL, (WPARAM)-1, 0L);
        }
        else
        {
            // set current selection based on model string
            if (::SendMessage(hWndCtrl, CB_SELECTSTRING, (WPARAM)-1,
                              (LPARAM)(LPCTSTR)value) == CB_ERR)
            {
                // just set the edit text (will be ignored if DROPDOWNLIST)
                AfxSetWindowText(hWndCtrl, value);
            }
        }
    }
}
Example #2
0
void AFXAPI DDX_FieldLBString(CDataExchange* pDX, int nIDC, CString& value,
                              CRecordset* pRecordset)
{
    ASSERT_VALID(pRecordset);

    HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
    if (pDX->m_bSaveAndValidate)
    {
        int nIndex = (int)::SendMessage(hWndCtrl, LB_GETCURSEL, 0, 0L);
        if (nIndex != -1)
        {
            int nLen = (int)::SendMessage(hWndCtrl, LB_GETTEXTLEN, nIndex, 0L);
            if (nLen > value.GetAllocLength())
                AfxFailMaxChars(pDX, value.GetAllocLength());
            ::SendMessage(hWndCtrl, LB_GETTEXT, nIndex,
                          (LPARAM)(LPSTR)value.GetBuffer(0));
            if (nLen == 0)
            {
                if (pRecordset->IsFieldNullable(&value))
                    pRecordset->SetFieldNull(&value, TRUE);
            }
            else
            {
                pRecordset->SetFieldNull(&value, FALSE);
            }
            value.ReleaseBuffer();
        }
        else
        {
            // no selection
            value.GetBufferSetLength(0);
            if (pRecordset->IsFieldNullable(&value))
                pRecordset->SetFieldNull(&value);
        }
    }
    else
    {
        if (!pRecordset->IsOpen() || pRecordset->IsFieldNull(&value))
        {
            SendMessage(hWndCtrl, LB_SETCURSEL, (WPARAM)-1, 0L);
        }
        else
        {
            // set current selection based on data string
            if (::SendMessage(hWndCtrl, LB_SELECTSTRING, (WPARAM)-1,
                              (LPARAM)(LPCTSTR)value) == LB_ERR)
            {
                // no selection match
                TRACE0("Warning: no listbox item selected.\n");
            }
        }
    }
}
Example #3
0
void AFXAPI DDX_FieldText(CDataExchange* pDX, int nIDC, CString& value,
                          CRecordset* pRecordset)
{
    ASSERT_VALID(pRecordset);
    HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC);
    if (pDX->m_bSaveAndValidate)
    {
        // check if length is too long (this is complicated by Windows NT/J)
        int nLen = ::GetWindowTextLength(hWndCtrl);
        if (nLen > value.GetAllocLength())
        {
            if (!_afxDBCS)
                AfxFailMaxChars(pDX, value.GetAllocLength());
            CString strTemp;
            ::GetWindowText(hWndCtrl, strTemp.GetBuffer(nLen), nLen+1);
            strTemp.ReleaseBuffer();
            nLen = strTemp.GetLength();
            if (nLen > value.GetAllocLength())
                AfxFailMaxChars(pDX, value.GetAllocLength());
        }
        // get known length
        ::GetWindowText(hWndCtrl, value.GetBuffer(0), nLen+1);
        value.ReleaseBuffer();
        if (nLen == 0)
        {
            if (pRecordset->IsFieldNullable(&value))
                pRecordset->SetFieldNull(&value, TRUE);
        }
        else
        {
            pRecordset->SetFieldNull(&value, FALSE);
        }
    }
    else if (pRecordset->IsDeleted())
    {
        CString strDeleted(MAKEINTRESOURCE(AFX_IDS_DELETED));
        AfxSetWindowText(hWndCtrl, strDeleted);
    }
    else
    {
        AfxSetWindowText(hWndCtrl, value);
    }
}
Example #4
0
LPSTR CStringToA(const CString& strData) 
{
    CString ret;
    char *ptr = NULL;
#ifdef _UNICODE
    LONG    len;
    len = WideCharToMultiByte(CP_ACP, 0, strData, -1, NULL, 0, NULL, NULL);
    ptr = new char [len+1];
	if (ptr)
	{
		memset(ptr,0,len + 1);
		WideCharToMultiByte(CP_ACP, 0, strData, -1, ptr, len + 1, NULL, NULL);
	}
#else
    ptr = new char [strData.GetAllocLength()+1];
    sprintf(ptr,_T("%s"),strData);
#endif
    return ptr;
}