Steps to Build Frame Window Recipe Application - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Steps to Build Frame Window Recipe Application

Description:

Enter the return type BOOL and the name getToggle ... Compile and show that this works. Syracuse University. Adding code and some variables ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 31
Provided by: carme50
Category:

less

Transcript and Presenter's Notes

Title: Steps to Build Frame Window Recipe Application


1
Steps to Build Frame WindowRecipe Application
Camen Vaca Ruiz MFC Windows Applications
2
Goals of the Project
  • Display a static text message in the center of
    the client area.
  • Show current mouse coordinates in a text message
    above the static message.
  • Show current mouse coordinates in static control
    above the message from item 2., demonstrates how
    that can be done.
  • Toggle the message from item 2. on and off, using
    a menu selection labeled toggle

3
Running Application
4
Build a blank solution
5
Single Document Interface
6
Construction Steps- Resource Editor
  • Click on
  • View/ Resource View
  • FWRecipe/menu/IDR_MAINFRAME. That shows the menu
    bar.
  • Click on
  • Edit item, and select each of its items in turn
    and hit the delete key to remove them.
  • Type in the word Toggle in the box below the Edit
    tag.
  • You can simply hit Delete.

7
RESOURCE VIEW- Add menus
  • Compile the program to see an empty frame window
    with the normal system menu
  • When you click on edit you will see the single
    Toggle item grayed out. It is grayed out because
    we have not defined a message handler for that
    yet.

8
Use class wizard to add Menu Handler
  • To add a handler in the menu option
  • Right click on Toggle/ Add Event Handler
  • Choose CMainFrame unde Class Name
  • Change Function handler name to OnToggle
  • Click Add and Edit
  • Add the code of the example to the function body

9
Construction Steps- Add Member variable
  • To add a member variable
  • Click Menu View ? Class View (excellent view for
    navigating around your code and initiating class
    wizard activities)
  • Right click on CmainFrame class and select Add
    Member Variable.
  • Enter the type BOOL and name m_bToggle.
  • MAKE SURE YOU SELECT Private Public is the
    default selection.
  • Click Finish This creates a private member
    variable named m_bToggle in the CmainFrame class
    to hold the state of the menu toggle.

10
Construction Steps- Add Member variable
11
Construction Steps- Add a function
  • Add a function
  • Right click on CmainFrame in the Class View again
  • Select Add Member Function
  • Enter the return type BOOL and the name getToggle
  • This time leave the selection of Access as
    public. This will create an accessor function
    for your view to get the state of the toggle.
  • Add the code return m_bToggle to the function
    body.

12
Adding a function
13
Adding a function
14
Steps to support View
  • Go to Class View
  • Double click on the CChildView class
  • View the inline function OnPaint() that the
    wizard has defined for you.
  • Add the code from the class example to the
    OnPaint() function

15
Adding Message Handlers
  • Right click on the CChildView class
  • Choose Properties. Click on Messages button
  • Select WM_LBUTTONDOWN, and Add
  • Repeat for WM_MOUSEMOVE and WM_CREATE
  • Note that the class wizard has already provided
    the message hanler for the WM_PAINT message (the
    OnPaint function we looked at before).

16
Adding Message Handler for Mouse
17
Adding code to message Handlers
  • Add code from the class example to OnMouseMove
    and OnLButtonDown message handler functions,
    skipping the last four lines in OnMouseMove.
  • Add member variables (int)
  • m_DisplayX, m_DisplayY, m_MouseX, m_MouseY,
    m_TriangleX and m_TriangleY as private
  • Do that using the wizard like we did before, or
    add them manually by typing into the class
    declaration.
  • These code additions will draw the static text in
    the center of the diagram, draw a triangle at the
    cursor when the left button is clicked, and show
    the mouse coordiates in a text messge. Compile
    and show that this works.

