Join 300,363 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,451 people online right now. Registration is fast and FREE... Join Now!
I've been programming for about 3 months and I learned some mid-level C++. I made a few programs in Command Prompt (CLR) and those worked fine. The thing is, I want to learn how to create and use a UI in my programs. I use Visual Studio 2008 (Team Suite) to make them, and I know how to design the UI, I just don't know what to put in my code for it to all work out.
Can someone please point me in the right direction? I'm tired of having my programs run in a small black box all the time!
CLR? Whenever I see CLR, I think the .NET CLR. Perhaps what you mean to say is that you have a CLI?
QUOTE
I use Visual Studio 2008 (Team Suite) to make them, and I know how to design the UI, I just don't know what to put in my code for it to all work out.
I'm not sure how to interpret this statement. You say you know how to make the GUIs, yet you don't know how to code one up? Pardon, but the two contradict each other.
Ultimately, you need to pick a widget toolkit. On Windows, you have quite a few choices available. There's the raw Win32 API, MFC, WTL, WxWidgets, Qt, GTK+, FLTK, etc.. Then you learn the API and its design and implement it. Learning an API is time consuming. Expect to expend significant time in learning and writing programs before you get comfortable with an API (and a subset of it usually).
If I were required to write up an API, I would either approach it through Win32 API or a library that provides an abstraction like WxWidgets or Qt. The Win32 API is not a bad place to start, not necessarily because the API itself is the greatest to use for GUIs, but because its great for a shocking and enlightening learning experience on third party APIs. Plus the Win32 API is not just about GUIs, but as the name suggests, any kind of Windows specific task.
If you do ultimately pick the Win32 API, sit down with the Petzold book. His book is basically the classic learning guide. With Qt, WxWidgets, FLTK, etc., they may or may not have books but they should have everything up online.
By the way, do expect a bit of a shock when you sit down with any of these APIs. You might feel that 3 months and you have plenty of experience, but all the learning code will look very alien. That's just the syntax too. The design will probably throw you off too, as it's unlikely that you are familiar with the kind of design paradigms that are a staple of GUI programming.
QUOTE
I'm tired of having my programs run in a small black box all the time!
I think after a bit of experience with making GUIs, your opinion will change. You won't be too happy to write up a GUI. Unless your program is all about the GUI, of course. And making GUIs isn't fun.
CLR? Whenever I see CLR, I think the .NET CLR. Perhaps what you mean to say is that you have a CLI?
Yes, the .NET CLR.
QUOTE
I'm not sure how to interpret this statement. You say you know how to make the GUIs, yet you don't know how to code one up? Pardon, but the two contradict each other.
No, they don't. I see what you're saying. In Visual Studio, you can place buttons, text boxes, menus, etc. in a form. That's what I mean by designing it. Unless that's what you already understood.
So, I have to learn an API? I actually did play around with MFC and it was pretty confusing.
Thanks,
Chris
EDIT:
I downloaded FLTK and it works great. Unlike others, FLTK actually has a lot of good beginner documentation. Thanks!
This post has been edited by cgseif323: 16 Jun, 2009 - 09:23 AM
QUOTE(cgseif323 @ confirming what Command Prompt (CLR) meant)
Yes, the .NET CLR.
So the language you are using is not C++ itself but C++/CLI. I make this distinction because C++/CLI is based off the C++ syntax, but is a new language in itself. It is not simply C++ with the backend to be the .NET platform and a few language extensions. I'm not trying to start a language war here, but understand that you'll get very limited help for C++/CLI. Either learn C++ itself, or preferably, stick with a pure .NET language. The ideal choice would be C#. Understand that if you choose to pursue C++/CLI, you are on your own with the syntax and the language quirks.
QUOTE
In Visual Studio, you can place buttons, text boxes, menus, etc. in a form. That's what I mean by designing it. Unless that's what you already understood.
That would be the logical interpretation. Not that I mean using a form designer to make a decent GUI is any trivial process, but all form designers do is generate the design code and helpers.
Ultimately, the design needs to resolve somehow into code. The menus, panels, labels, etc., are somehow being generated by code (how much of this code is visible to you depends). When you have a relatively static design (for example, in your web browser, the general layout doesn't change much, and menus don't turn into something new, there's an advantage to using a dedicated designer instead of manually coding up the design. Past the immediate design, however, and you do have to learn how the API works and do have to structure your code to work in the architecture imposed by the GUI, the system behind it, etc.
(This is also why I am in favor of teaching approaches that first introduce you to the API without a designer, and only when you are comfortable creating a GUI, introduce the designer and how it fits into the workflow. It's up to you, but you can't escape all the code.)
Why and how an API forms are interesting questions you can ponder later. From a practical perspective, you need to make two decisions. The first is to pick a sensible GUI toolkit and the second is to figure out how you are going to learn it. For example, on the .NET platform, the main choices would be WinForms and WPF. Since C++/CLI is a .NET language, one would expect you to use either of those GUI toolkits. Same with C# or any other .NET language. With pure C++, you cannot use the .NET toolkits (what a shame!) but you do have other choices including the Win32 API and the third party library Qt.
Since the selection of toolkits available to you is also determined by what language and platform you are on, I suggest making a decision there first. You should have gathered that I really don't want you to use C++/CLI. The two logical alternatives are C# and pure C++. It's not an easy choice given that you invested three months already in C++/CLI, but you should make that decision. Stay, or switch (and to which language)?
This post has been edited by Oler1s: 16 Jun, 2009 - 09:35 AM
So the language you are using is not C++ itself but C++/CLI. I make this distinction because C++/CLI is based off the C++ syntax, but is a new language in itself. It is not simply C++ with the backend to be the .NET platform and a few language extensions. I'm not trying to start a language war here, but understand that you'll get very limited help for C++/CLI. Either learn C++ itself, or preferably, stick with a pure .NET language. The ideal choice would be C#. Understand that if you choose to pursue C++/CLI, you are on your own with the syntax and the language quirks.
No, it is pure C++. I never even heard of C++/CLI. C++ is all I know.
No, it is pure C++. I never even heard of C++/CLI. C++ is all I know.
But, how do you know this? I'm not being accusatory, but you are rejecting my statement that you are programming in C++/CLI and not in C++. Thus you must have some basis for this statement.
QUOTE(cgseif323 @ on the code posted)
^ This seems like pure C++ to me. This is an extremely basic program I made in the CLR.
But it isn't. While there are many similarites, such as the headers <cstdio> and <iostream> the general syntax, and namespaces, your code is indeed C++/CLI code.
Since MageUK is offering his help, and my knowledge of C++/CLI is superficial at best, he can continue to help you if you choose to stay with C++/CLI.
QUOTE
Oh and by the way, what are the differences between C# and C++? I'm interested in learning C#
It's really about as meaningful as asking what the difference between two spoken languages are. While I can give example of differing syntax or some generalizations, it doesn't really do justice or tends to be so simplistic to be useless. I would request that you read quite a bit about the two languages, and then continue your inquiries, to confirm your impressions of the two languages, or inquire further.
No, it is pure C++. I never even heard of C++/CLI. C++ is all I know.
But, how do you know this? I'm not being accusatory, but you are rejecting my statement that you are programming in C++/CLI and not in C++. Thus you must have some basis for this statement.
I just don't understand why it's C++/CLI (I don't need to right now, so don't worry about it please). I'm not trying to reject your statement, sir, I only thought that you meant that I didn't know what I was talking about. I did know what I was talking about until you mentioned C++/CLI. My apologies. I just don't want to set this off on the wrong foot.
C++/CLI is C++ WITH the CLI, it's not a completely new language, it has new operators, yes, but it's not a new language.
C# 3.0 has completely new operators over C# 2.0, just as .NET 3.5 has new features over .NET 2.0, that doesn't make it a different language/framework, does it?
The fact that C++/CLI will compile native without the CLI aspect (#pragma unmanaged) is proof of this.