Getting out of consoles

Pages: 123
As the title says, I'm tired of being stuck in console apps using C++. I've tried Win32, and it always just throws this behemoth section of code at you and says "ok copy that, and compile it". Well, first off most of the times I run into type issues, and then if I can compile it, whats the point? I just learned nothing out of this. And finding documentation on it is about terrible.

So after dealing with Win32's crap, I decided I would try OpenGL. Not any better. So I tried GLUT, and that went slightly better but still got nowhere. So how in the hell do I get past this frustration of dealing with these libraries with no documentation?

When I was in Java, I had no issues with any of this. I needed something done, I pulled up Java docs and found what I needed, and made it. No ridiculous errors that shouldn't be there, no trouble getting everything linked and placed. It was all just there and worked. Good god this annoys me.
Still no luck with SFML?
None. I'm considering reformatting my computer just to get everything to where it should be. I feel like I have multiple copies of random crap right now. God this is annoying
Do you use the gcc that comes with code::blocks? If so, have you seen my last post here? http://cplusplus.com/forum/beginner/63779/
I didn't see that post actually. How do I even check my compiler version?
All the mentioned libraries have documentation.
Win32: http://msdn.microsoft.com/en-us/library/windows/desktop/hh447209%28v=vs.85%29.aspx
OpenGL: http://www.opengl.org/sdk/docs/man4/
GLUT: http://www.opengl.org/resources/libraries/glut/spec3/spec3.html

OpenGL is huge so it might be worth reading a book about it. Using a library like SDL or SFML might be easier to start with.
SDL documentation: http://www.libsdl.org/cgi/docwiki.cgi/SDL_API
SDL tutorials: http://lazyfoo.net/SDL_tutorials/index.php

SFML documentation: http://www.sfml-dev.org/documentation/1.6/
SFML tutorials: http://www.sfml-dev.org/tutorials/1.6/
Last edited on
SFML has been the latest I've tried. Having a hell of a time getting it to compile.
If you didn't download mingw separately you likely are using code::blocks version. Try downloading the version I linked in the other thread.
Ok and now what?
Did you add the bin folder to your path and remove the old mingw entry? Otherwise can you be more specific?
We had the same problem a couple weeks ago! Heres how i got mine to work: I Deleted all of my SFML folders and copies along with the MinGW. Then i uninstalled Codeblocks, I reinstalled everything and put the SFML files on a Flashdrive(Its slower, but i used a flashdrive so i could just take the files with me to every computer i compile on) and replaced the MinGW as usual. I followed the instructions down to the word on the site, and it suddenly worked. Post your errors if you have any, ive had just about every installing error SFML can throw out there.
It sounds like if you're running into type issues, you're not exactly ready to move onto a win32 program. And what's this about 'no documentation'? Last time I checked, msdn had all the documentation you could ask for.
And they throw the code at you because its faifly straightforward and they expect you to understand it. If you don't, you probably aren't at the level you think you are.

Take creating a window for example. You need to register a class, create a windows procedure, and create a window using the CreateWindow function. Then the message loop, and you're done. It's a simple, 5 minute project.
How do I even check my compiler version?
RTFM
In general there will be a version flag, that may be shorted as 'v'

Important: this release of SFML was compiled with gcc 4.4, which makes the SFML libraries not compatible with the old gcc 3.4.5. The MinGW team hasn't released a full package including gcc 4.4 yet, so here is one that you can use: mingw-with-gcc-4.4.zip (34.9 MB).

That's the second paragraph of the installation tutorial.
I know you said you don't want console apps, but what do you want exactly? Are you looking to develop games? Or something like Windows forms?
Last edited on
How to get past the furstraition, Try and Fail. Over and Over again.

When i started with win32 api & dx9, i dident get much working the first three months, but i keept at it, making smart classes and after a while i just got the hang of it.

And you allso gain some sort of "Second sense" in code. you just get it working with out realy thinking.

An Example, when i first got my hands over a ps3 dev kit. i just took some code and experimented with it, and after six weeks i had built an rendering pipleine for the Ps3 and that was the first time i ever was in contact with OpenGl es aswell. They only way i had to complete that was just giving it all to make it happen. You will probably never find good documentation on every subject you are working in, so you better get use to it aswell ;)
Last edited on
http://cplusplus.com/forum/beginner/58541/
I think this helped one guy.

EDIT:
Actually never mind. You've already responded to that post.

I'll see if I can find something else for you.
Last edited on
I wrote my first serious WIN32 front-end two weeks ago. I created some classes for each type of window. I'd like to share them. It'll make your experience a little easier.

In terms of documentation, I think it is pretty intuitive, but create an object with the applicable class for each button/text/editbox/etc that you want to create. You need to have a unique reference for each one (I use a list of enums). Put the enum value specific to that object as the argument for hMenu. Now whenever that object sends a message to the parent window, it will send it's enum value as the WM_COMMAND.

