Presentation is loading. Please wait.

Presentation is loading. Please wait.

INTRODUCTION TO VC++ As the Microsoft Windows 3.X and then 5.5 operating system was becoming popular, many programmers were interested in creating graphical.

Similar presentations


Presentation on theme: "INTRODUCTION TO VC++ As the Microsoft Windows 3.X and then 5.5 operating system was becoming popular, many programmers were interested in creating graphical."— Presentation transcript:

1

2 INTRODUCTION TO VC++ As the Microsoft Windows 3.X and then 5.5 operating system was becoming popular, many programmers were interested in creating graphical programs. They had to use Win32, which made it possible only to use C to create programs With this approach, everything was done manually, including the design and code writing, which was an increasing demanding task, wasting a good deal of time.

3 MFC LIBRARY Win32 was written in C and had no native support for C++. Therefore, Microsoft created a library, named Microsoft Foundation Classes Library, and abbreviated MFC This library was originally an “adaptation” or customization of Win32, adding object-orientation (classes and inheritance) to it The MFC is a library and can be used to manually develop programs The Microsoft Foundation Class (MFC) library is a set of data types, functions, classes, and constants used to create applications

4 MICROSOFT VISUAL C++ To make the use of MFC friendlier, Microsoft developed Microsoft Visual C++ This is a graphical programming environment that allows designing Windows objects and writing code to implement their behavior As its name indicates, this environment takes C++ as its base language

5 The first thing you should do to start a program is to create an application. In Win32, an application is created by a call to the WinMain() function and building a WNDCLASS or WNDCLASSEX structures.Win32 In MFC, this process has been resumed in a class called CWinApp (Class-For-A-Windows- Application). Based on this, to create an application, you must derive your own class from CWinApp

6 An application by itself is an empty thing that only lets the operating system know that you are creating a program that will execute on the computer. It doesn't display anything on the screen. If you want to display something, the CWinApp class provides the InitApplication() method InitApplication() is a Boolean method. If it succeeds in creating the application, it returns TRUE. If something went wrong when trying to create the application, it would return FALSE.

7 The minimum skeleton of an application would appear as follows: class CExerciseApp : public CWinApp { public: virtual BOOL InitInstance(); }; BOOL CExerciseApp::InitInstance() { return TRUE; }

8 After creating the application, to make it available to other parts of the program, you must declare a global variable of your class. It is usually called theApp but you can call it anything you want The fundamental classes of MFC are declared in the afxwin.h header file. Therefore, this is the primary header you may have to add to each one of your applications.

9 Based on this, a basic application can be created as follows: #include class CExerciseApp : public CWinApp { public: virtual BOOL InitInstance(); }; BOOL CExerciseApp::InitInstance() { return TRUE; } CExerciseApp theApp;

10 As its name implies, a frame of a window includes the borders, the location, and the dimensions of a window. There are two types of MFC applications: those that use a frame and those that don't. A frame-based application uses a concept known as the Document/View Architecture. This allows the frame to serve as a place holder for other parts of an application (such as the document and the view).

11 To create a frame, the MFC library provides various classes. One of these is called CFrameWnd and it is the most commonly used frame class. To use a frame, you can derive your own class from CFrameWnd as follows: class CApplicationFrame : public CFrameWnd { };

12 The skeleton of this frame only serves as a foundation for your class. You must actually create a window frame that would display to the user. To create a window frame, the CFrameWnd class provides the Create() method. Its syntax is: BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle = WS_OVERLAPPEDWINDOW, const RECT& rect = rectDefault, CWnd* pParentWnd = NULL, LPCTSTR lpszMenuName = NULL, DWORD dwExStyle = 0, CCreateContext* pContext = NULL );

13 As you can see, the only two required arguments are the class name and the window name. We will come back to all these arguments when we study window classes in more details. For now, a minimum frame can be created by simply passing the class name as NULL and the window name with a null- terminated string. Here is an example class CMainFrame : public CFrameWnd { public: CMainFrame(); }; CMainFrame::CMainFrame() { Create(NULL, "MFC Fundamentals"); }

14 In order to provide a window to the application, you must create a thread. This would be done using the CWinThread class. To make this a little easy, CWinThread is equipped with a public member variable called m_pMainWnd. This variable can be used to create a thread for the main window of the application. One of its advantages is that it makes sure that your application terminates smoothly when the user decides to close it.

15 CWinThread is the base class of CWinApp and therefore makes m_pMainWnd available to any CWinThread derived class such as CFrameWnd. Based on this, to create a thread for the main window to display, you can assign a pointer of your frame class to m_pMainWnd. After this assignment, m_pMainWnd can be used as the window object to display the frame, which is usually done by calling the ShowWindow() method.

16 BOOL CExerciseApp::InitInstance() { m_pMainWnd = new CMainFrame; m_pMainWnd->ShowWindow(SW_NORMAL); return TRUE; }

17


Download ppt "INTRODUCTION TO VC++ As the Microsoft Windows 3.X and then 5.5 operating system was becoming popular, many programmers were interested in creating graphical."

Similar presentations


Ads by Google