I found this excellent video on one of Microsoft's websites: http://msdn.microsoft.com/en-us/ff728575

I'm really just wondering how to organize the window procedures for my Dialogs/Buttons/etc.

Would one normally after creating a dialog throw the window procedure into a new file? I don't like tiny bits of code in different files, so I decided to ask for another opinion.

As far as using Win32 goes, what does one need to know program code organization-wise?

Recommended Answers

All 3 Replies

**I couldn't watch the video, it requires SilverLight which I don't want to bother installing.

Off the bat, I would have to say that if you plan to make anything more complex than a few very simple GUI elements, just bare-bone Win32 API is probably not what you would want to use. Plus, it's definitely not cross-platform. Qt would be a much better option.

>>I'm really just wondering how to organize the window procedures for my Dialogs/Buttons/etc.
That is what Object Oriented Programming is for. Win32 API is kinda awkward to use for complicated interfaces because it's all procedural (C-style). The best you can do is wrap those API calls into sensible classes. Often, you can just reflect the underlying structure. When you create Window, you get a HWND handle (which is most probably a pointer to an object that was created by the windows library) and only a set of functions can use this HWND. Well, naturally, you can just create your own class that has an HWND as private member, and whose constructor/destructor create and destroy the Window, for example. Doing this will make it a lot easier to use after... but the problem with that, is that it is a lot of work, and that work has already been done for you in countless GUI tools like Qt, wxWidget, MFC, VCL/CLX, etc. You would definitely be better off, in the long run, to get used to one of those.

>>Would one normally after creating a dialog throw the window procedure into a new file? I don't like tiny bits of code in different files, so I decided to ask for another opinion.

I don't like tiny bits of code in different files either, but I hate large source files with tons of functions of mixed purpose. Typically, you organize the code such that what is relevant to one specific task is in one specific file. It is more about logical separation than about file sizes. The motivation for this is that if you are concentrating on a particular sub-problem or aspect of the program, you want to work with a source file that contains what you need to work with, and not anything else that just gets in the way and forces you to scroll up-and-down all the time. Usually, in OOP, you often end up with one header and one cpp per class which may or may not include a few additional small helper classes or structs or enums or whatever. This is also good for compilation times. Unless you have a really good reason, don't make it more fine-grained than that. And it is acceptable to have a few medium-size classes in one header-cpp pair, but as long as they are really related.

>>As far as using Win32 goes, what does one need to know program code organization-wise?
I have never seen Win32 code that was well organized.. tidiness just isn't "compatible" with the Win32 API. Win32 is nice because it is quick and easy when you just want to pop-up a message-box, or a dialog of some sort, or if you need to create a window in which you are going render something else like a 3D scene with OpenGL or something like that. I have never seen people use it for anything more than that, and that usually doesn't require much organization (that is why it is nice for small test programs and stuff). But if you want to make even a basic GUI, it does require quite a bit of organizing the code properly, and for that Win32 just won't do because you have to do all the organizing yourself, which is tedious, so, again, better use a more elaborate GUI tool.


This might not answer your question, but what I sensed from your question is that you have started to play around a bit with Win32 and you are starting to realize that it isn't trivial to organize the code properly as you introduce more complexity to the application. This is in part because any GUI will require non-trivial organization and in part because the Win32 API is one of the GUI tools that provide the least amount of organization to start with. Any good programmer would have a hard time trying to make a clever, well-organized piece of code while using Win32.

I'm quite aware of QT and the others. I want to learn to use win32 effectively, just for the added skill.

If you're just starting out, you may find this tutorial page helpful. I know I did.

http://www.winprog.org/tutorial/

Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.