First, this creates static text somewhere on the window:
1
2
3
4
5
6
7
8
9
10
11
12
13
class StaticText 
{
	HWND hwnd;
public:
	void Create(std::string text, int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int hMenu)
	{
		hwnd = CreateWindowEx(0,"Static", text.c_str(), WS_CHILD | WS_VISIBLE, Xpos, Ypos, Xsize, Ysize, parent, (HMENU)hMenu, NULL, NULL);
	}
	void Text(std::string text) // Changes text
	{
		SetWindowText(hwnd, text.c_str());
	}
};


This is a button:
1
2
3
4
5
6
7
8
9
10
11
class Button
{
	HWND hwnd;
public:
	void Create(std::string text, int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int hMenu, bool def = false)
	{
		DWORD style = WS_CHILD | WS_VISIBLE;
		if (def) style |= BS_DEFPUSHBUTTON;
		hwnd = CreateWindowEx(0, "Button", text.c_str(), style , Xpos, Ypos, Xsize, Ysize, parent, (HMENU)hMenu, NULL, NULL);
	}
};


This creates an edit box. You can set or get text from it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class EditBox 
{
	HWND hwnd;
public:
	void Create(int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int hMenu)
	{
		hwnd = CreateWindow("Edit", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER, Xpos, Ypos, Xsize, Ysize, parent, (HMENU)hMenu, NULL, NULL);
	}
	std::string GetText()
	{
		char text[4096]; // You may need to increase this
		int len = GetWindowTextLength(hwnd) + 1;
		GetWindowText(hwnd, text, min(len,4096));
		return text;		
	}
	void SetText(std::string)
	{
		SetWindowText(hwnd, text.c_str());
	}
};


This creates a Group Box (It's a border that can have a caption):
1
2
3
4
5
6
7
8
9
10
11
12
13
class GroupBox 
{
	HWND hwnd;
public:
	void Create(std::string text, int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int hMenu)
	{
		hwnd = CreateWindowEx(0, "Button", text.c_str(), WS_CHILD | WS_VISIBLE | BS_GROUPBOX, Xpos, Ypos, Xsize, Ysize, parent, (HMENU)hMenu, NULL, NULL);
	}
	void SetText(std::string text)
	{
		SetWindowText(hwnd, text.c_str());
	}
};


This is a status bar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class StatusBar 
{
	HWND hwnd;
	int progress;
public:
	void Create(int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int hMenu)
	{
		progress = 0;
		hwnd = CreateWindowEx(0, PROGRESS_CLASS, NULL, WS_CHILD | WS_VISIBLE | PBS_SMOOTH, Xpos, Ypos, Xsize, Ysize, parent, (HMENU)hMenu, NULL, NULL);
		
		SendMessage(hwnd, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
		SendMessage(hwnd, PBM_SETPOS  , 0, 0);
	}
	void SetProgress(int prog) // Progress between 0 and 100.
	{
		progress = prog;
    
		if (prog < 100) SendMessage( hwnd, PBM_SETPOS, prog, 0 );
		else			SendMessage( hwnd, PBM_SETPOS, 0   , 0 );
	}
};


This one's not an object. It's a function that when called will open the default windows OPEN dialogue and when completed, will return a string containing the path of the selected file/folder.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
string LoadFileDialog(LPCSTR Filter)
{
    char Filestring[256];
    string fname;

    OPENFILENAMEA opf;
    opf.hwndOwner = 0;
    opf.lpstrFilter = Filter; // Filter = "All files\0\*.*\0\0" for all files
    opf.lpstrCustomFilter = 0;
    opf.nMaxCustFilter = 0L;
    opf.nFilterIndex = 1L;
    opf.lpstrFile = Filestring;
    opf.lpstrFile[0] = '\0';
    opf.nMaxFile = 256;
    opf.lpstrFileTitle = 0;
    opf.nMaxFileTitle=50;
    opf.lpstrInitialDir = 0;
    opf.lpstrTitle = "Open File";
    opf.nFileOffset = 0;
    opf.nFileExtension = 0;
    opf.lpstrDefExt = "*.*";
    opf.lpfnHook = NULL;
    opf.lCustData = 0;
    opf.Flags = (OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT);
    opf.lStructSize = sizeof(OPENFILENAME);

    if(GetOpenFileNameA(&opf))
    {
        fname = opf.lpstrFile;
    }

    return fname;
}


Another hint: If you're using visual studio 2010 you can use this to use the Windows 7 theme instead of Win98. Now you don't need to mess with the manifest files.
1
2
3
4
#pragma comment(linker,"/manifestdependency:\"type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' \
language='*'\"") 


I'm working on a REALLY simple thing tonight. I'll post the code when I'm done.
Last edited on
Okay, here is something super simply for you. It only uses a few of the classes above. It helps me to test a text-to-speech function that I've been working on. I have not included the code for that function as it isn't relevant

GUI.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Enables default windows styles
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' \
    version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")

#include <Windows.h>
#include "resource1.h"
#include "GUI_Functions.h"

// Window loop
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_COMMAND:
        switch(LOWORD(wParam))
        {
            case ID_BTTN_1: // This is the only object which sends messages
            {
                std::string text = Edit1.GetText(); // Get the text
                Edit1.SetText("");                  // Lets clear the window

                // Set some static text
                if (text.size() == 0)
                    Stat1.Text("Fault: String is empty");
                else
                    Stat1.Text(text);

                // My own function
                text_to_speech(text);
            }
        } // end WM_COMMAND switch
        break;
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    case WM_CREATE:
        CreateObjects(hwnd); // Creates the objects. This is called first
        break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    } // end msg switch
    return 0;
}

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

    //Step 1: Registering the Window Class
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = 0;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_ICON1));
    wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_ICON1),IMAGE_ICON,16,16,0);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "Main Window";

    RegisterClassEx(&wc);

    // Step 2: Creating the Window
    hwnd = CreateWindowEx (    WS_EX_CLIENTEDGE,    "Main Window",    "Text to speech tester",    WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 530, 135, NULL, NULL, hInstance, NULL);

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

    // Step 3: The Message Loop
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);    //DispatchMessage calls WndProc() 
    }
    return Msg.wParam;
}


