Jeffrey J. Berkley, PhD - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Jeffrey J. Berkley, PhD

Description:

... your project at the top of the Resources Explorer View and then Add ... variable to a dialog and TRACE entered values to the View class. ... The View Class ... – PowerPoint PPT presentation

Number of Views:119
Avg rating:3.0/5.0
Slides: 18
Provided by: jeffrey63
Category:
Tags: phd | berkley | jeffrey | the | view

less

Transcript and Presenter's Notes

Title: Jeffrey J. Berkley, PhD


1
INDE 544 - Lecture 6
  • Jeffrey J. Berkley, PhD
  • Office 208 Sieg Hall
  • Office Hours 330-420 PM Tuesday Thursday
  • e-mail jberkley_at_u.washington.edu

2
Creating a Modal Dialog
  • Right click your project at the top of the
    Resources Explorer View and then Add-Resource.
  • From Add Resource dialog, select Dialog and then
    press the New button.
  • Open Properties to change the Caption and the ID
    name
  • Under Properties, be sure to select
    Behavior-Visible-TRUE, or you will not see the
    dialog when it is activated.
  • Add controls however you see fit.
  • Create a class for the dialog by double clicking
    it and naming the class.

3
Link the Dialog to Menu and Buttons
  • Add the new dialog header to the View class
  • Under your button or menu mapped function,
    declare the class as CYourDialog dlg
  • It can be activated with the function
    dlg-DoModal()
  • Example Create a dialog and activate it with
    menu, button or toolbar item.

4
Mapping Dialog Control to a Variable
  • After creating the dialog class, right click it
    from the Class Explorer View and choose
    Add-Variable
  • Check the Control variable checkbox and select
    Value from the Category drop down menu
  • Define the variable type, name and associate it
    with the proper Control ID.
  • Press Finish to continue.
  • To save entered data before the dialog is closed,
    use UpdateData(TRUE). The best time for this to
    happen is usually when the user hits the OK
    button. Add an event handler to the OK button
    and the add UpdateData() to the new function.
  • Example Map a text variable to a dialog and
    TRACE entered values to the View class.

5
More About Dialogs
  • To set the Tab order on your dialog box, Tab
    Order from the Format menu.
  • Click on the controls in order of preference and
    then press enter when done.

6
Creating a Dynamic Link Library (DLLs)
  • To create a DLL, choose New from the file menu,
    select MFC as the project type and MFC DLL as the
    template. You can create multiple projects in
    one workspace by creating the project from
    File-Add.
  • You will want to choose MFC Extension DLL so that
    you can use C classes.

7
Writing Libraries to a Common Folder
  • Usually you want to keep all of your libraries
    (.lib files) and dlls (.dll) in one place.
  • Library
  • lib
  • dlls
  • include
  • Right click on your dll project and bring up
    Properties. Under the Linker-General you can
    define the destination for your dll under Output
    File. Under Linker-Advanced you can define your
    library destination under Import Library. You
    can use ../ to step up one level in the folder
    tree from your current location.
  • Applications will first look for DLLs in the same
    directory were the application executable is,
    then the System folder and then in folders
    defined by the environment variable Path.
  • You can set your path as follows Right click My
    Computer and then click Properties. Under
    Advanced-Environment Variables you can access
    the path variable. Separate each new location
    with a semicolon. Do NOT leave a space after the
    semicolon. You will have to reboot your computer
    for these changes to take effect.

8
Making Your Class Available to a Library
  • To make a class available to a library, you must
    insert AFX_EXT_CLASS between class and the
    class name. For example
  • class AFX_EXT_CLASS Info
  • //stuff
  • Example Link a dll class to your project and
    utilize it.

9
Making a Function Available to your Library
  • In the dll project, insert the following before
    your function __declspec(dllexport)
  • In the project using the dll, declare the
    function in a header file with the following
    before your function__declspec(dllimport)
  • ExampleIn your dll project use__declspec(dllexp
    ort) double pow_n(double v1, int n)
  • double dRetv1
  • for(int i0i
  • return dRet
  • In the project using the dll use
  • __declspec(dllimport) double pow_n(double v1,
    int n)

10
Threads
  • Threaded applications allow for parallel
    processing and for different processes to operate
    at different rates
  • Haptic Thread 1000 Hz
  • Graphic Thread 30 Hz
  • A thread function is defined such as
  • UINT TimerThread(LPVOID pInfo)
  • // Code
  • return 0
  • To call the thread use
  • CWinThread AfxBeginThread( AFX_THREADPROC
    pfnThreadProc, LPVOID pParam, int nPriority
    THREAD_PRIORITY_NORMAL)

11
Threads
  • Threads are easiest to call as a functions,
    however, you can send a pointer to a class using
    the LPVOID variable. This way you can use MFC
    classes in the thread. The LPVOID variable can
    be used to pass any info you want.
  • UINT MyThread(LPVOID pInfo)
  • CFormView pView(CFormView ) pInfo
  • pView-MyFunction()
  • return 0

12
Saving and Loading Data
  • Under the Document class, you will find the
    Serialize() function. Use to extract items
    from the archive and archive.
  • Through the document class you can also use the
    function SetModifiedFlag() to indicate a document
    needs to be saved. To access this from the view
    class, use the GetDocument() function.
  • You can add a Serialize function to your own
    classes to save and restore data members.

13
Modeless Dialogs
  • Take a regular dialog and add a pointer to the
    view class. (i.e. CMyCodeView m_pView). Make
    sure to include MyCodeView.h in the
    ModlessDlg.cpp file and forward declare the class
    in ModlessDlg.h (i.e. class CModlessDlg)
  • Create an alternative constructor where the only
    input variable is a pointer to the view class.
    Simply copy the declaration in the header and the
    constructor in the base and insert the new
    arguments. For example replace (CWnd pParent
    /NULL/) with (CMyCodeView pView).
  • Copy the argument value to view pointer
    (m_pViewpView) is the constructor source code.
  • Add a Create() function to the modeless dialog
    like the following
  • BOOL CModelessDlgCreate()
  • return CDialogCreate(CModelessDlgIDD)
  • In both functions associated with the buttons OK
    and CANCEL, add DestroyWindow(). You cant use
    CDialogOnOK() or CDialogOnCancel() for a
    modeless dialog.

14
Modeless Dialog In The View Class
  • Create a pointer to the modeless dialog in the
    view class header (CModelessDialog
    m_pModelessDlg)
  • Initialize the dialog somewhere in your code
    (m_pModelessDlgnew CModelessDialog(new)). The
    constructor of the view class is a good place.
  • Delete the dialog in the view destructor (delete
    m_pModelessDlg)
  • When you want to activate the dialog, use
    m_pModelessDlg-Create()

15
Other Stuff
  • You can change the icon and title of your
    application in the App class. Check out the
    function InitIntance() in the example code.
  • // Sets window title and the icon
  • HICON hIcon LoadIcon(IDI_CLASS_ICON)
  • SetClassLong(m_pMainWnd-GetSafeHwnd(),
  • GCL_HICON, (LONG) hIcon)
  • m_pMainWnd-SetWindowText("Code Example 1")

16
Project 1
  • Motion Tracking interface
  • Requirements
  • Define a repetitive motion path in 3D space
  • Track and display the motion (can be with text)
  • User should be able to add an offset to the
    motion, while the simulation is running
  • Enable the simulation to pause, restart and reset
  • Programming
  • Create a dll that yields 3D motion
  • Motion should be executed through a thread.
  • UML Due April 23
  • Project Due April 28th

17
Next Week
  • OpenGL
Write a Comment
User Comments (0)
About PowerShow.com