Skip to main content
gamedev.net
🔒 Locked

Adding a GUI to pure c++ code.

Started by VanillaSnake21 Mar 2, 2009 at 11:25 PM 10 replies 2.4k views
Original Post
VanillaSnake21
VanillaSnake21
The title is probably confusing, but I'll try to explain what I mean: I'm writing a small tool (for managing files) and I've already made a simlpe gui with custom buttons (bitmaps) and formated text. I'm using GDI+ for all the entire gui. The problem is that I want to open a new dialog-like window when I click the "Import" button. The new window can be very simple and all it needs to contain is a text box with a label saying "Import from which directory?". I don't need any browsing boxes or anything like that. So I'm trying to find the best library or architecture or anything else that can do that for me. I'm using Visual Express C++ and it doesnt have the resource editor. I would really want to use a resource script to create a very simple textbox, but I can't find any sources that show me how to do that (it looks like .rc scripts for dialogs are becoming obsolete). There are so many new technologies - Windws Forms, Windows Presentation Layer, VBA (not new), MFC etc. So I'm not sure where to start. What is the fastest way to create something like that, but also what is the currently accepted way to do this? Thanks. Edit: Might as well ask this also, is there any way to dynamically insert widgets into the window? So lets say a user clicks a button and another button appers in the window, or lets say the button moves smoothly from the left side of the window to the bottom once the user pressed it?
You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts
daviangel
daviangel
To quote one of the most well know Windows programmers:

Q. There are so many ways to write Windows programs these days. There's the API, there's MFC, and now there's .NET and Windows Forms, and in a couple years Avalon is coming out. What should I use?
A. I can't answer that question for you. The programming interface you chose must be based on many factors, including the programming resources you have, and your target audience.

However, it is very clear that the world needs to be moving in the direction of managed code, and that's where the world seems to be going. Exploring Microsoft .NET now (including learning C# and Windows Forms) puts you in an excellent position to take on WinFX (also known as Avalon) when it becomes available.
--Charles Petzold

Personally, I find winforms easiest but then again I'm familiar enough with C++/CLI, .NET,etc to work with it.
If not and don't want/care to learn it you will have to stick with straight Win32 or MFC.
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
VanillaSnake21
VanillaSnake21
Well I do know some C# but I need the program to be done pretty fast. I'm much more familiar with C++ so it's my lang of preference for this project. I thought about learning VB just for the sakes of being able to create GUIs in seconds but again, I would rather avoid learning a diff langaugae right now, an architecture - maybe. I'm not really asking which technology is better, I'm asking what will get me there faster, considering
a) I have already started a non managed, non .net project
b) I have written a fair share of custom gui code using just gdi+
c) Need a very simple textbox in a new window.

Considering those factors I would personally prefer sticking with the old .rc scripts to make my textbox, but afail, there is no good places on the net that show how to do that. I actually have a simple script but vc express doesn't want to compile it saying, unexpected end of file found or something.
You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts
george135
george135
You don't need anything.
Just use standard Win32 api and resource dlg
VanillaSnake21
VanillaSnake21
Quote:
Original post by mutex
Have you checked the resource file reference on MSDN?


Yea I looked at that before, but it only gives me parts, it doesn't tell me how to build an entire script file. Like I said, I already made a small script from the what I could find online, but it crashes with a fatal error. Here it is:

#include "resource.h"IDD_IMPORTDLG DIALOG 260, 200, 180, 120TITLE "ImportDlg"STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENUCAPTION "Import"FONT 8, "MS Shell Dlg"BEGIN    BUTTON          "OK", IDOK, 120, 100, 50, 14    LTEXT           "", IDD_TEXTBOX1, 40, 8, 90, 80END


The error is:
1>.\resource.h(3) : fatal error RC1004: unexpected end of file found

My resource file is:

#define IDD_IMPORTDLG 1#define IDD_TEXTBOX1  2
You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts
daviangel
daviangel
Quote:
Original post by VanillaSnake21
Quote:
Original post by mutex
Have you checked the resource file reference on MSDN?


Yea I looked at that before, but it only gives me parts, it doesn't tell me how to build an entire script file. Like I said, I already made a small script from the what I could find online, but it crashes with a fatal error. Here it is:

*** Source Snippet Removed ***

The error is:
1>.\resource.h(3) : fatal error RC1004: unexpected end of file found

My resource file is:

#define IDD_IMPORTDLG 1#define IDD_TEXTBOX1  2

Yeah it's tricky doing it by hand from what I remember. Lamothe did this in one of his game programming books and that's where I first saw it and could never figure it out since there is 2 parts to it and you are probably missing one of the steps that's why you're getting an error.

[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
VanillaSnake21
VanillaSnake21
Quote:
Original post by daviangel
Yeah it's tricky doing it by hand from what I remember. Lamothe did this in one of his game programming books and that's where I first saw it and could never figure it out since there is 2 parts to it and you are probably missing one of the steps that's why you're getting an error.


The 2 parts are the .rc file declaring the script and the resource.h that defines any resources IDs, I got both but I'm probbaly forgetting to add something in either the .h or the .rc file. I'm trying to recover my password from Dreamspark so I can use VS 2008, I'll make it create a script for me and see what I was doing wrong.
You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts
mutex
mutex
Okay I reproduced your problem. You're missing a newline at the end of resource.h.

After you fix that you'll get more errors. Here's what compiled for me:

#include "resource.h"#include <windows.h> // Need windows.h for dialog/window styles.IDD_IMPORTDLG DIALOG 260, 200, 180, 120// TITLE "ImportDlg" // TITLE is not a valid directive.STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENUCAPTION "Import"FONT 8, "MS Shell Dlg"BEGIN    // Need to use PUSHBUTTON instead of BUTTON.    PUSHBUTTON          "OK", IDOK, 120, 100, 50, 14    LTEXT           "", IDD_TEXTBOX1, 40, 8, 90, 80END

daviangel
daviangel
Quote:
Original post by VanillaSnake21
Quote:
Original post by daviangel
Yeah it's tricky doing it by hand from what I remember. Lamothe did this in one of his game programming books and that's where I first saw it and could never figure it out since there is 2 parts to it and you are probably missing one of the steps that's why you're getting an error.


The 2 parts are the .rc file declaring the script and the resource.h that defines any resources IDs, I got both but I'm probbaly forgetting to add something in either the .h or the .rc file. I'm trying to recover my password from Dreamspark so I can use VS 2008, I'll make it create a script for me and see what I was doing wrong.

Yeah save yourself the grief of doing it by hand although I know Petzold wouldn't approve since Visual Studio rots the mind-LOL!


[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
VanillaSnake21
VanillaSnake21
Thanks everyone :D, I got VS2008 running, mutex, thanks
You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts
Everyman
Everyman
Just as an aside, there also several solutions to easily equip arbitrary programs with a UI, e.g. by using a client/server approach where the program just has to connect to a GUI server which in turn dynamically creates the UI and reports relevant events back to the client:
http://www.gtk-server.org/apps.html


Check out freshmeat for several other such tools.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.