GUI_Functions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <Windows.h>
#include <string>

std::string LoadFileDialog(const char* Filter);

void CreateObjects(HWND hwnd);

// Object classes
class StaticText // This creates static text
{
    HWND hwnd;
public:
    void Create(std::string text, int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int hMenu);
    void Text(std::string text); // Changes text
};

class Button // This creates a button
{
    HWND hwnd;
public:
    void Create(std::string text, int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int hMenu, bool def = false);
};

class EditBox // This creates an edit box.  You can set or get text from it
{
    HWND hwnd;
public:
    void Create(int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int ident);
    std::string GetText();
    void SetText(std::string);
};

class GroupBox // A nice border with a caption
{
    HWND hwnd;
public:
    void Create(std::string text, int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int hMenu);
    void SetText(std::string text);
};


// Externals
extern GroupBox     GBox1;
extern EditBox        Edit1;
extern Button       Bttn1;
extern StaticText   Stat1;    

// Object IDs
enum hmenu
{
    ID_GBOX_1    = 30001,
    ID_EDIT_1,
    ID_BTTN_1,
    ID_STAT_1,
};


And the GUI_Functions:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "GUI_Functions.h"

void StaticText::Create(std::string text, int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int ident)
{
    hwnd = CreateWindowEx(0,"Static", text.c_str(), WS_CHILD | WS_VISIBLE, Xpos, Ypos, Xsize, Ysize, parent, (HMENU)ident, NULL, NULL);
}
void StaticText::Text(std::string text)
{
    SetWindowText(hwnd, text.c_str());
}
////////////////////////////////////////////////////////////////////////////
void Button::Create(std::string text, int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int ident, bool def)
{
    DWORD style = WS_CHILD | WS_VISIBLE;
    if (def) style |= BS_DEFPUSHBUTTON;
    hwnd = CreateWindowEx(0, "Button", text.c_str(), style , Xpos, Ypos, Xsize, Ysize, parent, (HMENU)ident, NULL, NULL);
}
////////////////////////////////////////////////////////////////////////////
void GroupBox::Create(std::string text, int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int ident)
{
    hwnd = CreateWindowEx(0, "Button", text.c_str(), WS_CHILD | WS_VISIBLE | BS_GROUPBOX, Xpos, Ypos, Xsize, Ysize, parent, (HMENU)ident, NULL, NULL);
}
void GroupBox::SetText(std::string text)
{
    SetWindowText(hwnd, text.c_str());
}
////////////////////////////////////////////////////////////////////////////
void EditBox::Create(int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int ident)
{
    hwnd = CreateWindow("Edit", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER, Xpos, Ypos, Xsize, Ysize, parent, (HMENU)ident, NULL, NULL);
}
std::string EditBox::GetText()
{
    char text[2048];
    int len = GetWindowTextLength(hwnd) + 1;
    GetWindowText(hwnd, text, min(len,2048));
    return text;
}
void EditBox::SetText(std::string text)
{
    SetWindowText(hwnd, text.c_str());
}
////////////////////////////////////////////////////////////////////////////
void CreateObjects(HWND hwnd)
{
    GBox1.Create("Text to speech",   5,  5, 500, 77, hwnd, ID_GBOX_1);
    Edit1.Create(                   10, 27, 420, 22, hwnd, ID_EDIT_1);
    Bttn1.Create("Go"            , 440, 25,  50, 27, hwnd, ID_BTTN_1);
    Stat1.Create(""              ,  20, 57, 400, 18, hwnd, ID_STAT_1);
}
////////////////////////////////////////////////////////////////////////////
// Globals
GroupBox    GBox1;
EditBox        Edit1;
Button        Bttn1;
StaticText    Stat1;


I've also created an icon with the resource editor in Visual studio. A resource.h file is automatically generated which contains IDI_ICON1 used to register the main class in WinMain().
Last edited on
Here's another idea.

If you've given up on Win32, you could try Qt. You can make significantly complicated interfaces that look really good with their editor. Once you've got that, you get the code and interface it with your back end.

Qt is a very nice tool and does require some skill. Once you've got the skill it also makes you more hirable. There is almost always a post on the jobs forum for someone with Qt knowledge.

They have some pretty cool tutorials to help you out as well in the suite itself.
http://qt.nokia.com/downloads/
Pages: 123