posted on Saturday, September 25, 2004 7:59 PM by suniljagadish

Microsoft Visual C++ 6.0

I have joined a course for MS VC++. I’ve thought of putting up stuff o’er here as and when I am learning. I have classes on Saturday & Sunday. So, I’ll be summarizing stuff what I learnt for the day.

Today it was a class on basics of VC++ and its architecture. The topics that are going to be covered as a part of the course are:
1. Intro to MFC
2. MFC Base classes and Dialog boxes
3. MFC Applications
4. Intro to Com
5. COM objects and libraries
6. COM Interfaces
7. ActiveX Template Library
8. Creation of COM client
9. Automation and dual interfaces
10. ActiveX controls
11. Data access with ADO
12. Marshalling and COM threading models
13. ActiveX server components
14. COM using Microsoft Transaction Server
15. COM+ and Windows DNA

Class 1: Introduction to MFC

Overview of MFC
• MFC class library is an application framework for writing applications for Windows platform or any other platform that supports Win32 APIs
• It is a collection of C++ classes or in other words MFC is an encapsulation of large portion of Windows API in C++ form
• Using MFCs, we can create Windows dialog boxes, device context and other common graphic objects
• Classes provided by MFCs are accessed through interfaces. MFC code is compiled and converted into Win32 API calls.

Execution of MFC
There are two steps of execution:
1. Code compilation
2. Resource compilation

Code compilation: The source code is compiled along with the required libraries (windows headers and runtime header files) and an obj file is created.

Resource compilation: Resource files like images, icons, bitmaps etc compiled separately and a RES file is obtained.

The outputs of both the compilers (code and resource) are linked together and the final executable file is obtained.

MFC Base Classes
There are two main base classes in MFC:
1. cWinApp
2. cFrameWnd

cWinApp class: This is the base class from which a windows application object is derived. An application object consists of member functions for initializing applications. cWinApp class provides3 methods:

1. InitInstance(): This method is called when the application object is loaded into the memory.

2. Run(): This method acquires tand dispatches windows calls until the application receives the WM_QUIT (a constant), message. (ie. when “X” button is pressed)

3. ExitInstance(): It is called when an application object is removed from the memory


Just a sample program to create a frame and display a message box when InitInstance() is invoked

#include<afxwin.h>

class MyWindow : Public cFrameWnd
{
 Public:
  MyWindow()
  {
   // NULL is for icon
   create(NULL, “Sample window”);
}
~MyWindow()
{
 messageBox(“Sample window”, “cFrameWnd”);
}
};

class MyApp : Public cWinApp
{
 Public:
  // Override these methods
  BOOL InitInstance();
  BOOL ExitInstance();
}

BOOL MyApp :: InitInstance()
{
 :: messageBox(o, “Sample Window”, “InitInstance”, MB_OK | MB_ICONASTERIX);
 
 MyWindow mywinobj;
 Mywinobj = new MyWindow;

 // Speicify the main window
 M_PMainWnd = mywinobj;

 Mywinobj->showwindow(SW_SHOWMAXIMIZED);
return TRUE;
}

Comments