• 13
• 16
• 27
• 9
• 9

# Creating a platform independent Window Class?

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

## Recommended Posts

I want to implement a class to handle the creation and management of Win32 windows (for now) that will also provide what I need for OpenGL (The hWnd for instance). I was planning on having a function such as CreateNewWindow() and others for returning the various handles and propreties but I'm unsure where to start. I also want to make it extendable so that once I know more Mac/Linux specific c++ I can update the class for those as well. Would it be possible to create it so that the class uses #ifdef to find the platform and runs code accordingly? Or would I need a sperate class for each? (because the mac code return return a hWnd for instance?) Could anyone point me a the right direction for now? Thanks :)

##### Share on other sites
wxWidgets is an open source cross-platform GUI library. I don't know if wxWidgets is good for high-performance apps (Games, etc ) but if you just need GUI stuff it should suffice.

hth,
Joe

##### Share on other sites
Thanks for the reply but I don't mean that.

I want to create my own class that wraps up all of the window work that needs to be done.

So I can do something like:

CWindow myWindow;

myWindow.CreateWindow(800, 600);

hWnd = myWindow.gethWnd();

##### Share on other sites
Quote:
 Original post by menghaThanks for the reply but I don't mean that.I want to create my own class that wraps up all of the window work that needs to be done.So I can do something like:CWindow myWindow;myWindow.CreateWindow(800, 600);hWnd = myWindow.gethWnd();

If you want this to be truely cross-platform, then you're going to have to forget about creating getters and setters for things like HWND. HWND is strictly a Windows idea. I suggest you start by designing your interface, being very careful to abstract away from any platform dependent features. That also means that you're going to have to learn to create and manage windows in several environments before you are to get started, so that you have a concept of what ideas you're going to need to create abstractions for.

##### Share on other sites
SDL already does this very well.

##### Share on other sites
Quote:
 Original post by menghaThanks for the reply but I don't mean that.I want to create my own class that wraps up all of the window work that needs to be done.So I can do something like:CWindow myWindow;myWindow.CreateWindow(800, 600);hWnd = myWindow.gethWnd();

window myWindow;window.createWindow(800,600);window.createOpenGLContext();