Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2006

Tip: Looking for answers? Try searching our database.

New to C++ entirely (HELP!)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James - 29 Mar 2006 16:56 GMT
I'm interested in learning C++.  I'm not sure exactly what this means.  I'm
currently a VB.NET/C#.NET programmer (both Windows Forms and ASP.NET).  I am
totally clueless when it comes to C++.  I've tried creating new projects and
even that is confusing.  I'm unsure of the differences between MFC, ATL,
Win32, etc. etc. applications.  I don't even know where to begin.

If I wanted to write a full screen application with some type of simple
graphical output, would I just create a console application?  What if I
wanted to create a simple dialog based app?

I want to get to a point where I can write/understand something as mundane
as:

1.)  Full screen "DOS" app that draws a circle of a given color.
2.)  Simple Dialog app with text boxes that has a button that just does a
MessageBox of the concatention of the fields.

I haven't the faintest idea where to begin.  Can anyone help me out here?
William DePalo [MVP VC++] - 29 Mar 2006 18:54 GMT
> I'm interested in learning C++.  I'm not sure exactly what this means.

:-)

> I'm currently a VB.NET/C#.NET programmer (both Windows Forms and ASP.NET).
> I am totally clueless when it comes to C++.  I've tried creating new
> projects and even that is confusing.  I'm unsure of the differences
> between MFC, ATL, Win32, etc. etc. applications.  I don't even know where
> to begin.

OK. The first thing you need to do is to separate C++ the language from the
programming environment. To learn ISO standard C++, my recommendation is to
read the book "Thinking in C++" by Bruce Eckel:

http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html

This is not the academic treatise that many C++ books are, and in fact if
you pursue C++ in earnest you will outgrow it soon. Still, I'd suggest this
book as an introduction to the language.

> If I wanted to write a full screen application with some type of simple
> graphical output, would I just create a console application?  What if I
> wanted to create a simple dialog based app?

The problem here is that standard C++ is completely agnostic as to windowing
systems. Of course you can use it with the Win32 API or .Net's WinForms, but
you can also use GTK or QT or Motif or whatever. That support comes from
libraries written in C++, but not part of the language.

MFC and ATL are C++ class libraries that target native Win32 development.
MFC is long in the tooth, ATL is newer and a more modern usage of the
language and relies heavily on C++'s template facility.

If you target the .Net platform, you can use a MS "dialect" of C++. With
VS2003, this language is called Managed Extensions for C++ aka MC++. With
VS2005 you can use C++/CLI which stands for Common Language Infrastructure
or something. Note that, for now, using either language means that you have
decided to target .Net on Windows platforms and nothing else.

> I want to get to a point where I can write/understand something as mundane
> as:
[quoted text clipped - 4 lines]
>
> I haven't the faintest idea where to begin.  Can anyone help me out here?

Well, the first step is to decide if you want to target Windows or .Net. I
put this quick hack together in response to a similar question for a poster
who wanted to target .Net.

I used the IDE to create an empty Win32 (not console) project. This is the
source file:

//-------------------------------------------------------------

#include "po2.h"

void HelloWorld::Main()
{
Application::Run( new HelloWorld() );
}

void HelloWorld::Main2()
{
int               h;
IntPtr            handle;
FileStream   __gc *fs;
StreamWriter __gc *sw;

if ( AttachConsole(-1) == 0 )
 AllocConsole();

h = GetStdHandle(-11);
fs = new FileStream(IntPtr(h), FileAccess::Write);
sw = new StreamWriter(fs);
sw->AutoFlush = true;
Console::SetOut(sw);

Console::WriteLine("Hello, world!");
}

HelloWorld::HelloWorld()
{
Text = "Hello, world!";
BackColor = Color::White;
}

void HelloWorld::OnPaint(PaintEventArgs *pea)
{
Graphics __gc *grfx = pea->Graphics;
Rectangle rc;

grfx->DrawString("Hello, World!", Font, Brushes::Black, 0, 0);

rc = get_ClientRectangle();
rc.Width  -= 1;
rc.Height -= 1;

grfx->DrawLine(Pens::Red, 0, 0, rc.Width, rc.Height);

grfx->DrawEllipse(Pens::Blue, rc);
}

void HelloWorld::OnResize(EventArgs *ea)
{
Invalidate();
}

// Hack avoids including <windows.h>

