Object Oriented Windows API Example

Just out of curiosity does anyone have an example of a simple Win32 program in an object oriented format? I'm aware that the Windows API is not object oriented but I was just looking for an example with a blank window? Having trouble and just wondering how it could be done? Thanks.
Here's one, "bare-bones" take from Raymond Chen's "The Old New Thing" blog.

Andy

The new scratch program
http://blogs.msdn.com/b/oldnewthing/archive/2005/04/22/410773.aspx
Last edited on

...I'm aware that the Windows API is not object oriented...


It most certainly is. You are simply not familiar with what OOP looks like implemented in C. Its important to realize that OOP is not a programming language, but rather a programming paradigm.

Here is some food for thought ...

What to you think the HWND parameter is actually that is the first parameter of most GUI related Api functions?
closed account (Dy7SLyTq)
You are simply not familiar with what OOP looks like implemented in C
c is most certainly not oop. the closest thing it has is data structures. unless you make alterations to the compiler (at which point its not c) or do what lib cello did, and that isnt even truly oop. if the win api is written in c then it isnt oop. its abstracted to look like that.
if the win api is written in c then it isnt oop

Just because C doesn't provide language features to support (i.e. make it easy to write) object-oriented code doesn't mean you cannot write object-oriented C.

Object-Oriented Programming In C
http://www.drdobbs.com/object-oriented-programming-in-c/184402190

In the Windows API, the various handle types are generally--as you no doubt know--handles (opaque pointers) to structs which hold the state of an objects. The functions which act on the handles (or rather, the objects they identify) of a given type can be considered to be "methods" of the corresponding "class" of object. So in this sense the WinAPI can be taken to object-oriented, at least to a certain extent.

Andy
Last edited on

... the closest thing it has is data structures...


And they are objects. But data structures may not have functions you say? Well, this one does ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
typedef struct _WNDCLASSEX 
{ 
    UINT    cbSize; 
    UINT    style; 
    WNDPROC lpfnWndProc; 
    int     cbClsExtra; 
    int     cbWndExtra; 
    HANDLE  hInstance; 
    HICON   hIcon; 
    HCURSOR hCursor; 
    HBRUSH  hbrBackground; 
    LPCTSTR lpszMenuName; 
    LPCTSTR lpszClassName; 
    HICON   hIconSm; 
} WNDCLASSEX; 



And in fact, its the most important function in Windows Programming (C or otherwise), that is, WNDPROC lpfnWndProc. It has a special name. We call it the Window Procedure, with capital letters.

I'm glad I answered this thread. It gives me some appreciation on the real level of misunderstanding out there, by folks one would think would know better. Makes me wonder what folks think happens to their C++ OOP code when the compiler gets it and spits out C or asm code. Apparently, something that started out as bona fide Stroustrup approved C++ code is somehow undone into something less OOP pure? That isn't how it works.

The reverse is also true. Everything written in C++ isn't OOP code. It isn't C++ that makes code OOP compliant, the same way that it isn't C or asm that makes code non OOP compliant. OOP is a coding methodology or paradigm, if you will, and there are many languages that support it to varying degrees. Here in this forum right now it wouldn't take me very long to find piles of C++ code by beginners who are breaking every rule of OOP based design (just about every program with piles of global variables stuck all over the place like right under the includes and plastered all over the Window Procedure.
Last edited on
Topic archived. No new replies allowed.