470,594 Members | 1,106 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

New to C++ entirely (HELP!)

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?
Mar 29 '06 #1
3 1586
"James" <mi*******@gmail.com> wrote in message
news:OJ*************@TK2MSFTNGP10.phx.gbl...
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/...ngInCPP2e.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:

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?


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
Mar 29 '06 #2
In article <OJ*************@TK2MSFTNGP10.phx.gbl>, mi*******@gmail.com
says...
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
Mar 29 '06 #3
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.

"James" wrote:
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?

Mar 31 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by abcd | last post: by
8 posts views Thread by Johnny Knoxville | last post: by
17 posts views Thread by JT | last post: by
3 posts views Thread by Jesper Denmark | last post: by
32 posts views Thread by robert d via AccessMonster.com | last post: by
36 posts views Thread by aljamala | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.