int __stdcall WinMain(int, int, char *pszCmd, int)
{
std::string cmdLine(pszCmd);

if ( cmdLine.find("window") != std::string::npos )
{
 HelloWorld::Main();
 return 0;
}

else if ( cmdLine.find("console") != std::string::npos )
{
 HelloWorld::Main2();
 return 0;
}

else
 return -1;
}

//-------------------------------------------------------------

#include <string>

#using <System.dll>
#using <mscorlib.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::IO;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::ComponentModel;
using namespace System::Runtime::InteropServices;

[ DllImport("KERNEL32.dll", EntryPoint="AllocConsole",
CallingConvention=CallingConvention::StdCall) ]
extern "C" unsigned short int AllocConsole(void);

[ DllImport("KERNEL32.dll", EntryPoint="AttachConsole",
CallingConvention=CallingConvention::StdCall) ]
extern "C" unsigned short int AttachConsole(int);

[ DllImport("KERNEL32.dll", EntryPoint="GetStdHandle",
CallingConvention=CallingConvention::StdCall) ]
extern "C" int GetStdHandle(int);

public __gc class HelloWorld : public Form
{
public:

   HelloWorld();
   static void Main();
   static void Main2();

protected:

    void OnPaint(PaintEventArgs __gc *);
    void OnResize(EventArgs __gc *);
};

and this is the the header

#include <string>

#using <System.dll>
#using <mscorlib.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::IO;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::ComponentModel;
using namespace System::Runtime::InteropServices;

[ DllImport("KERNEL32.dll", EntryPoint="AllocConsole",
CallingConvention=CallingConvention::StdCall) ]
extern "C" unsigned short int AllocConsole(void);

[ DllImport("KERNEL32.dll", EntryPoint="AttachConsole",
CallingConvention=CallingConvention::StdCall) ]
extern "C" unsigned short int AttachConsole(int);

[ DllImport("KERNEL32.dll", EntryPoint="GetStdHandle",
CallingConvention=CallingConvention::StdCall) ]
extern "C" int GetStdHandle(int);

public __gc class HelloWorld : public Form
{
public:

   HelloWorld();
   static void Main();
   static void Main2();

protected:

    void OnPaint(PaintEventArgs __gc *);
    void OnResize(EventArgs __gc *);
};

It is a hack to be sure, but the its attractiveness (if there is any) is
that it is self-contained and the framework classes that it uses should be
familiar to you as a C# developer.

It may get you started to understand the learning curve that you face.

If you want to target Windows, but not .Net, then the first step is to
decide whether you want to learn the Win32 API, MFC, ATL or WTL. No matter
which way you go, you are looking at 6 months (at least) of time to get up
to speed to build anything as trivial as my quick hack. Unfortunately, there
is no easy way to get up to speed. And the lack of one is as much as reason
for .Net as anything else, IMO.

Regards,
Will
Ray Tayek - 29 Mar 2006 22:23 GMT
> I'm interested in learning C++.  I'm not sure exactly what this means.

why do yo wish to learn c++?

> I'm
> currently a VB.NET/C#.NET programmer (both Windows Forms and ASP.NET).  I am
> totally clueless when it comes to C++.  I've tried creating new projects and
> even that is confusing.  I'm unsure of the differences between MFC, ATL,
> Win32, etc. etc. applications.  I don't even know where to begin.

iirc, the win32, mfc, atl just create projects that start you off using
those things. win32 probaly uses the old win sdk stuff. you can find out
about that by gettin some old books by petzold an richter. or older
books on mfc or atl.

if you make a windows forms application, it will look like the c#/vb
stuff that you are used to. you just have to stick with the managed c++
stuff.

thanks
beginthreadex - 31 Mar 2006 19:21 GMT
Look for Walter Savitch's book called "Absolute C++". This is a very good
book and I recommend it for people like you hands down over everything. Start
there. And once you are finished with that book, you'll not have as many
issues with MFC or standard windows.

Some of the things that you might want to consider, is your project
longterm. Since you are working with ASP.NET you might read the book above,
then go download some ISAPI samples. ISAPI is really simple, but if you are
used to the ASP (especially of the .net flavor) then you will never go back
if you find that you can work with ISAPI.

> I'm interested in learning C++.  I'm not sure exactly what this means.  I'm
> currently a VB.NET/C#.NET programmer (both Windows Forms and ASP.NET).  I am
[quoted text clipped - 14 lines]
>
> I haven't the faintest idea where to begin.  Can anyone help me out here?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.