Integration of OOP with the win32 API

Hi guys,

I've been studying C and C++ for a while now and I'm looking forward to learn Win32 programming with MS Visual Studio C++. However, there's something I can't seem to get the hang of.

I know enough C++ to understand OOP, but I don't see how OOP integrates with Win32 programming. I mean, I've been studying and writing console programs, but Win32 programs seem to have nothing to do with that way of programming. My guess is that to write Windows programs, you associate your code with user interface objects, but I would like to see a working example of how you create your own class and integrate it into a Win32 program in this manner.

I'm now into Petzold's book, but it seems he won't fully or directly answer this question, and It's a crucial one for me. So, if anyone could point me in the right direction or give me a brief summary about how OOP integrates with Win32 programming, It'd be greatly appreciated. I also think it might help intermediate programmers, so it's not only me.

Thanx.
Last edited on
Do You mean something like this? http://msdn.microsoft.com/en-us/library/ff381400%28v=VS.85%29.aspx (scroll down a bit)...
Since we're at it, is there a reason MSDN uses C++ casts all over the place except for this one line?

SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pState);

My own version uses a reinterpret_cast and I have had no problems. As far as I'm aware, they should compile to the same thing.
It´s less efford and the compiler warnings are still on :D... I think it depends on the author...

In the winsock examples it´s the same...

How long are the explicit casting operators part of the standard?... And the Win32 API is from the good old c-times...
Microsoft started the development of the Windows Api back in the early 80s long before C++ and OOP came into widespread use. To maintain cross language compatibility the Win Api is strictly procedural and C based. If the Win Api would have been done in Microsoft C++ using OOP, likely only Microsoft languages would have been able to use it. Until COM came around in the early 90s, there was no industry standard in terms of the binary layout of 'objects'.

I have been programming for a long time and have used many languages and approaches. What works best for me is to use the Win Api directly 'as is' for my GUIs, and use C++ objects strictly as 'business objects'. For example, I've written C++ OOP wrappers around my ODBC database access library. Also, I use my own String class instead of Microsoft's or the one in the std C++ library.

Most folks I guess prefer to use OOP wrappers around the Win32 Api (MFC, .NET, etc). I differ in that regard - as I stated. What I do do however, is use a modified form of your standard SDK style program where I use my own message crackers and message routing scheme. I really don't like the design of the standard Sdk style program with the massive switch construct. That's a good way to start learning though; and Petzold is a good teacher.

Last edited on
Topic archived. No new replies allowed.