Click here to Skip to main content
15,896,606 members
Articles / Desktop Programming / ATL

FontComboBox ActiveX Control

Rate me:
Please Sign up or sign in to vote.
4.91/5 (5 votes)
7 Aug 2002CPOL1 min read 93.2K   2.4K   32  
Another FontComboBox class. This one uses the ATL technology.
///////////////////////////////////////////////////////////////////////////////
//
// FontComboBox.cpp : CFontComboBox implementation
//
// Author: Jean-Michel LE FOL
// Date:   04/12/2002
//
///////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "FontCombo.h"
#include "FontComboBox.h"

///////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CFontComboBox::get_Aspect (fcbAspect* pVal)
{
    *pVal = m_nAspect;

    return S_OK;
}

///////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CFontComboBox::put_Aspect (fcbAspect newVal)
{
    m_nAspect = newVal;

    if ( ::IsWindow (m_ctlComboBox.m_hWnd) )
    {
        m_ctlComboBox.Invalidate();
    }
    return S_OK;
}

///////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CFontComboBox::get_TransparentBorder (BOOL* pVal)
{
    *pVal = m_bTransparentBorder;

    return S_OK;
}

///////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CFontComboBox::put_TransparentBorder (BOOL newVal)
{
    m_bTransparentBorder = newVal!=0;

    if ( ::IsWindow (m_ctlComboBox.m_hWnd) )
    {
        m_ctlComboBox.Invalidate();
    }
    return S_OK;
}

///////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CFontComboBox::get_Selection (BSTR* pVal)
{
    if ( *pVal != NULL )
    {
        ::SysFreeString (*pVal);
        *pVal = NULL;
    }
    if ( !::IsWindow (m_ctlComboBox.m_hWnd) )
    {
        *pVal = ::SysAllocString (OLESTR(""));

        return S_OK;
    }
    int nIndex = m_ctlComboBox.DefWindowProc (CB_GETCURSEL, 0, 0);
    int nLen = m_ctlComboBox.DefWindowProc (CB_GETLBTEXTLEN, nIndex, 0);

    if ( nLen == 0 )
    {
        *pVal = ::SysAllocString (OLESTR(""));
    }
    else
    {
        USES_CONVERSION;
        LPTSTR sText = (LPTSTR)_alloca((nLen+1)*sizeof(TCHAR));

        m_ctlComboBox.DefWindowProc (CB_GETLBTEXT, nIndex, (WPARAM)sText);
        *pVal = ::SysAllocString (T2OLE(sText));
    }
    return S_OK;
}

///////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CFontComboBox::put_Selection (BSTR newVal)
{
    if ( !::IsWindow (m_ctlComboBox.m_hWnd) )
    {
        m_sInitialContent = newVal;
        return S_OK;
    }
    USES_CONVERSION;
    LPCTSTR sText = OLE2T(newVal);
    int nIndex = m_ctlComboBox.DefWindowProc (CB_FINDSTRING, (WPARAM)-1, (LPARAM)sText);

    if ( nIndex == CB_ERR )
    {
        m_ctlComboBox.SetWindowText (sText);
    }
    else
    {
        m_ctlComboBox.DefWindowProc (CB_SETCURSEL, nIndex, 0);
    }
    return S_OK;
}

///////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CFontComboBox::get_Enabled (BOOL *pVal)
{
    if ( ::IsWindow (m_ctlComboBox.m_hWnd) )
    {
	    *pVal = m_ctlComboBox.IsWindowEnabled();
    }
    else
    {
        *pVal = m_bEnabled;
    }
	return S_OK;
}

///////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CFontComboBox::put_Enabled (BOOL newVal)
{
    if ( ::IsWindow (m_ctlComboBox.m_hWnd) )
    {
    	m_ctlComboBox.EnableWindow (newVal);
    }
    else
    {
        m_bEnabled = newVal != 0;
    }
	return S_OK;
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer CSC
France France
Jean-Michel LE FOL is a GraphTalk product architect.
GraphTalk is a set of products which cover the whole scope of the development process. GraphTalk is used by the main insurance compagnies over the world.
The development team is currently based in France near Paris.

Comments and Discussions