Solved

How to hide winmain

Posted on 2004-10-12
4
655 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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

733 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