🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: microsoft.public.vc.ide_general
Article #9

Re: Using VC++ from a C++Builder perspective

#9
From: Scott McPhillips MVP
Date: Sat, 13 Nov 2004 01:38
94 lines
5452 bytes
Jason W. Hinson wrote:
>>Using the MFC library that comes with VC++...
>>
>>CEdit* myEdit = new CEdit();
>>CRect rect(left, top, right, bottom);
>>myEdit->Create(WS_VISIBLE | WS_BORDER, rect, this, IDC_MYEDIT);
>>myEdit->SetFont(GetFont());
>>myEdit->SetWindowText("Something");
>>
>>MFC control objects have almost no member variables.  Instead, numerous 
>>CWnd functions (like SetFont) are inherited by all of them to get/set 
>>the properties that are stored within Win32.  MFC does not try to be 
>>very "C++ish".  Rather, it is for the most part a thin wrapper over the 
>>Win32 APIs.  It provides the essential interface needed between the C 
>>language API callbacks and C++ member functions.  You can see a lot of 
>>it quickly by working through the SCRIBBLE tutorial in the help.
> 
> 
> Thanks for the reply, Scott...
> 
> This is not bad at all.  You created the object directly with a new 
> command, and you didn't have to refer to it by its ID number to set its 
> variables (though it looks like you did have to give it an ID and make 
> sure it was unique).  I'm obviously new to VC++, and I didn't know if 
> such actions were the standard way of doing things or not.
> 


The unique ID is used by the control to send notifications to the parent 
window.  This is the "standard" way to programmatically create a 
control, but one seldom needs to programmatically create a control.  So 
your question is not really a good context in which to understand the 
basics of MFC controls.


> 
> Another quick question: When you build a CEdit with the VC7 IDE, it is 
> given an ID number, if I understand correctly.  Does it not have a name 
> as well?  From the VERY limited exposure I've had, it seems you always 
> have to get the item (I forget the call) using its ID, then that gives 
> you a CWnd pointer (not a CEdit pointer).  So if there are 
> CEdit-specific members, how do you access them?  If you create a combo 
> box at run-time and want to add members to it, is that something you can 
> do once you have a CWnd pointer to it, or is there some other way you 
> have to access that type of component?
> 


In the code above, the control's "name" is myEdit.  More typically, it 
would be a dialog member variable named m_myEdit so other functions can 
access it.


> I also noticed that you could assign an IDE-created CEdit a variable, 
> but (again, from my limited exposure) it seemed that this only gave you 
> direct edit capabilities for the text in the CEdit rather than pointing 
> you to the CEdit object itself.  However, when you create a variable 
> for, say,  a button, it seems to point to the button object itself.  If 
> I got that right, it sure is confusing.


You are confused, because you actually have a choice between creating 
control member variables and data-exchange member variables. 
Data-exchange member variables (a CString) can only be used for 
getting/setting the text.  Data-exchange variables are a silly little 
marketing pizazz feature that make simple jobs simple, but can do no 
more.  Fluff.

But control member variables (a CEdit) refer to the control object and 
can call all control functions.  They are your workhorses.


> Another annoyance I noted (and I'd like to think there were an easy way 
> around this) is that if I created a button, added some code for its 
> click event, then deleted the button, VC7 did not seem to do a good job 
> of cleaning up the code that used to go with the button.  In fact, at on 
> point it seems it didn't even get rid of some of the creation routines 
> for the button, and so it refused to run just because I used the IDE to 
> delete a button.  Is that just the way it is, or did I miss something?
> 
> Sorry for all the added questions, but I really appreciate any help you 
> can offer!  I'll also find the SCRIBBLE tutorial for some added 
> experience.
> 
> 
> -Jason

That's just the way it is.  This problem will go away when you have more 
that a few days experience.  I can't criticize the IDE for being 
unwilling to delete some of my code.  After all, I may be intending to 
copy that code to a new function!

-- 
Scott McPhillips [VC++ MVP]
Technical Details
Message-ID: <OB6NXHSyEHA.2600@TK2MSFTNGP09.phx.gbl>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!cyclone.bc.net!msrtrans!news.microsoft.com!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
References: <hinson-6E84C1.18360311112004@news.east.cox.net> <#eu5gVFyEHA.1452@TK2MSFTNGP11.phx.gbl> <hinson-DFA459.17044712112004@news.east.cox.net>

Show Full Headers
Complete Article Headers
X-Google-Thread: f707b,2ac2be6d0340ebc1
X-Google-Thread: f5c5c,2ac2be6d0340ebc1
X-Google-Attributes: gidf707b,gidf5c5c,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Fri, 12 Nov 2004 20:38:14 -0500
From: "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>
Organization: McPhillips Designs
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Subject: Re: Using VC++ from a C++Builder perspective
References: <hinson-6E84C1.18360311112004@news.east.cox.net> <#eu5gVFyEHA.1452@TK2MSFTNGP11.phx.gbl> <hinson-DFA459.17044712112004@news.east.cox.net>
In-Reply-To: <hinson-DFA459.17044712112004@news.east.cox.net>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <OB6NXHSyEHA.2600@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.vc.ide_general,borland.public.cppbuilder.vcl.components.using
NNTP-Posting-Host: pcp220481pcs.elkrdg01.md.comcast.net 68.55.209.237
Lines: 1         
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!cyclone.bc.net!msrtrans!news.microsoft.com!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl