Win32 vs. MFC

Discussion in 'MFC' started by Sanskruti, Jan 12, 2007.

  1. Sanskruti

    Sanskruti New Member

    Jan 7, 2007
    Likes Received:
    Trophy Points:
    Software Consultant
    Mumbai, India

    Software Development Kit (SDK)

    It is a set of tools designed to help C programmers create Windows applications.

    Windows SDK consists of the large set of books describing functions, messages, structures, macros and resources .There are also tools including a dialog editor and an image editor, on-line help files and a set of windows libraries and header files. It has large collection of API functions written in C.

    What is an API?

    API is an acronym for Application Programming Interface.It is simply a set of functions that are part of Windows OS. Programs can be created by calling the functions present in the API.The programmer doesn’t have to bother about the internal working of the functions .By just knowing function prototype and return value he can invoke the API functions. A good understanding of Windows API would help you to become a good Windows programmer .Windows itself uses the API to perform its GUI magic.
    Windows APIs are of two basic varieties:
    API for 16-bit Windows (Win16 API)
    API for 32-bit Windows (Win32 API)
    Each of these have sub-APIs within it. If you are working in Windows 3.1 then you have to use Win16 API and in Windows NT you have to use Win32 API.

    Microsoft Foundation Class (MFC)

    VC++ provides us a rich class library called the MFC Library, which is a set of C++ classes that encapsulate the functionality of applications written for the Microsoft Windows Operating System. The class library gives you a complete application framework .The framework defines an architecture for integrating user interface of an application for Windows with the rest of the application. It also provides implementations for a set of the user-interface components.MFC represents entire family of class libraries.MFC offers high level of abstraction that lets you focus in details to your application while allowing its classes to be customized and extended.MFC makes programming in Windows and C++ a much more productive endeavour.It is a collection of Windows API calls which are written in C.Programming in MFC reduces the code to a considerable extent as compared to SDK.

    Let ‘s look at the program that creates simple window using MFC.

    #include <afxwin.h>
    //The  CWinApp class is the base class from which you derive 
    //a Windows  application  object.
    //An application  object provides member functions  for  initializing your application
    //(and each instance of it) and for running the application
    class mywin : public CFrameWnd 
    public :
    		Create (0,”HELLO – WINDOW”) ;
    class  myapp     :  public    CWinApp
    	// Override InitInstance to initialize each new  instance of your application running 
    	//under   Windows.Typically ,you  override  InitInstance  to construct  your main window //object and set the CWinThread : : m_pMainWnd  data member to point to that //window.
    	int   InitInstance()
    		mywin     *f ;
    		f = new   mywin;
    		f - >ShowWindow(3);
    		m_pMainWnd  = f;
    		return  1;
    myapp app;
    Lets see the same program to create a window in SDK as we did with MFC.

    #  include  <windows.h>
    HWND  hwnd;
    MSG  msg;
    WNDCLASS   wnd;
    int WINAPI  WinMain(HINSTANCE   h,HINSTANCE   p, LPSTR   s , int  show)
    	RegisterClass(&wnd) ;
    		DispatchMessage(&msg) ;
    	return msg.wParam;
    long  WINAPI process(HWND hd,UINT mess,WPARAM more,LPARAM pos)
            case   WM_CREATE:MessageBox(hd,"CREATING","wait!",0)  ;
            case   WM_ClOSE:MessageBox(hd,"Closing","wait",0);
    		case    WM_DESTROY:MessageBox(hd,"destroying","wait",0);
    	Return DefWindowProc(hd,mess,more,pos);

    Comparing MFC vs SDK program

    Thus we can see that programming in MFC reduces the code to a considerable extent as compared to SDK.

    This is because in SDK we have to write the whole code right from scratch,i.e,we need to write each and every function.Whereas in case of an MFC program the MFC does lot of things on behalf of the user, i.e we need not write each and every function explicitly.
  2. parvez.yu

    parvez.yu New Member

    Feb 14, 2008
    Likes Received:
    Trophy Points:

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice