|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Creating Windows GUIs with C++
This is only slightly related to robo, but...
I've been making Windows applications for about a year since I took a programming class in school last year. The main thing I've done is a server launcher for Command & Conquer Renegade (an old FPS) and its assorted mods. More to the point, I create installers and distribute my programs over the web. I've been using VB.NET. While I love the language, a lot of people who I distributed the program to have complained about the .NET framework, as it requires a large RAM overhead (my program, while relatively small, takes 20 MB of RAM to run), and is sluggish redrawing the window and such on the screen. They are also frustrated with having to download a relatively large framework in the first place. I'm working on acquiring a copy of VB6 to circumvent these issues, but at the suggestion of another member of our code team, I'm trying to do something similar in C++ To make a long story short, I've been teaching myself C++ (due to its similarity to the C we use to program our robots with) so that I can create better, smaller, and faster-running apps. However, since I highly doubt that my users would want do everything in command prompt, I want to create a GUI. I understand it's possible to create windows using only the Windows API, but that's very complex (for me, at this level, anyways), and I've been looking into other options. A fellow code member on my team suggested I used Glade, which is a GUI builder that uses the GTK+ toolkit. Does anyone else have any experience, either in Glade or just creating windows with C++ in general, and if so, do you have any advice for me? |
|
#2
|
||||
|
||||
|
Re: Creating Windows GUIs with C++
Where I work at Sony Creative Software, we use C++ directly with the Win32 API. It makes for much faster programs, especially when it comes to user interface elements. It's fine to work with once you're used to it, but there's a steep learning curve - mostly because it's written in such a way that it can be used in C (i.e. no classes, just a whole lot of global functions, structures and macros).
I would suggest you look into MFC (Microsoft Foundation Classes). It's basically a Microsoft-written C++ wrapper for the Win32 API. If you're using Visual C++, there are wizards to get you started with MFC applications. Otherwise, if you're interested in using the API directly, I have to recommend this book; it's considered the "bible" of Windows programming. |
|
#3
|
|||||
|
|||||
|
Re: Creating Windows GUIs with C++
http://www.winprog.net/tutorial/
Helped me (of course, a little side help from a couple of advanced programmers) create this program: http://rapidshare.com/files/76407628...aller.rar.html the winprog site is a really good introduction to programming API which leads to learning to use OS components and programs. I'm looking forward to starting to learn MFC, which should be the next step for programming applications and so. If you need any help with API, I'll be glad to help. Nir. |
|
#4
|
|||
|
|||
|
Re: Creating Windows GUIs with C++
Check out the Qt toolkit from Trolltech: http://trolltech.com/products/qt/homepage
It's open source (GPL'd)...so if you create open source apps with it you can use it for free. The docs are great--they have some tutorials and lots of examples. I've used it to create ~3 GUI apps now, and it's worked great every time. - Taj |
|
#5
|
||||
|
||||
|
Re: Creating Windows GUIs with C++
Also check out wxWidgets
|
|
#6
|
||||
|
||||
|
Re: Creating Windows GUIs with C++
Awesome guys. Thanks for the help.
|
|
#7
|
||||
|
||||
|
Re: Creating Windows GUIs with C++
wxWidgets is pretty cool for multi platform free stuff. There is a pretty nice visual compiler called wxDev-C++. The one bad thing about wxWidgets is that it is bulky and is all 3rd party so some things aren't all the way there, its not the most supported. Programs like VLC media player and audacity use wxWidgets. With wxDev-C++ the exe seems to be kinda big.
I looked a little bit at QT and it just seems kinda weird, and I believe you need a license for it. I didn't look into it too much. I would suggest learning the windows programming, you will probably be much better off. Get Visual Studio and maybe a nice book and play around. Or..... You can learn some C#, from what I hear C# and the .net framework are very easy to use and are good for GUI applications. One plus side to C# is all the memory management is done inside the .net framework so you don't have to worry about memory leaks as in C++. With C# you cant do things with memory though as you can in C/C++ though. So it all comes down to personal preference. C# may be easier but I think it is a bit more restricted compared to C++ and with C++ you will probably be writing and debugging more then C#. I don't know too much about C# but this is just what I have heard ![]() |
|
#8
|
|||
|
|||
|
Re: Creating Windows GUIs with C++
Quote:
Last edited by shawger : 19-12-2007 at 23:41. |
|
#9
|
||||
|
||||
|
Re: Creating Windows GUIs with C++
I'm having issues now.
My code: This is just a simple "Hello World" using message boxes. Code:
#include <Windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{
MessageBox(NULL, "Hello!",
"Hello World", MB_OK | MB_ICONINFORMATION);
if (MessageBox(NULL, "I'm learning to use C++ to write native Windows programs. Cool, isn't it?",
"Cool, No?", MB_YESNO | MB_ICONQUESTION) == IDYES)
MessageBox(NULL, "You know it!", "Sweet!", MB_OK);
else MessageBox(NULL, "Jerk.", "Grrr", MB_OK);
return 0;
}
1. When I create an empty solution and insert this code, everything runs fine on my computer, but when I tried to show it to friends they said they all got an error that my application was not configured properly. 2. When I create an empty Win32 solution and insert the code, it refuses to build, telling me for each argument I pass: Quote:
Last edited by slavik262 : 20-12-2007 at 18:27. |
|
#10
|
||||
|
||||
|
Re: Creating Windows GUIs with C++
Your error message is Unicode-related. For every Windows function that deals with strings, there are actually two functions - one that uses ASCII strings (each character is 1 byte wide) and one that uses wide strings (each character is 2 bytes wide). The Win32 API functions typically have an 'A' or 'W' at the end of the name (like 'MessageBoxW').
The problem here is that your build environment appears to be configured to use Unicode, so all the Windows functions like MessageBox are automatically being aliased to their Unicode equivalents, like MessageBoxW. You're therefore trying to pass a string with ASCII characters (declared something like "stringgoeshere") into a function that takes a wide-character string (declared like L"stringgoeshere"). You could just put an 'L' in front of all your strings to force them to use wide characters, but there's a better solution. Windows has a data type called a 'TCHAR' you can use for strings, which is automatically converted into either ASCII or wide characters when you compile, depending on whether or not the _UNICODE preprocessor flag is set. All you have to do is include tchar.h, enclose your literal strings with the _T() or _TEXT() macros, and use the TCHAR data type whenever declaring string variables. Code:
#include <tchar.h>
...
// This is a string of 256 characters (ASCII or wide)
TCHAR szText[256];
...
// _T and _TEXT do the same thing
MessageBox(NULL, _T("Hello!"),
_TEXT("Hello World"), MB_OK | MB_ICONINFORMATION);
Last edited by Pat Fairbank : 20-12-2007 at 18:37. |
|
#11
|
||||
|
||||
|
Re: Creating Windows GUIs with C++
Thank you. It now compiles. And it works perfectly on my machine. However it still generates an error whenever I show it to somebody else:
Quote:
Code:
#include <Windows.h>
#include <tchar.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{
MessageBox(NULL, _T("Hello!"),
_T("Hello World"), MB_OK | MB_ICONINFORMATION);
if (MessageBox(NULL, _T("I'm learning to use C++ to write native Windows programs. Cool, isn't it?"),
_T("Cool, No?"), MB_YESNO | MB_ICONQUESTION) == IDYES)
MessageBox(NULL, _T("You know it!"), _T("Sweet!"), MB_OK);
else MessageBox(NULL, _T("Jerk."), _T("Grrr"), MB_OK);
return 0;
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is easyC compatible with windows vista | team877 | Programming | 10 | 12-02-2007 12:43 |
| What to do with an old Windows 3.10 laptop? | Elgin Clock | IT / Communications | 13 | 14-07-2005 17:45 |
| Prob. With Windows 2k | Staz | Programming | 2 | 15-01-2005 10:15 |
| Creating no pressure with double solenoid? | Combat Chuck | Pneumatics | 7 | 29-02-2004 22:45 |
| Need Help With Windows Applications In C++ | Hailfire | Programming | 9 | 05-01-2003 10:13 |