PDA

Click to See Complete Forum and Search --> : Combining Win32 API with OOP


Sc0rp
Nov 16th, 2001, 04:18 PM
Hi, I'm currently reading a book about creating Windows based applications using API with C++.

And since it's API, it's mainly C, and less C++.
I'd like to build my applications using OOP, but without using MFC.

Where do I start?
Can you give me examples of basic classes used for Windows programming?


Thanks.

CornedBee
Nov 17th, 2001, 02:06 AM
Well, you'd have to come up with a basic concept: Do you want to make wrappers around the API (like MFC does), or do you only want some functional object that hide more of the API (a little bit like VB does).

Whatever you do, remember that CALLBACK functions can't be class member functions unless they are static.

parksie
Nov 17th, 2001, 07:20 AM
Welcome to the bandwagon :) Me and Kedaman are working on something similar ;) This is what the new Windows headers look like (I'm regenerating them with templates):namespace Win32 {
// Constants
const int WS_OVERLAPPED = 0x00000000L;
const int WS_POPUP = 0x80000000L;
const int WS_CHILD = 0x40000000L;
const int WS_MINIMIZE = 0x20000000L;
const int WS_VISIBLE = 0x10000000L;
const int WS_DISABLED = 0x08000000L;
const int WS_CLIPSIBLINGS = 0x04000000L;

extern "C" long __stdcall SetWindowLongA(HWND hWnd, int nIndex, long dwNewLong);
extern "C" long __stdcall SetWindowLongW(HWND hWnd, int nIndex, long dwNewLong);
template<class chrtyp> inline long __stdcall SetWindowLong(HWND hWnd, int nIndex, long dwNewLong);
inline long __stdcall SetWindowLong<char>(HWND hWnd, int nIndex, long dwNewLong)
{ return SetWindowLongA(hWnd, nIndex, dwNewLong); }
inline long __stdcall SetWindowLong<wchar_t>(HWND hWnd, int nIndex, long dwNewLong)
{ return SetWindowLongW(hWnd, nIndex, dwNewLong); }

CornedBee
Nov 17th, 2001, 01:46 PM
parksie: how about splitting it up into several namespaces, like
namespace Win32Window
{
CreateWindowA...
...
}
namespace Win32Thread
{
CreateThread...
...
}

You would need to come up with good seperations, but I think it wouldn't be bad.

parksie
Nov 17th, 2001, 04:47 PM
Well this is only there to prevent it polluting the :: namespace. These functions won't be used by any programs, since they'd use the abstraction layer (ask Ked, not me, he's the one with the bright idea :p)

CornedBee
Nov 18th, 2001, 03:03 AM
Well, if you'd ever need a bigger team, I'd work with you.

Zaei
Nov 18th, 2001, 09:44 AM
As would I. I cant stand having some random #define changing my custom DLL DrawText Call into DrawTextA....and then it wonders why it cant find a function with the parameters I am passing.

Z.

kedaman
Nov 18th, 2001, 02:00 PM
The idea is to use 1) Object Oriented Programming and 2) Generic Programming to build up layers for use in developing device independent applications.
Parksie is working on the mostly functional and parameterized namespace, which I will be building up several interfaces in a parameterized nested class hierarchy for use as "pseudo-polymorphism" in device independent programming.
All layers will be fully object oriented, so there will be no global functions nor handles floating around, typically you will be performing a bitblt like this:
TargetDC.Rect(10,10,50,50).Do( bitblt(srccopy) << SourceDC.Rect(10,10,50,50));
among other alternatives:
(TargetDC<<Myrect).Do<bitblt(srccopy) >(SourceDCrect);
The GDI object will provide access for the win32 environment with easy moves:
Window x=GDI.Window<caption>("My app");
x.minimize();
GDI.Window<top>().Destroy();
Window y=GDI.CreateWindow(wndclass,"my window",somepos);

Zaei
Nov 18th, 2001, 02:19 PM
That is quite a project! I cant wait to see how everything turns out.

Z.

kedaman
Nov 18th, 2001, 04:27 PM
Yeah, it's not going to be an overnight project, but rather slowly growing one
btw nice avatari :)

Zaei
Nov 18th, 2001, 06:02 PM
Thanks =). I thought it could go in for a change.

Z.

Sc0rp
Nov 21st, 2001, 01:50 PM
Hey, sorry for not replying; Just got back from a 3-day trip.

Anyway, I was looking for something more basic.
I'm just starting with C++ Windows programming, so I just want basic guidelines.
Primarily on the approach.

I have no idea where to start. :o

kedaman
Nov 21st, 2001, 02:00 PM
my recommendation is Sams teach yourself C++ in 21 days
http://newdata.box.sk/bx/c/

Sc0rp
Nov 21st, 2001, 02:48 PM
kedaman:

That's the book I used to learn C++.
What I would like are guidelines on how to apply the OOP techniques I learned there on Win32 programming.

kedaman
Nov 22nd, 2001, 04:43 AM
I'm not sure if there is such kind of things, win32api programming has been more or less functional with exception for MFC and GDI+ i guess but that's what I'm going to change in the nearest years ;)

Sc0rp
Nov 22nd, 2001, 01:46 PM
OK, thanks for your time everybody. ;)