Sign in to follow this  

windows GUI and C++

This topic is 3595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey there! I've almost finished all the game-elements-programming and now it's time to create a mapeditor for my very own game. I was wondering if there were any libraries or other ways (or maybe it's already included in the WinAPI) to easily start using open/load/save windows etc in c++. If someone could give me any guidance on where to start learning about Windows GUI (programming related), I'd be very grateful. I do hope it's possible in only c++, as I have not the need to learn a complete new programming language for only just this. Besides, I'll still need to use my cpp-files in the editor. Many thanks, - Stijn

Share this post


Link to post
Share on other sites
I wasn't quite sure what exactly you meant.

When you say "Win API" do you mean win32 or a totally GUI environment like a VC++ forms project? Which is still win32 by the way but the VC++ IDE gives them different names. Then there's different versions of a simple Win32 GUI win API app. For example I hijack the main entry point and write my own interface because I don't want all that application generated stdafx stuff.

Everything under Windows uses the Win API but different approaches put different layers on top of it. Like MFC is a C++ wrapper for direct API functions, as is the "forms" project environment.

Even a graphics or games engine still uses the Win API at some level underneath their code unless they're writing directly to hooks in a specific video card for pure speed. The Win API isn't just a method to access their GUI stuff, in fact the real API is nothing to do with GUIs. It directly accesses all the core computer functions. So it can do pretty much anything you want (Windows is written in C++) but it really depends on what you want to do specifically.

For heavy GUI stuff then a "forms" project is probably best because you get a toolbox with every widget in existence in it (almost!). Personally I never use it because ... well never mind... I just prefer lean and mean.

m0ng00se

Share this post


Link to post
Share on other sites
Heh, yeah sorry. I was affraid it wasn't clear. I've been ill for a couple of days, so straight thinking isn't my strongest point at the moment. What I wanted to do is make us of the save and load dialog boxes. Nothing more. Now I think about it, why not use all of the forms-features. It looks neater, and it's more organized.

So yes, that's what I want to do. Learn how to use those damn Windowsforms. I'm using Visual Studio and C++. Any tutorials people could link me to, or give a headstart (do know I know my c++-stuff)?

-Stijn

Share this post


Link to post
Share on other sites
If you simply need dialog boxes to select a file to load/save, you can use GetOpenFileName and GetSaveFileName. They are implemented in the Windows API, look here for more details.

This is an example I found in one of my old projects:


#define BUFFER_SIZE 1024

char* ChooseFileForWriting (HWND hwnd,
char *pszFilter,
char *pszDefExt)
{
static char szFile[BUFFER_SIZE];
memset(szFile, 0, sizeof(szFile)); // GetSaveFileName() failed without this

OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = pszFilter;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile) - 1;
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
ofn.lpstrDefExt = pszDefExt;

BOOL b = GetSaveFileName(&ofn);
if (0 == b)
{
DWORD dwErr = CommDlgExtendedError();
if (0 != dwErr)
{
sprintf(szFile, "GetSaveFileName() error: %u", dwErr);
MessageBox(hwnd, szFile, 0, 0);
}
return 0;
}
return szFile;
}




Edit: Sourcecode formatted ;)

Share this post


Link to post
Share on other sites
Actually I didn't make myself very clear either. Once upon a time there was only the Win API to call directly for all MS Windows stuff. Then MS "wrapped" it up with MFC. The issue is that MFC is an extra layer on top (bloatware) that adds a lot of stuff you don't need and makes debugging a bit more complex.

It is also strictly class based. Everything under MFC is inherited from a single parent class. If you like the OOP approach then it's great. The "Forms" apps generator and project is based on MFC.

I'm a lazy programmer that graduated from C coding where I could do whatever I liked without worrying about constructors and destructors and private and public members etc. So I prefer to write direct to the Win API and I build my own classes when I need them. I use third party SDK's for most of the stuff I would normally use MFC for. The MFC approach does force a more professional coding approach from an OOP perspective.

It's sort of overkill though if you only need it for what you have already mentioned. You're carrying around a whole lot of code that never gets used if you use the app generator. I'd just use the API in a simple Win32 app.

m0ng00se

Share this post


Link to post
Share on other sites
Personally I'm not a big fan of MFC, at least not for gaming projects. For an editor though where you may have lots of controls and other UI features, it could be useful for you. Just beware that it's become somewhat bloated over the years, and it isn't exactly designed with performance in mind. Also you should be aware that it only comes with the paid versions of Visual Studio, and can't be used with the Express editions.

As an alternative you may want to consider the Windows Template Library (WTL). It's an extension of ATL that includes classes for windowing and common controls, and overall is a much leaner package compared to MFC. It's downsides are that there's no real complete documentation, and that it might seem a bit confusing if you're not used to working with templates. I also believe it's usable with the Express editions, but I'm not 100% on that.

Option #3 is to simply go for the raw Windows API. This is what I do for my projects, however my editors are used solely by me so I usually don't bother to put in a lot of fancy UI features. Designing your UI and handling all of your controls and dialogs through straight Win32 can be quite tedious, and you may yourself either repeating a lot of code or designing some classes that look an awful lot like MFC classes (re-writing code that you already have access to usually isn't a good thing). The API is also in C, which means everything is functions and structs. However the upside is you'll be in absolute control of everything that happens, and if you're unfamiliar with Windows programming you'll definitely learn a whole lot about how things work at a lower level.

Option #4 would be to use some sort of third-party library. I know they exist, but I have zero experience with any of them so I can't really give you advice as to which are useful.

Share this post


Link to post
Share on other sites
Why dont you use C# or VB for editor type programs?

Edit: I read what you said, but C# is enough similar to C++ that its an easy transition, and VB.net is downright simple!

[Edited by - Crazyfool on February 10, 2008 5:51:38 PM]

Share this post


Link to post
Share on other sites

This topic is 3595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this