Building an MFC Application Using the Wizard. Terms Solution – A container for related projects – An executable or DLL – May be constructed from multiple.

Slides:



Advertisements
Similar presentations
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Advertisements

The Web Warrior Guide to Web Design Technologies
© by Pearson Education, Inc. All Rights Reserved.
Introduction to Microsoft Windows MFC Programming: the Application/Window Approach Lecture 4.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Operating Systems Day 4. Cascade Windows 1.Open one or more windows 2.Right click on task bar 3.Click cascade windows menu item Tile Windows 1.Open one.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
CHAPTER SIX Loop Structures.
1 ENG236: ENG236: C++ Programming Environment (2) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
McGraw-Hill© 2007 The McGraw-Hill Companies, Inc. All rights reserved. 1-1.
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.
CS5103 Software Engineering Lecture 08 Android Development II.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Working with Unmanaged Code.
Computing IV Visual C Introduction with OpenCV Example Xinwen Fu.
Using Visual Studio 2013 An Integrated Development Environment (IDE)
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
IE 411/511: Visual Programming for Industrial Applications
Chapter 9 Programming with Web Forms Programming In Visual Basic.NET.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
Website Development with Dreamweaver
Visual C++ Lecture 11 Friday, 29 Aug Windows Graphic User Interface l Event driven programming environment l Windows graphic libraries (X11 on Unix,
C++ MFCs CS 123/CS 231. MFC: Writing Applications for Windows zClasses in MFC make up an application framework zFramework defines the skeleton of an application.
Getting Started The structure of a simple wxWidgets program, Look at where and how a wxWidgets application starts and ends, how to show the main window,
Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)
Domain 3 Understanding the Adobe Dreamweaver CS5 Interface.
Chapter 1: Hello, MFC Your first MFC Application Department of Digital Contents Sang Il Park.
MFC Windows Programming: Document/View Approach More detailed notes at: 360/notes-html/class15.htm.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Overview of Previous Lesson(s) Over View  Microsoft Foundation Classes (MFC)  A set of predefined classes upon which Windows programming with Visual.
Introduction It is developed to create software applications. It is a tool for developers of any program that uses both basic and expert settings. It.
Microsoft Foundation Classes. What is MFC? Set of C++ classes written by MS Simplifies writing complex programs Covers many areas: – GUI – I/O – O/S interfaces.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files.
Lesson 11: Looking at Files and Folders what a file or folder is on the computer how to recognize a file or folder on the desktop how to recognize the.
1 Chapter 12 – Web Applications 12.1 Programming for the Web, Part I 12.2 Programming for the Web, Part II 12.3 Using Databases in Web Programs.
Using Microsoft Visual Studio 2005 Original by Suma Rao Revised by John G. McMahon ( 9/6/2008 )
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
1 Getting Started with C++. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Visual Studio 2008.
Bitmap (Chapter 15).
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Chapter2: Drawing a Window. Review: Introducing MFC.
Chapter2: Drawing a Window
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 2 – Welcome Application Introduction to Graphical.
Introducing Dreamweaver. Dreamweaver The web development application used to create web pages Part of the Adobe creative suite.
Open project in Microsoft Visual Studio → build program in “Release” mode.
Overview of Previous Lesson(s) Over View 3 Program.
Working with the Window Object JavaScript considers the browser window an object, which it calls the window object.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Overview of Previous Lesson(s) Over View  Windows Programming  WinMain()  Where execution of the program begins and basic program initialization is.
Entity Framework Database Connection with ASP Notes from started/getting-started-with-ef-using-mvc/creating-an-
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
Building an MFC Application
Chapter 14 Windows Programming with the Microsoft Foundation Classes
Microsoft Foundation Classes MFC
Chapter 2: The Visual Studio .NET Development Environment
Steps to Build Frame Window Recipe Application
Android Studio, Android System Basics and Git
Introduction to the Visual C# 2005 Express Edition IDE
Using Procedures and Exception Handling
Microsoft Visual Studio
How to organize and document your classes
Microsoft Windows 7 Basics
Chapter 12 Windows Programming with the Microsoft Foundation Classes
Steps to Build Frame Window Recipe Application
Presentation transcript:

Building an MFC Application Using the Wizard

Terms Solution – A container for related projects – An executable or DLL – May be constructed from multiple projects – Each project or solution is a directory and its contents – May have different versions – May generate multiple applications – Solutions & projects manageable in W. Explorer – Logical relationship of solution:components does not necessarily mirror the way they are stored on disk.

Solutions, Projects & directories Solution1 (in VS explorer view) – App1 (Project 1) X.cpp X.h – App2 (Project 2) – App3 (Project 3) Visual Studio Projects (WinExplorer view) – Solution 1 (folder) App1 (folder) App2 (folder) App3 (folder) Solution1.sln(shareable metadata) Solution1.suo(user-specific metadata) App1 might depend on App2 & App3 – Managed with project dependencies

Project A container for items e.g.; code,.rc files May be used in other projects Types specify language,etc.

Using VS 2013 Premiere - 1 Open VS Select File  new  Project Select Visual C++ In the center area, select MFC Application At the bottom of the screen, enter a name for your project (like "JSmith-MFC-app") – (use your own name!!) – At the bottom right corner Check the box for "create directory" Click OK

