Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to hide winmain

Posted on 2004-10-12
4
Medium Priority
?
682 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 200 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
Suggested Courses

636 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