• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 684
  • Last Modified:

How to hide winmain

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
Mag2000
Asked:
Mag2000
  • 2
  • 2
1 Solution
 
stefan73Commented:
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
 
Mag2000Author Commented:
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
 
stefan73Commented:
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
 
Mag2000Author Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now