Log in

View Full Version : C++?



mburt
08-14-2006, 12:45 PM
Just wondering if the "Other" forum could be used as a C++ place thingy.

Snorkle?
08-14-2006, 01:36 PM
It is other, isnt it?

Snorkle?
08-14-2006, 01:37 PM
wow u know c++ thats incredible i was gonna start learning C but i gues i changed my mind

Twey
08-14-2006, 04:01 PM
I see no reason why not.

shachi
08-14-2006, 06:44 PM
Umm... what about C too??

mburt
08-14-2006, 06:50 PM
I feel like I've wasted my money.. I bought a C++ book, but didn't realize it was only console C++, which is COMPLETELY diferent from Win32 C++, which I'm trying to do now, without Microsoft's Visual C++.. I would really like some help.

Twey
08-14-2006, 06:50 PM
Well obviously if C++ is allowed C will be too :)

Eeh? You bought "a C++"? You mean you bought a C++ compiler? That's a total waste of money. There are plenty of good compilers out there, such as the Free Dev-C++ (http://www.bloodshed.net/dev/devcpp.html).
There's no such thing as a console-only compiler. There are ways to create GUI apps with every compiler. The usual toolkit for Windows applications is the Microsoft Foundation Classes (MFC) which are, insofar as I'm aware, only available if you buy MSVC++. However, your application will not only be as good but actually probably be considerably better if you use a Free toolkit such as wxWidgets (http://www.wxwidgets.org/) or Qt (http://www.trolltech.com/products/qt), since you will gain platform portability and an actual decent toolkit. :)
MFC is fast, but as toolkits go, it lacks a lot.

"Win32 C++" is generally defined by two things: COM and MFC. Neither is actually necessary to create workable, graphical Windows applications.

However, if you didn't know this already, it's probably not time for you to start trying to create GUI apps yet.

mburt
08-15-2006, 01:41 AM
This is quite ironic actually, I made a typo, and left out the word book, secondly the compiler I have is Dev C++ (comes with the book I bought)

mburt
08-15-2006, 01:42 AM
There's no such thing as a console-only compiler.

Yes, I know that, but making Windows programs in Visual C++ is way easier.

mburt
08-15-2006, 01:45 AM
Okay, to say the least, this is the C++ (I guess you could say..) that I've learned: (a basic "Hello World" program)



#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!";
system("PAUSE");
return 0;
}


I figured out that kind of C++ very easily. Then I wanted to make a Windows App, but I need some guidance. Links, tutorials, whatever. :)

Twey
08-15-2006, 02:30 AM
making Windows programs in Visual C++ is way easier.Au contraire. I found MFC thoroughly unpleasant to use. Qt, by comparison, is very intuitive. I'm not familiar enough with wxWidgets to comment, but I know that its selection of widgets is similar to Qt's, making them both far more comprehensive than MFC's.

#include <iostream>
// using namespace is a bit overkill for two calls.

int main() {
std::cout << "Hello, World!"
<< endl << endl << "Press enter to continue.";
std::cin.ignore(); // using system("pause") makes the program platform-dependant.
return 0;
}

Snorkle?
08-15-2006, 04:22 AM
Wow i know how u feel i bought a book about javascript soon to find out it was all netscape stuff and not IE too

DimX
08-15-2006, 08:58 AM
Well nowdays javascript is every-browser stuff.

And if you want to make GUI Windows without any MFCs and Visual stuff, you should check out this: http://www.winprog.org/tutorial/index.html. I made a GUI app with Dev-C++ using this tutorial :p

Twey
08-15-2006, 02:33 PM
Using windows.h directly is interesting, but not really practical :) Plus, you have to mess about with COM and suchlike, and you lose all platform independence.

Certainly, write a couple of apps just with windows.h to get the feel of it, but I wouldn't recommend it for a real project.

shachi
08-15-2006, 02:34 PM
Anyone knows of a good C tutorial for beginners?? I have been searching for ages but never found a one which actually was appropriate.:(

Twey
08-15-2006, 02:37 PM
http://www.cprogramming.com/tutorial/c/lesson1.html
I don't like C. :) I get battered for it by every old-time hacker I meet, but I just can't be persuaded to like that ugly language.

I guess I'm addicted to objects. ;)

shachi
08-15-2006, 02:39 PM
I don't have a c++ compiler(yet) so I am sticking to c for the time being and will learn c++ some time later. Thanks for the link.:)

mwinter
08-15-2006, 10:42 PM
I wouldn't recommend considering C as a stepping stone to C++. It simply isn't. There is no point in using C++ unless you're going to use its object-oriented features, and a switch in paradigm is much more difficult proposition than a switch in language.

Mike

mburt
03-21-2007, 02:35 PM
Well I am back... And I have learned a nice bit about Win32 API. My Hello World script:

#include <windows.h>

const char g_szClassName[] = "myWindowsClass";

char string[] = "Hello, World";

void GamePaint(HDC hDC)
{
TextOut(hDC, 0, 0, string, sizeof(string)-1);
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
switch(msg)
{
case WM_PAINT:
hDC = BeginPaint(hwnd, &ps);
GamePaint(hDC);
EndPaint(hwnd, &ps);
return 0;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
default:
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);

if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}

I used CodeBlocks to create it and used MinGW compiler (with mwindows flag). Enjoy :)

Twey
03-21-2007, 04:26 PM
Equivalent wxPython code:
import wx

a = wx.App()
f = wx.Frame(None, wx.ID_ANY, "The title of my window", size=(240, 120))
wx.StaticText(f, wx.ID_ANY, "Hello, World")
a.SetTopWindow(f)
f.Show()
a.MainLoop()This is also portable across almost every graphical platform in existence. Why not to use low-level routines when high-level ones will do. :)

mburt
03-21-2007, 06:30 PM
Yeah, that's with wxWidgets. I can't get 2.8.2 working right for CodeBlocks. It keeps trying to access C:\wxWidgets-2.6.2\ as the include path. I even changed the Compiler Options variables... still won't work.

Shotgun Ninja
04-04-2007, 06:58 PM
This is quite ironic actually, I made a typo, and left out the word book, secondly the compiler I have is Dev C++ (comes with the book I bought)


Heh, was it one of the Thomson Course PTR books, say, Beginning Game Programming for Teens or Introduction to C++ Programming?