18
Adding code and some variables
19
Add Static Control to Client Area
  • Now, we want to add the static control to also
    show mouse coordinates.
  • Go to the FileView and double click on resource.h
    to see the contents of that file in the edit
    window. Add define IDC_STATIC1 and pick a
    number to enter on the right which is one more
    that the highest number shown in the top group.
    Add 1 to the value of _APS_NEXT_COMMAND_VALUE.
  • Add the member variable m_pCStatic as a private
    data member of the CChildView class typed as
    Cstatic.
  • Go to the ChildViewOnCreate function and add
    the statements
  • m_pStatic new CStatic()
  • CRect rect(CPoint(100,70),CSize(90,22))
  • m_pCStatic-gtCreate(,WS_CHILDWS_VISIBLEWS_BOR
    DER, rect, this, IDC_STATIC1)
  • This creates the static control. Add the bottom
    four lines of code from the CChildViewOnMouseMov
    e function in my example.

20
Add Static Control to Client Area
  • Now, we want to add the static control to also
    show mouse coordinates.
  • Go to the Solution Explore
  • Double click on resource.h to see the contents of
    that file in the edit window.
  • Add define IDC_STATIC1 and pick a number to
    enter on the right which is one more that the
    highest number shown in the top group.
  • Add 1 to the value of _APS_NEXT_COMMAND_VALUE.

21
Add Static Control to Client Area
  • Add the member variable m_pCStatic as a private
    data member of the CChildView class typed as
    Cstatic.
  • Go to the ChildViewOnCreate function and add
    the statements
  • m_pStatic new CStatic()
  • CRect rect(CPoint(100,70),CSize(90,22))
  • m_pCStatic-gtCreate(,WS_CHILDWS_VISIBLEWS_BOR
    DER, rect, this, IDC_STATIC1)
  • This creates the static control. Add the bottom
    four lines of code from the CChildViewOnMouseMov
    e function in my example.

22
Static variable defined in ChildView.h
23
Add Code to Handle Messages
24
Initialize Members in Main and Child Classes
  • Finally, we need to give initial values to the
    member variables we added to CMainFrame and
    CChildView.
  • Add the intializer m_bToggle(TRUE) to the
    CMainFrameCMainFrame() constructor.
  • Add the intializers to the CChildViewCChildView(
    ) m_DisplayX(100), m_DisplayY(100),
    m_MouseX(0), m_MouseY(0), m_TriangleX(-1),
    m_TriangleY(-1), m_pCStatic(NULL)and add to
    the CChildViewCChildView() destructor
    delete m_pCStatic
  • Be sure you have these include directives in your
    ChildView.cpp file
  • include "MainFrm.h"
  • include ltsstreamgt
  • include ltiomanipgt
  • using namespace std
  • Compile and see the running program in all its
    glory.

25
Initialize MainFrame Member
26
Initialize Child View Members
27
Running Application
28
Structure of FWRecipe Program
29
Initialize Members in Main and Child Classes
  • Finally, we need to give initial values to the
    member variables we added to CMainFrame and
    CChildView.
  • Add the intializer m_bToggle(TRUE) to the
    CMainFrameCMainFrame() constructor.
  • Add the intializers to the CChildViewCChildView(
    ) m_DisplayX(100), m_DisplayY(100),
    m_MouseX(0), m_MouseY(0), m_TriangleX(-1),
    m_TriangleY(-1), m_pCStatic(NULL)and add to
    the CChildViewCChildView() destructor
    delete m_pCStatic
  • Compile and see the running program in all its
    glory.

30
Closing Notes
  • Test application by compiling and running each
    time you add a new Windows Message Handler.
  • Make sure you include stdafx in the cpp file
    for each server module you add we havent used
    any server modules in this example, but you will
    want to for any relatively complex application.
  • Test each server module as a stand-alone module,
    using its test stub, before you call it from the
    interface code.
  • Your server modules are usually called by the
    interface message handlers
  • They affect transformations on the applications
    data in response to user inputs.
Write a Comment
User Comments (0)
About PowerShow.com