From: Giovanni Dicanio on
"Joseph M. Newcomer" <newcomer(a)flounder.com> ha scritto nel messaggio
news:4026o5hjq6r69ao0pf0rrsf8hestrdsv7i(a)4ax.com...

> [...] But if it is some complex type, you may have a
> failure. For example
>
> class X {
> CArray<int> Data;
> }
>
> will cause a compilation error if you write
> b = a;
> as above, because CArray has no defined assignment operator.

Which I consider an error in the design of CArray.
(Other container classes like STL's vector are copyable "out of the box".)

Giovanni



From: RB on
(in my world sometimes when people get sloppy they do things that are "wrong" )
Thanks again for the input, I will put it to good use.
By the way there is one question I forgot to ask.
Since I can change my text with this code without writing an owner draw
function. Are there any reasons to still create the DrawItem function for
this, i.e. it there a facet I'm missing or could there be problems to do it this way ?
It would appear to me that if I wanted to just change separte lines of text
(color or font) that I would indeed need the owner draw for that.
Later.......RB


From: Joseph M. Newcomer on
I agree, but I needed a quick&dirty example that illustrated the failure of structure
assignment in C++, and CArray is an easy target.
joe

On Tue, 23 Feb 2010 00:36:45 +0100, "Giovanni Dicanio"
<giovanniDOTdicanio(a)REMOVEMEgmail.com> wrote:

>"Joseph M. Newcomer" <newcomer(a)flounder.com> ha scritto nel messaggio
>news:4026o5hjq6r69ao0pf0rrsf8hestrdsv7i(a)4ax.com...
>
>> [...] But if it is some complex type, you may have a
>> failure. For example
>>
>> class X {
>> CArray<int> Data;
>> }
>>
>> will cause a compilation error if you write
>> b = a;
>> as above, because CArray has no defined assignment operator.
>
>Which I consider an error in the design of CArray.
>(Other container classes like STL's vector are copyable "out of the box".)
>
>Giovanni
>
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on
See below...
On Mon, 22 Feb 2010 20:01:13 -0500, "RB" <NoMail(a)NoSpam> wrote:

>(in my world sometimes when people get sloppy they do things that are "wrong" )
>Thanks again for the input, I will put it to good use.
>By the way there is one question I forgot to ask.
>Since I can change my text with this code without writing an owner draw
>function. Are there any reasons to still create the DrawItem function for
>this, i.e. it there a facet I'm missing or could there be problems to do it this way ?
> It would appear to me that if I wanted to just change separte lines of text
>(color or font) that I would indeed need the owner draw for that.
>Later.......RB
****
I *love* owner-draw controls, and use owner-draw listboxes everywhere. They are cool, and
powerful, and allow you to do anything.

If all you want to do is change the font, uniformly, for every entry, then the SetFont is
sufficient and you don't need the DrawItem (but don't mark the control as owner-draw!)

But keep that code around! You will eventually want to do owner-draw somewhere else.

The most common use is that I can implement OnDeleteItem. It DOES NOT WORK CORRECTLY for
non-owner-draw listboxes.
joe

>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Glyn on


"RB" wrote:

> I have created the below code that actually works and compiles with
> zero errors and zero warnings. I would like criticism and input on
> it from all angles, First off is there a better way to do this. Does
> my code have problems etc. (granted I have left some error checking
> out to keep it brief)
> This all started when I wanted to change the font type and size in my
> FormView Listbox. I always try to keep everything within MFC since I
> want to concentrate on my stuff and not windows stuff. But everywhere
> I looked on the net for changing a font in a resource control had stuff
> setting the Owner Draw style to yes and writing an owner draw function
> of DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct ) which I eventually
> did learn to create and get working BUT in the process I ran across some
> things that made me think I did not have to write the owner draw function
> and I could set the font with supplied MFC control functions.
> And therein became this code. I have a standard MFC appwizard app with
> the generated view class having the CFormView as the base class
> Then I created a Listbox in the resource editor (on top of the FormView)
> with the following styles Selection = None and
> OwnerDraw = No (since I no longer need DrawItem)
> Vertical scroll and No integral height are checked, & no extended styles.
> Then in my FormView class header file I put the New font declaration of
> ----------header file-----------------------------------
> class CTry_2View : public CFormView
> {
> protected: // create from serialization only
> CTry_2View();
> DECLARE_DYNCREATE(CTry_2View)
> public:
> //{{AFX_DATA(CTry_2View)
> enum { IDD = IDD_TRY_2_FORM };
> CListBox m_FormListBoxObj;
> //}}AFX_DATA
>
> // Attributes
> public:
> CTry_2Doc* GetDocument();
> //// >>>>>HERE IS FUTURE NEW FONT FOR MY LISTBOX <<<<<<<////////
> CFont NewFont; // Construct instance of CFont class for new font.
>
> // Operations
> public:
> etc etc ....
> --------------cpp file------------------------------------
> Then in the destructor of the cpp file I put the DeleteObject
> CTry_2View::CTry_2View()
> : CFormView(CTry_2View::IDD)
> {
> //{{AFX_DATA_INIT(CTry_2View)
> // NOTE: the ClassWizard will add member initialization here
> //}}AFX_DATA_INIT
> // TODO: add construction code here
> }
>
> CTry_2View::~CTry_2View() // add destructor any code here
> { ////>>>>> HERE IS MY CLEAN UP OF FONT <<<<<<<<///////
> NewFont.DeleteObject(); // this CFont NewFont obj is declared in this
> // view class's header file.
> }
> ----------NOW further down in this same cpp file I put a button handler
> that changes the listbox font when clicked. The button was also created
> in the resource editor and the skeleton handler was added through the
> class wizard. I basically came up with all this code my own by experimenting
> with what I could find in the help files and seeing what intellisense would
> offer me on each item so I expect some criticism on my novice level creation.
> And are there still reasons I should go with the owner draw scenario as
> opposed to this way?
>
> //-------------Begin OnChangeFontClick function------------//
> void CTry_2View::OnChangeFontClick()
> {
> // Create instance of CClientDC class to this ( CWnd* )
> CClientDC dc(this);
>
> //create CFont Ptr to current font obj of listbox
> //The m_FormListBoxObj is a ClassWizard created listbox variable
> //of category Control and type CListBox
> CFont *pOldListBoxFont = m_FormListBoxObj.GetFont();
>
> // Declare old LOGFONT to save just in case I needed it later
> LOGFONT OldFontLogStruct;
> LOGFONT* pOldFontLogStruct = &OldFontLogStruct; //create ptr to it.
>
> // fill OldFontLogStuct with current font data
> pOldListBoxFont->GetLogFont(pOldFontLogStruct);
>
> // Declare a New LOGFONT struct variable
> LOGFONT NewFontLogStruct;
> LOGFONT* pNewFontLogStruct = &NewFontLogStruct; //create ptr to it.
>
> // copy the old stuff to new
> *pNewFontLogStruct = *pOldFontLogStruct;
>
> // CFont NewFont is declared in header file and destructed
> //(DeleteObject) in cpp file of the generated View class.
> CFont *pNewFont = &NewFont; // create ptr to it.
>
> // set the values we are concerned with in new font
> NewFontLogStruct.lfPitchAndFamily = (FF_MODERN || FIXED_PITCH);
>
> // lfHeight is negative int so convert abs.
> NewFontLogStruct.lfHeight = ( abs( pOldFontLogStruct->lfHeight ) + 4);
>
> // Courier New is a fixed space font
> strcpy(NewFontLogStruct.lfFaceName, "Courier New");
>
> // Create the new font with updated NewFontLogStruct
> BOOL FontCreation = NewFont.CreateFontIndirect(&NewFontLogStruct);
>
> if (FontCreation == 0)
> {
> MessageBox("Font creation failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
> }
> else
> { // Now set the font to the listbox control in my formview class
> m_FormListBoxObj.SetFont(pNewFont, TRUE);
> }
> } // end of function
>
>
> .
>

Hello,

I don't know if you've been told about this yet, but you have logical
operator here...

NewFontLogStruct.lfPitchAndFamily = (FF_MODERN || FIXED_PITCH);

It should be...

NewFontLogStruct.lfPitchAndFamily = (FF_MODERN | FIXED_PITCH);

Regards

Glyn Richards