Solved

How to hide winmain

Posted on 2004-10-12
4
631 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now