Joined: 12/26/2006
Posts: 256
Location: United States of America
I've self-learned a lot about C++ but have mostly done nothing useful with it. I'm going to write a simple computer program (per Truncated's suggestion on the IRC channel) in order to sink my teeth into something concrete.
I remember using Visual C++ 6.0 and writing various "test" programs using the MFC framework. Eventually, I found that my "test" programs were writing things to the registry that I had no idea about! When I tried to correct for it, I ended up crashing the entire computer, requiring a clean reformatting of the hard disk. That pretty much ended my exploration of programming Windows using C++.
Right now, I'm using Visual C++ 2005 Express Edition with the Platform SDK installed to write native Windows code. (Since I have no interest in using the .NET extensions with C++, the graphical windows builder included in that IDE will be of little use.)
I'm seeking suggestions for the best way to access the Windows API with my C++ code. I understand that the "raw" API is mostly procedural and doesn't allow for very good object-oriented programming of the user interface. I've had bad experience with the MFC, as detailed above. Additionally, I want the program to be portable, so that the UI can be written for another operating system; thus, the UI code would be abstrated away from the main program logic.
Essentially, what would be the best way to code the user interface code?
Please keep in mind that I am a beginner, but Bisqwit gave me the great compliment that I do think like a programmer. Don't be afraid of being technical as long as you can explain it, and all suggestions and discussion is welcome.
Thanks!
For me, I found the switch to Linux to be a great helper for programming. Suddenly I had access to programming tools that worked, were stable, and did exactly what they were supposed to :)
Sure you can program in Windows too… but MFC and Windows APIs in general are somewhat of a deterrent to me.
i aJUST vCan not vRead cnSOURCE_CODE that vLooks aLIKE this :P
(Edit: But it took years to learn the basics of writing code that ⒈ does not have security holes and/or resource leaks and ⒉ works like typical programs do instead of sporting wild-coloured MS-DOSisms.)
Joined: 6/20/2004
Posts: 292
Location: United Kingdom
There's always SDL which can be used for multi-operating systems. I've used it a bit (I had to for a uni project, although very basic stuff), although I don't know how good it is for an actual programmer.
http://www.libsdl.org/
SDL is aimed at games. It doesn't really do GUI stuff unless you want to write your own UI engine.
That's where wxWidgets, GTK+ or things like them come into play. But honestly, very few people do stuff like that. It's just too easy to write for a single OS and leave others hanging. Which sucks...
Joined: 12/26/2006
Posts: 256
Location: United States of America
I knew that somebody was going to say that. : )
C# is a good language for Windows programming that avoids a lot of that... but unless the .NET Framework becomes cross-platform (I don't see it as likely; having a .NET Framework for MacOS, for example, wouldn't be Microsoft's smartest move), it's obviously not very portable.
I don't like the look or feel of GTK+ (as in the Windows version of GIMP). Writing a Windows-only program certainly would be easy, but I'm looking toward developing sound programming skills.
So, instead of libraries, let's talk about good ways of decoupling (a buzzword?) the UI from the rest of the code. A lot of people on this site use Linux; how well do the open-source emulators here do that?
Edit:
Could you please explain what you mean by this?
There is a huge difference between "it looks like it works" and "it's done and error-free".
There are myriads of subtle mistakes a programmer can do, and they WILL creep into your code, resulting in subtle but possibly devastating bugs. It takes a mathematically trained brain less than a month to learn a programming language, but it takes years to be able to recognize and avoid most pitfalls, and to develop a coding-style that'll help preventing bugs in the first place.
Still, no software is bug-free, and often more time is spent on maintaining and debugging a finished product than was spent on the initial development.
as for cross-platform UI-libraries: did you take a look at Qt yet? It's far more sophisticated and object oriented than MFC or GTK+. It'll also do a better job at blending into your existing environment (if you wish to choose your framework after visual criteria).
and btw, switching to linux really helps.
Joined: 12/26/2006
Posts: 256
Location: United States of America
Seems very impressive... and intimidating, if I may be honest...
Oh, I believe you. It's not possible for me right now, but it's definitely something I've got my eye on.
I use various. I only eschew Redhat-variants. But as long as I get my favourite software (ssh, bash, joe, strace, g++, slrn, xterm-256color, mozilla-firefox (mplayer I will compile), wget and coreutils) anything is fine ― even Cygwin.
In unix, there are conventions that most programs adhere to. Conventions regarding input, output, commandlines, configuration files, etc.
For a long time I was making programs that worked like programs did in MS-DOS. They were quite different from those in unix environment.
Adhering to the conventions makes it possible to use the tools as parts of tool-chains to perform tasks besides the ones conceived by the tool's author.
For example, the standard program "du" (disk usage) lists the amount of diskspace used by a subtree in the filesystem.
An example of its output:
Perhaps they would realize that the tree may grow large, and as such, facilities for scrolling the tree would be needed. Perhaps even a search function. Colours would be nice too.
However, all of those improvements sacrifice the usability for other purposes besides those conceived by the author.
For example, if I want to count together the amounts of disk space used in the various ".deps" directories in the path, then with the standard tools I can do it, like this:
First, let's prune the listing to only those directories with .deps in their name:
Of course the experienced user won't waste time writing all those intermediate steps separately; they can write the desired command straight away.
So if the author wants the list to be scrollable? Well, it already is! Just pipe the output to "more" or "less", like this:
bisqwit@chii:~/nes/fceu/fceu/src/drivers$ du |less
The "less" program can also do interactive searching on the output, and highlight the search hits. No need to reinvent the wheel.
It works nicely with any program that outputs lines of text into the stdout.
This is what the unix commandline is about.
Well, this may be a bit of a "best of both worlds" type of solution, but if you're leaning towards cross platform applications, there's always mono.
I had some difficulty (read: it just won't work) porting code from windows -> linux, but if you start in linux (using something like monodevelop), the success rate from linux -> windows is much higher.
I'm sorry to say, but for windows users in this day and age, I don't really see why you wouldn't have .NET installed. I doubt disk usage is an issue, and if you're just getting into development, it really is a pretty good RAD tool.
Joined: 12/26/2006
Posts: 256
Location: United States of America
Maximus wrote:
I'm sorry to say, but for windows users in this day and age, I don't really see why you wouldn't have .NET installed. I doubt disk usage is an issue, and if you're just getting into development, it really is a pretty good RAD tool.
I do have it installed, and I agree that it's an excellent tool; my only concern was platform portability.
Eventually I would like to write some tools for the nice people on this site to use. I know it would be a lot of work, but I imagine a TAS Movie Maker Studio suite integrating the emulator, input editing tools, memory search/watch, and even macros and bot scripting (calculating input based on memory values) all integrated into one software package. That's also why I'm studying a lot of existing source code (particularly for the emulators on this site) to see what other people's code looks like. My idea is only a pipe dream if I stay at my current level of programming ability.
Back to my previous question: how do the emulators here acheive portability with the many Linux users on this site?
I don't like the look or feel of GTK+ (as in the Windows version of GIMP).
I think that's more a problem with the Gimp than with GTK+.
GTK+ is ok'ish for making portable graphical programs. Its only problem in Windows is that you can't compile small stand-alone binaries using it. Either the GTK+ runtime libraries must be installed in the system or you have to provide over a dozen DLLs (taking up many megabytes) with your program if you want to run it. I believe there are other portable GUI libraries which do not have so much overhead.
For what's worth, I have made a program using GTK+ and compiled it for Windows (using mingw), so it's definitely possible: http://warp.povusers.org/FuncViewer/