Using VS 2013 Premiere - 2 In the navigation panel, right-click your project name (NOT the solution name) Click on Properties Ensure these values are present: – Under General: Configuration type: Application (.exe) Use of MFC: Use MFC in a Shared DLL – Assumes user's PC has MFC installed – Faster than "Use MFC in a static library" Common language runtime (CLR): no CLR – Under C/C++, Code Generation, Runtime Library "Multithreaded Debug" – Under Pre-compiled headers: "Not using pre-compiled headers "

Using VS 2013 Premiere - 3 You should now have – Two.h files MainFrame.h – function prototypes & global variables MyWinApp.h – name of your program & project #include class CMyWinApp : public CWinApp {public: virtual BOOL InitInstance(); }; – Three.cpp files Main.cpp #include " MyWinApp.h " CMyWinApp MyApplication; MyWinApp.cpp – #include MyWinApp.h, InitInstance code MainFrame.cpp – #include both.h files, everything else

Classes & Global variables Declare global vars in MainFrm.h Define, initialize in PreCreateWindow or in OnCreate following is in MainFrm.h class CMainFrame : public CFrameWnd {// no initializations here!!! private: // declare global variables here public: // declare constructors and prototypes for // other functions in MainFrame.cpp void OnPaint(); // for example }

Flow of execution (hidden) WinMain runs InitInstance begins – CMainFrame runs (does nothing in our case) – Main window object (CREATESTRUCT) created – PreCreateWindow Allows "filling-in" of struct values Window exists but is not displayed yet Sends WM_CREATE on ending – OnCreate Creates a view to occupy the window Creates a status bar (if requested) Initialize your own variables here InitInstance ends – sends WM_PAINT OnPaint writes/draws text & graphics, shows screen

PreCreateWindow Optional settings "cs" is the name of the CREATESTRUCT passed to the PreCreateWindow member cs.lpszName = title; (a CString init'd here) cs.x = 0;//Y pos of window cs.y = 0;//X pos of window cs.cx = 700;//window width cs.cy = 300;//window height

OnCreate Most actions inserted by the Wizard Can now SetFont, use it's size Compute row positions for TextOut/DrawText

OnPaint Must do: – CPaintDC dc(this); // Invalidate window so entire client area // is redrawn when UpdateWindow is called. – Invalidate(); // Update Window to cause View to redraw. – UpdateWindow(); MAY do this: – SetFont(&myfont, true); – dc.TextOut(formatted string);

Setting Font VERIFY(myfont.CreateFont( 24,// nHeight in points 0,// nWidth 0,// nEscapement 0,// nOrientation FW_NORMAL,// nWeight TRUE,// bItalic FALSE,// bUnderline 0,// cStrikeOut ANSI_CHARSET,// nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision DEFAULT_QUALITY, // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily _T("Arial")));// lpszFacename SetFont(&myfont, true);

Debugging tips AfxMessageBox (_T("your message")); Be CAREFUL where you put AfxMessageBox. – If it's in an OnMove, it will pop up for EVERY pixel of the movement!! – Same for OnPaint (pops up for each redraw) – May need to test for !m_wndView in OnSetFocus Use a test to prevent multiple popups Win32API attribute "afx_msg" is empty: – E.g.; afx_msg int OnCreate(…) – "afx_msg" does not apply to MFC programs – Can be safely omitted when coding – Wizard keeps it for commonality

Window Creation Create new frame window object CMainFrame* pFrame = new CMainFrame; CMainFrame is the frame object pFrame points to the object Set it as main window object m_pMainWnd = pFrame; Load frame's resources pFrame->LoadFrame(……parameters….) Now show & update the window Notes: – "stdafx.h" includes "afxwin.h" – m_pMainWnd is defined in afxwin.h – Starting with version 3.0, all MFC classes are "thread safe" and require the multi-threaded run-time libraries to link successfully. – Do NOT add: #include to your code

MFC-Hello sample MainFrm.cpp – 1 message map (for CMainFrame class) – handlers - on_wm_create(), on_wm_setfocus() MFC-hello.cpp – 2 message maps (for CMFChelloApp class, for CAboutDlg class) – there are two message maps, because there are 2 classes, though the message map for the CAboutDlg class does not have any handlers. – rule is 1 map per class Childview.cpp - 1 message map for the cChildview class.

Basic Structure of an MFC program Main.cppMyWinApp.cpp MainFrame.cpp MyWinApp.h MainFrame.h afxwin.h

Using fonts CreateFont – allows specifying EVERYTHING CreatePointFont – specify only size & typeface Cfont myfont; myfont.CreateFont (…); or myfont.CreatePointFont (…); Activate it: – Method 1 (using a pointer to the context object) CDC* dc; dc = GetDC(); CFont * fontptr = dc->SelectObject(&myfont); – Method 2 (using the context object directly) CPaintDC dc(this);// "this" is handle for current window CFont * fontptr = dc.SelectObject(&myfont);

Resource (.rc) files Collection of UI elements – Provide info to user Icons Bitmaps Toolbars Cursors Dialogs Accelerators

Resource files & their content Projname.rc – toolbars, dialog boxes, etc. – Accelerator and string tables. – Default "About" dialog box. Resource.h – definitions for the resources Projname.ico – The icon file for the project or a control