C++, MFC Version 6, ComboBox - Font

Noah Aas 925 Reputation points
2024-04-09T14:08:42.1666667+00:00

Hello! I need to modify an old application. The ComboBox should get the Courier font. How can I achieve this?

The developer at the time used it at runtime to create the combobox. Can anyone give me some tips? Is not easy, I know.

I have googled without success.

Picture.

enter image description here

The idea is to simply fill in with spaces to get a clean, readable selection, as some of the names are different lengths.

Thanks for your help. With best regards Noah


int CDDF_A1::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;

	m_getOrderQueue.Create("", WS_TABSTOP|WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, 812, NULL, FALSE, (_bstr_t)"1375759644");

	m_SelectedOrderList.Create("", WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, 821, NULL, FALSE, (_bstr_t)"-656125452");
	
	
int CDDF_A1::Test()
{
	
	// Creates a 12-point-Courier-font
//  m_Font.CreatePointFont(120, _T("Courier"));

  // With a member variable associated to the static control
//  m_SelectedOrder.SetFont(&m_Font);

// Font setzen

/*
	IFontDisp *pFontDisp = (IFontDisp *)m_SelectedOrder.GetFont();
	IFont *pFont = NULL; 
	pFontDisp->QueryInterface(IID_IFont, (LPVOID *) &m_Font);//&pFont);
	CY size;
	pFont->get_Size(&size);
	size.Lo = 135000;
	pFont->put_Size(size);

	m_SelectedOrder.SetFont(pFontDisp);


	pFontDisp->Release(); 
	pFont->Release(); 
*/
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,904 questions
{count} votes

Accepted answer
  1. RLWA32 48,056 Reputation points
    2024-04-10T13:37:00.2466667+00:00

    Assuming that you are trying to obtain an IFontDisp interface pointer for use with an ActiveX control you can do the following to create a 12 pt. Courier font -

    FONTDESC fdesc{ sizeof(fdesc), L"Courier", 120000LL, FW_NORMAL, ANSI_CHARSET, FALSE, FALSE, FALSE };
    
    IFontDisp* pFontDisp = NULL;
    HRESULT hr = OleCreateFontIndirect(&fdesc, IID_PPV_ARGS(&pFontDisp));
    if (SUCCEEDED(hr))
    {
        // rest of code
    }
    

    I didn't have an old version of VC++ handy so you may need to modify the syntax to conform to whatever version you are using.


1 additional answer

Sort by: Most helpful
  1. Guido Franzke 2,191 Reputation points
    2024-04-10T08:14:26.2066667+00:00

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.