MSCV++ 4.0 - Dialog Boxes and SelectObject

This is a discussion on MSCV++ 4.0 - Dialog Boxes and SelectObject within the C++ Programming forums, part of the General Programming Boards category; Having built a 'std' SDI program, I was wanting to control the font & cursor for the dialog. S ofar, ...

MSCV++ 4.0 - Dialog Boxes and SelectObject

Having built a 'std' SDI program, I was wanting to control the font & cursor for the dialog. S ofar, the only help /code I can find always relates to the primary apps "ondraw" function. Is there an alternative to use SelectObject or get the device context?

I have snipped a piece of code I've been working with ....

Code:

// CDCTestFont3App commands
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// In this situation - what would be the code to handle resources correctly using
// SelectObject() - I'm presuming it is neccesary and that a CFont *oldfont would
// also be required. (The book i'm reading warns about resource leaks in this situation.
// The problem is determining what device context would be used to handle
// SelectObject for the dialog box. - is it: this.SelectObject, or is some form
// of assignment of a type via a pointer required?
LOGFONT fontdata; // Create the LOGFONT structure...
ZeroMemory( &fontdata, sizeof(LOGFONT) );
GetDlgItem(IDOK)->GetFont()->GetLogFont(&fontdata); // Copies font info into fontdata
fontdata.lfWeight = FW_SEMIBOLD; // Set the weight of the font
lstrcpy(fontdata.lfFaceName, "Arial Narrow"); // Change the name of the font
new_font.CreateFontIndirect(&fontdata); // Create a new font with the specified LOGFONT parameters
GetDlgItem(IDOK)->SetFont(&new_font); // Assign the font to the widget
// If attempt to use same font again it would fail as font create already
// need to have individual font for each style to be used.
ZeroMemory( &fontdata, sizeof(LOGFONT) );
GetDlgItem(IDC_AboutTitle)->GetFont()->GetLogFont(&fontdata);
fontdata.lfWeight = FW_THIN; // THIN TEXT
fontdata.lfItalic = TRUE;
lstrcpy(fontdata.lfFaceName, "Comic Sans MS");
title_font.CreateFontIndirect(&fontdata);
GetDlgItem(IDC_AboutTitle)->SetFont(&title_font);
GetDlgItem(IDC_AboutCopyright)->SetFont(&title_font);
CWinApp* pApp = AfxGetApp();
if( pApp != 0 )
{
m_hIconOkay = pApp->LoadIcon( IDI_GreenIcon );
m_hIconCancel = pApp->LoadIcon( IDI_RedIcon );
ASSERT(m_hIconOkay);
ASSERT(m_hIconCancel);
m_AboutOK.SetIcon( m_hIconOkay );
m_AboutCancel.SetIcon( m_hIconCancel );
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

Code Tags

I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you

For example:

Without code tags:

for(int i=0;i<5;i++)
{
cout << "No code tags are bad";
}

With Code Tags:

Code:

for(int i=0;i<5;i++)
{
cout << "This code is easy to read";
}

This is of course a basic example...more complicated code is even easier to read with code tags than without.

I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found at the link in my signature. Any further questions or ways I can help please feel free to PM me.