Solved

How to hide winmain

Posted on 2004-10-12
4
665 Views
Last Modified: 2010-08-05
How can I hide winmain from my project and replace it with my own main() function?

I'd like to have my programs inherit from CApp kind of like what's below (CApp would contain the guts for mostly everything like creating the window, processing messages as well as containing winmain if it can be done)

//-------------------------------
// main.h
class CMyApp: public CApp
{
      void Main();
      void Init();
      void Paint();
      void ShutDown();
};



//-------------------------------
// main.cpp
#include "Main.h"

void Main()
{
      CMyApp MyApp;
}
void CMyApp::Init()
{
}
void CMyApp::Paint()
{
}
void CMyApp::ShutDown()
{
}
//-------------------------------

I'm striving for api, cpu and os independence, that's the reason behind replacing the main with my own and hiding it in CApp.
0
Comment
Question by:Mag2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
stefan73 earned 100 total points
ID: 12286051
Hi Mag2000,
You can use defines for this, like:

platform.h:
#ifdef _WIN32
#define APPMAIN winmain
#else
#define APPMAIN main
#endif

main.cpp:
int APPMAIN(){
    ...call platform-specific init
    ...call generic
    ...etc.
}



Cheers!

Stefan
0
 

Author Comment

by:Mag2000
ID: 12286271
What about the parameters of Winmain? (HINSTANCE Instance, HINSTANCE PreviousInstance, LPSTR pCommandLine, int CommandShow)

I'd like to hide the parameters in CApp. And save the parameters as member variables of CApp?
0
 
LVL 12

Expert Comment

by:stefan73
ID: 12287947
Mag2000,
Yes, that's a possibility. But you're probably better off using CApp as an abstract base class, having generic methods, and deriving from that a WinApp and a UnixApp class. Beware, though, that Win-specific code won't compile on Unix, and vice versa.

I'm not quite sure what you're aiming at. Do you want to write an OS-independent GUI library? That's a very long way to go, even for a brave soul :-)
0
 

Author Comment

by:Mag2000
ID: 12291815
Actually that's pretty much what I'm doing. My MyApp is a derived class from CApp which is abstract.

I don't care if my CApp is not 100 percent OS independent, only the MyApp class. CApp (the abstract class) is more or less going to be a graphic engine that I want my applications to build off of. Were MyApp will use the functionality inherited from this abstract class as the bases for coding my programs.

Code wise I want it to look like the above classes (main.h, main.cpp) with the winmain, creation of windows, message pump, ect. all hidden in the CApp abstract class.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question