How can I get MFC support apart from creating MFC application using App Wizard?

c++, mfc, visual-c++, visual-studio-2008

Solution

You can create an MFC app manually, there are a lot of dependencies and fussing around. But it can be fun to do. Here is a small tutorial.

Create the following HelloMFC file:

#include <afxwin.h>

  class HelloApplication : public CWinApp
  {
  public:     
   virtual BOOL InitInstance();
  };

  HelloApplication HelloApp;

  class HelloWindow : public CFrameWnd
  {        
   CButton* m_pHelloButton;
  public:     
   HelloWindow();
  };


  BOOL HelloApplication::InitInstance()
  {        
   m_pMainWnd = new HelloWindow();       
   m_pMainWnd->ShowWindow(m_nCmdShow);      
   m_pMainWnd->UpdateWindow();      
   return TRUE;
  }


  HelloWindow::HelloWindow()
  {        
   Create(NULL,             
    "Hello World!",               
    WS_OVERLAPPEDWINDOW|WS_HSCROLL,                
    CRect(0,0,140,80));        
   m_pHelloButton = new CButton();
   m_pHelloButton->Create("Hello World!",WS_CHILD|WS_VISIBLE,CRect(20,20,120,40),this,1);
  }

To Compile this at the command line, there's are all the libraries that need to be linked. You will notice that there is no WinMain or main in the code above. MFC burried its main in the libraries. It is defined in `appmodul.cpp` which you can find in your MFC\SRC directory.

Anyway, here is how you can compile the above code:

cl.exe hellomfc.cpp /EHsc /I atlmfc\include /I Includes /I Includes\Winsdk atlmfc\lib\amd64\nafxcw.lib Libs\libcmt.lib Libs\Ke rnel32.Lib Libs\User32.Lib Libs\Gdi32.Lib Libs\MSImg32.Lib Libs\ComDlg32.Lib Lib s\WinSpool.Lib Libs\AdvAPI32.Lib Libs\Shell32.Lib Libs\ComCtl32.Lib Libs\ShLwApi .Lib Libs\Uuid.lib atlmfc\lib\amd64\atls.lib Libs\Ole32.Lib Libs\OleAut32.Lib Li bs\oldnames.lib Libs\WS2_32.Lib Libs\MsWSock.Lib Libs\OleAcc.Lib Libs\comsuppw.l ib Libs\GdiPlus.lib Libs\Imm32.Lib Libs\WinMM.Lib Libs\MsXml2.Lib Libs\OleDlg.L ib Libs\Urlmon.Lib /link/SUBSYSTEM:WINDOWS

Note: the above obviously depends on the specific location of your library files, but those are the required libraries.

Problem

I know that when we use App Wizard for creating an MFC application in VC++, the wizard automatically adds the required libs to the project. I want to create an MFC application manually. How to do that?

Original source