Building Applications Using VC

Embed Size (px)

Citation preview

  • 8/8/2019 Building Applications Using VC

    1/54

    Building Applications Using VC++

    Overview of OOP

    OOP is about trying to represent the Objects that we find in the realworld ( or at least that part of which programs address ) in software.

    WHAT IS OBJECT ?

    Objects are the elements through which we perceive the world around us,which have recognizable identities and particular behaviors.

    These Objects may be of various types, ranging from the physical to themore conceptual.

    In OOP there is mainly two kinds of Objects :

    Those that directly represent the ideas used to describe the application

    Those that are used as programming tools to implement code

    Object = (private) data + (public) processes

    Objects have a private part of hidden internal detail, and a

    public interface which clearly defines the set of possible

    behaviors of the object.

    Areas of Object technology

    The general field of object technology can be seen as falling into four areaof application :

    OOP

    OOD

    OOA

    OODBs

  • 8/8/2019 Building Applications Using VC

    2/54

    Key Features of OOP

    Abstraction / encapsulation

    Inheritance

    Polymorphism

    Abstraction / encapsulation

    It the representation of all the essential features of an object, whichmeans its possible states & behaviors.

    Encapsulation is the practice of including in an object everything it needs,(both data & processes) hidden from other objects in the system. Theinternal state of an object is not directly accessible from outside, and

    cannot be altered by external changes to the application.Changes to the internal implementation details can be made withoutaffecting the external interface.

    Inheritance

    Inheritance means that one class inherits the characteristics of another classas part of its definition. It appropriate when one class is a kind of otherclass (e.g. A is a kind of B text window is a kind of window). These typesof hierarchies are fundamental to OOP. Some classes may inherit from more

    than one other class, (multiple inheritance).

    Inheritance has two complementary roles :

    1. To allow class to be extended so that its existing functionality can bebuilt on for new applications.

    2. To allow similar objects to share their common properties & allowedbehaviors.

    3. Polymorphism

    4. It means having many forms. The general description of polymorphism is that it allows different objects to respond to the samemessage in different ways, the response specific to the type of object.This is achieved by various types of overloading - allowing asymbol ( operator like +) to have more than one meaning dependingon the context in which it is used.

  • 8/8/2019 Building Applications Using VC

    3/54

    5. Polymorphism is particularly important when object oriented programsare dynamically creating & destroying objects in a classificationhierarchy at run time.

    MFC Introduction

    Microsoft created a group called the AFX group (stands for(A)pplication (F)ramework(X)).

    They came up with a class library that presented a very highabstraction from the Windows API.

    The AFX group was actually responsible for two things: theMFC library and the IDE's support for MFC (namely, theresource editor and the wizards).

    MFC Classes

    CObject CException CBrush CListBox

    CWinApp CMemoryException CFont CComboBox

    CMenu CNotSupportedException

    CBitmap CScrollBar

    CArchive CArchiveException CPalette

    CDumpContext

    CFileException CRgn

    CRuntimeClass

    CResourceException CWnd

    CMemoryState

    CFile CFrameWnd

    CFileStatus CDC CMDIChildWnd

    CString CClientDC CMDIFrameWnd

  • 8/8/2019 Building Applications Using VC

    4/54

    CTime CWindowDC CDialog

    CTimeSpan CPaintDC CModalDialog

    CPoint CMetaFileDC CStatic

    CRect CGdiObject CButton

    CSize CPen CEdit

    CObject CException CBrush CListBox

    CWinApp CMemoryException CFont CComboBo

    x

    CMenu CNotSupportedException

    CBitmap CScrollBar

    CArchive CArchiveException CPalette

    CDumpContext

    CFileException CRgn

    CRuntimeClass

    CResourceException CWnd

    CMemoryState

    CFile CFrameWnd

    CFileStatus CDC CMDIChildWnd

    CString CClientDC CMDIFrameWnd

    CTime CWindowDC CDialog

    CTimeSpan CPaintDC CModalDialog

    CPoint CMetaFileDC CStatic

  • 8/8/2019 Building Applications Using VC

    5/54

    CRect CGdiObject CButton

    CSize CPen CEdit

    The Visual C++ Development Environment

    The Workspace

    When you start Visual C++ for the first time, an area on the left side of Developer Studio looks like it is taking up a lot of real estate andproviding little to show for it. This area is known as the workspace, andit is your key to navigating the various pieces and parts of your

  • 8/8/2019 Building Applications Using VC

    6/54

    development projects. The workspace allows you to view the parts of your application in three different ways:

    Class View allows you to navigate and manipulate your source codeon a C++ class level.

    Resource View allows you to find and edit each of the variousresources in your application, including dialog window designs, icons,and menus.

    File View allows you to view and navigate all the files that make upyour application.

  • 8/8/2019 Building Applications Using VC

    7/54

    The Output Pane

    The Output pane might not be visible when you start Visual C++ for

    the first time. After you compile your first application, it appears at thebottom of the Developer Studio environment and remains open untilyou choose to close it.

    The Output pane is where Developer Studio provides any informationthat it needs to give you; where you see all the compiler progressstatements, warnings, and error messages; and where the Visual C++debugger displays all the variables with their current values as youstep through your code.

    After you close the Output pane, it reopens itself when Visual C++ hasany message that it needs to display for you.

    Starting Your First Project

    Creating the Project Workspace

    Every application development project needs its own projectworkspace in Visual C++. The workspace includes thedirectories where the application source code is kept, as wellas the directories where the various build configuration filesare located. You can create a new project workspace byfollowing these steps:

    1. Select File | New. This opens the New Wizard

    2. On the Projects tab, select MFC AppWizard (exe).

    3. Type a name for your project, such as Hello, in theProject Name field.

    4. Click OK.

    This causes the New Wizard to do two things: create a projectdirectory (specified in the Location field) and then start theAppWizard.

  • 8/8/2019 Building Applications Using VC

    8/54

    Using the Application Wizard to Create the Application Shell

    The AppWizard asks you a series of questions about what typeof application you are building and what features andfunctionality you need. It uses this information to create ashell of an application that you can immediately compile andrun. This shell provides you with the basic infrastructure thatyou need to build your application around. You will see howthis works as you follow these steps:

    In Step 1 of the AppWizard, specify that you want tocreate a Dialog-based application. Click Next at thebottom of the wizard.

  • 8/8/2019 Building Applications Using VC

    9/54

    In Step 2 of the AppWizard, the wizard asks you about anumber of features that you can include in your application.

    You can uncheck the option for including support for ActiveXcontrols if you will not be using any ActiveX controls in yourapplication.

    Because you won't be using any ActiveX controls inapplication, go ahead and uncheck this box.

  • 8/8/2019 Building Applications Using VC

    10/54

    The final step of the AppWizard shows you the C++classes that the AppWizard will create for yourapplication.

    Click Finish to let AppWizard generate your applicationshell.

    Before AppWizard creates your application shell, itpresents you with a list of what it is going to put into the

    application shell, based on the options you selected whengoing through the AppWizard.

    Click OK and AppWizard generates your application.

  • 8/8/2019 Building Applications Using VC

    11/54

    After the AppWizard generates your application shell, you are returnedto the Developer Studio environment.

    You will notice that the workspace pane now presents you with a treeview of the classes in your application shell.

    You might also be presented with the main dialog window in the editorarea of the Developer Studio area.

  • 8/8/2019 Building Applications Using VC

    12/54

    To Build and Execute the project

    Select Build | Build Hello.exe to compile your application.

    As the Visual C++ compiler builds your application, you seeprogress and other compiler messages scroll by in the Outputpane. After your application is built, the Output pane shoulddisplay a message telling you that there were no errors orwarnings.

    The Output pane displays ( if )any compiler errors.

    Select Build | Execute Hello.exe to run your application.

    Your application presents a dialog with a TODO message and OK and Cancel buttons

  • 8/8/2019 Building Applications Using VC

    13/54

    You can click either button to close the application.

    Adding Code to Your Application

    You can attach code to your dialog through the Visual C++ ClassWizard.

    You can use the Class Wizard to build the table of Windows messagesthat the application might receive, including the functions they shouldbe passed to for processing, that the MFC macros use for attaching

    functionality to window controls.

    You can attach the functionality for this first application by followingthese steps:

    To attach some functionality to the Hello button, right-click overthe button and select Class Wizard from the pop-up menu.

  • 8/8/2019 Building Applications Using VC

    14/54

    With IDHELLO selected in the Object ID list, select BN_CLICKED inthe list of messages and click Add Function. This opens the AddMember Function dialog

    This dialog contains a suggestion for the function name. Click OK to create the function and add it to the message map.

    Finishing Touches

    Now that your application is functionally complete, you can still add a

    few details to finish off the project. Those finishing touches includeCreating the dialog box icon

    Adding maximize and minimize buttons

    Creating the Dialog Box Icon

  • 8/8/2019 Building Applications Using VC

    15/54

    In the tree view of your application resources in the workspace pane,expand the icon branch and select the IDR_MAINFRAME icon.

    This brings the application icon into the editor area of the DeveloperStudio.

    Using the painting tools provided, repaint the icon to display an imagethat you want to use to represent your application,

    Adding Maximize and Minimize Buttons

    In the dialog editor, where you design your application window, youcan add the minimize and maximize buttons to the title bar of yourapplication window by following these steps:

    Select the dialog window itself as if you were going to resize thewindow.

  • 8/8/2019 Building Applications Using VC

    16/54

    Using the pop-up menu (from right-clicking the mouse), selectthe dialog properties.

    Select the Styles tab

    After you turn on the minimize and maximize boxes, you cancompile and run your application. The minimize and maximizebuttons appear on the title bar

  • 8/8/2019 Building Applications Using VC

    17/54

    File Types in Project

    dsw :Workspace file

    .dsp :Project file

    .clw :ClassWizard file

    .ncb :No Compile Browser file(Contains details used byClassview & Classwizard Toolbar)

    .opt :Options file(Stores cusomized workspace display)

    .cpp :C++ source file (Implementation Code)

    .h :C++ header file(definition & class declaration code)

    .rc :Resource Script file(details of resources)

    .rc2 :Resource Script file(used to include resourcesin to otherprojects)

  • 8/8/2019 Building Applications Using VC

    18/54

    Understanding the Components of a Dialog-Based Application

    Dialog applications are much simpler than SDI and MDIapplications. Create one called FirstDialog , with an About box,no Help, 3D controls, no automation, ActiveX control support,no sockets, source file comments, and MFC as a shared DLL. Inother words, accept all the default options.

    Three classes have been created for you for the applicationcalled FirstDialog :

    CAboutDlg, a dialog class for the About dialog box

    CFirstDialogApp, a CWinApp class for the entire application

    CFirstDialogDlg, a dialog class for the entire application.

    All the familiar Windows controls are available for dialog boxes

    Static text . Not really a control, this is used to label othercontrols such as edit boxes.

    Edit box . Single line or multi line, this is a place for users totype strings or numbers as input to the program. Read-onlyedit boxes are used to display text.

    Button . Every dialog box starts with OK and Cancel buttons,but you can add as many of your own as you want.

    Check box . You use this control to set options on or off; eachoption can be selected or deselected independently.

    Radio button . You use this to select only one of a number of related options. Selecting one button deselects the rest.

    List box . You use this box type to select one item from a listhard coded into the dialog box or filled in by the program asthe dialog box is created. The user cannot type in the selectionarea.

  • 8/8/2019 Building Applications Using VC

    19/54

    Combo box . A combination of an edit box and a list box, thiscontrol enables users to select from a list or type theirresponse, if the one they want isn't on the list.

    The data types that go with each control type

    Edit box. Usually a string but also can be other data types,including int, float, and long

    Check box . int

    Radio button . int

    List box. String

    Combo box. String

    Scrollbar . int

    Access Values from a Control

    To access values from control in VC++ you have to createMember Variable ( It gives bound values connectivity tocontrol )

    OR

    You have to create Constructer derived from ControlClasses( to access values from control dynamically &unbound )

    To create Member Variable (bound) use following the steps :

    Select a control & Right Click and select Class Wizard or pressCTRL + W.

    Then Select Member Variables Tag

  • 8/8/2019 Building Applications Using VC

    20/54

    Then choose its type or category from given options

  • 8/8/2019 Building Applications Using VC

    21/54

    Data Validation

  • 8/8/2019 Building Applications Using VC

    22/54

    You can give the limitations to the variables

    To store the Values in variable

    Use UpdateData( ) function to clear or store the values inmember variable.

    To clear or restore the previous value use UpdateData( 0 )

    To store the value for display in control use

    UpdateData( 1 ).

    Creating Constructer Variable :

  • 8/8/2019 Building Applications Using VC

    23/54

    You have to create reference from base class of the relatedcontrol

    CONTROL BASE CLASS

    Buttons CButton

    List boxes CListBox

    Edit controls CEdit

    Combo boxes CComboBox

    Scroll bars CScrollBar

    Static controls CStatic

    Way of Creation

    CEdit* ed = (CEdit*)GetDlgItem(IDC_EDIT1);

    Where GetDlgItem() contains the name of Control;

    CEdit is the base class for EDIT BOX control & ed is theconstructer for the control

    ed will represent all the properties supported by the EDITBOX

    To add the local variable/functions

    To create local variable for your project choose following steps

    Right click on the dlg class from class view

    Select Add Member Variable or Add Member Function option(all the type of variable or function is same as C++)

  • 8/8/2019 Building Applications Using VC

    24/54

    File Types in Project

    dsw : Workspace file

    .dsp :Project file

  • 8/8/2019 Building Applications Using VC

    25/54

    .clw :ClassWizard file

    .ncb :No Compile Browser file(Contains details used byClassview & Classwizard Toolbar)

    .opt :Options file(Stores cusomized workspace display)

    .cpp :C++ source file (Implementation Code)

    .h :C++ header file(definition & class declaration code)

    A Single Document Interface Application

    An SDI application has menus that the user uses to open onedocument at a time and work with that document. This sectionpresents the code that is generated when you create an SDIapplication with no database or compound document support,with a toolbar, a status bar, Help, 3D controls, source filecomments, and with the MFC library as a shared DLL in otherwords when you accept all the AppWizard defaults after Step1.

    Five classes have been created for you. For the applicationFirstSDI, they are as follows:

    CAboutDlg, a dialog class for the About dialog box

    CFirstSDIApp, a CWinApp class for the entire application

    CFirstSDIDoc, a document class

    CFirstSDIView, a view class

    CMainFrame, a frame class

    In Last Step (6) you can select the base class for your SDIapplication.

  • 8/8/2019 Building Applications Using VC

    26/54

  • 8/8/2019 Building Applications Using VC

    27/54

    SDI Application Run time view

  • 8/8/2019 Building Applications Using VC

    28/54

    Understanding a Multiple Document Interface Application

    A multiple document interface application also has menus, andit enables the user to have more than one document open atonce. This section presents the code that is generated whenyou choose an MDI application with no database or compounddocument support, but instead with a toolbar, a status bar,Help, 3D controls, source file comments, and the MFC libraryas a shared DLL. As with the SDI application, these are thedefaults after Step 1. The focus here is on what differs fromthe SDI application in the previous section.Six classes havebeen created for you :

    CAboutDlg, a dialog class for the About dialog box

    CFirstMDIApp, a CWinApp class for the entire application

    CFirstMDIDoc, a document class

    CFirstMDIView, a view class

  • 8/8/2019 Building Applications Using VC

    29/54

    CMainFrame, a frame class

    CChildFrame, a child frame class

    MDI Application Design view

    MDI Application Run time view

  • 8/8/2019 Building Applications Using VC

    30/54

    Database Connectivity

    With Simple Dialog Box

    Create ODBC DSN from Control Panel for your Table

    First include Header file named : afxdb.h in project.

    Then create Member Variable with type of CDatabase (db)formain database (eg. *.mdb);

    After creating database, create Member Variable with type of

    CRecordset(rs)

    To Connect Database with DSN created by ODBC

    db.OpenEx("DSN= DSN name ;UID= User name ");

    Connect the Recordset (rs) with Database

  • 8/8/2019 Building Applications Using VC

    31/54

    rs.m_pDatabase=&db;

    To Connect the Particular Table

    rs.Open(CRecordset::snapshot,"select * from tablename ");

    ^ Recordset type

    To get the field value of the field

    rs .GetFieldValue( fieldname ",variable);

    To get First Record : rs .MoveFirst();

    To get Next Record : rs .MoveNext();

    To get Prev Record : rs .MovePrev();

    To get Last Record : rs .MoveLast();

    To Add the Record :

    CString query;

    query = insert into tablename +

    fieldValue +

    db.ExecuteSQL(query);

    rs.Requery();

    To delete the record

    CString query;

    query="delete from table name where

    field name = "+ field value +"'";

    db.ExecuteSQL(query);

    rs.Requery();

    To Edit the record :

  • 8/8/2019 Building Applications Using VC

    32/54

    CString query;

    query="update table name set field name ='"+ field value +";

    db.ExecuteSQL(query);

    rs.Requery();

    Other functions :

    IsEOF, IsBOF etc.

    Database Connectivity

    o With SDI Application

    While Creating Application :

    1. In Step 2 Select Database View without file support option

    2. Click on Data Source Button & Select ODBC

    1. Give particular DSN

    2. Then Select Particular Table from dialog box

    In Step 4 Deselect Printing & print preview option

    VC++ automatically creates the public variable with databaseutility named : m_pSet

    Take Edit Boxes as per your databases field

    Create Member Variables for each edit box.

    In the Member Variable Name Combo box There isthe list of Field variables per your

    database fields

    Select appropriate Field variable for each edit box

  • 8/8/2019 Building Applications Using VC

    33/54

    e.g. : m_pSet-> m_Fieldname for an edit box

    variable

    It will display the record value in appropriate edit box. (run

    time) You can move the record from toolbar or menu by selectingappropriate option

    To Add Record :

    m_pSet->AddNew();

    UpdateData(1);

    m_pSet->Update();

  • 8/8/2019 Building Applications Using VC

    34/54

    To Edit Record :

    m_pSet->Edit();

    UpdateData(1);

    m_pSet->Update();

    To Delete Record :

    m_pSet->Delete();

    UpdateData(1);

    Other functions :

    IsEOF, IsBOF etc.

    Database Connectivity

    With OLEDB

    In Step 2 Select Database view without file support

    Then Click on the DataSource Button

    Select OLEDB option & select ODBC provider & give DSN orbuild connection string

    Then click OK & select the required table.

    It will automatically create the variable named m_pSet

    Use all the commands( of ODBC connectivity ) to utilize thedatabase.

    With DAO

    [Window Title]

    Reserved Battery Level

  • 8/8/2019 Building Applications Using VC

    35/54

    [Main Instruction]

    Plug in or find another power source

    [Content]

    Your battery power is low (7%). If you don't plug in your computersoon, it will hibernate automatically.

    #include #include #include

    #include

    Create CFile object eg. :

    CFile f;

    Then use following syntax :

    f.Open(filename",CFile::modeCreate|CFile::modeWrite );

    To Write the Data into file use following :

    CString sz =It the CFile Text;

    f.Write(sz, strlen(sz));

    f.Close();

    CArchive

    Archive is associated with a file and permits the bufferedwriting and reading of data to and from storage

    You must create a CFile object before you can create aCArchive object.

    The archives load/store status is compatible with the filesopen mode. You are limited to one active archive per file.

  • 8/8/2019 Building Applications Using VC

    36/54

    When you construct a CArchive object, you attach it to anobject of class CFile (or a derived class) that represents anopen file.

    CArchive also supports programming with the MFC WindowsSockets classes CSocket and CSocketFile. The IsBufferEmptymember function supports that usage

    Example :

    CFile myFile(Note.txt", CFile::modeCreate |CFile::modeWrite);

    CArchive ar(&myFile, CArchive::store);

    ar.WriteString( This from Archive" );

    // Flush all of the data to the file :

    ar.Flush();

    ar.Close();

    Exception Handling

    CException CException is the base class for all exceptions.

    Some derived classes :

    CMemoryException Out-of-memory exception

    CNotSupportedException Request for an unsupportedoperation

    CArchiveException Archive-specific exception

    CFileException File-specific exception

    CDBException Database exception (based on ODBC)

    CDaoException Data access object exception (that is,exception conditions arising for DAO classes)

    CInternetException Internet exception (for Internet classes).

  • 8/8/2019 Building Applications Using VC

    37/54

    These exceptions are intended to be used with the

    TRY, CATCH, AND_CATCH, and END_CATCH macros

    Simple Example

    CFile tmpFile;

    CFileException ex;

    if (! tmpFile.Open("\\Tmp\\temp.txt", CFile::modeRead, &ex))

    {

    TCHAR tmp[255];

    CString str;

    ex.GetErrorMessage(tmp, 255);

    str = The data file could not be opened because : ";

    strr += tmp;

    MessageBox(str);

    }

    else

    tmpFile.Close();

    TRY

    Use this macro to set up a TRY block.

    A TRY block identifies a block of code that might throwexceptions.

    Those exceptions are handled in the following CATCH andAND_CATCH blocks.

    CATCH

    Use this macro to define a block of code that catches the firstexception type thrown in the preceding TRY block.

  • 8/8/2019 Building Applications Using VC

    38/54

    CATCH ( exception_class , exception_object_pointer_name )

    Where

    exception_class : Specifies the exception type to test for.

    exception_object_pointer_name : Specifies a name for anexception-object pointer that will be created by the macro.

    You can use the pointer name to access the exception objectwithin the CATCH block.

    Example :

    CFile* pFile = NULL;

    TRY

    {

    pFile = new CFile("\\Too\\temp.txt", CFile::modeRead);

    }

    CATCH (CFileException, Ex)

    {

    Ex->ReportError(MB_OK,0);

    }

    END_CATCH

    AND_CATCH

    AND_CATCH( exception_class, exception_object_pointer_name )

    Where :

    exception_classSpecifies the exception type to test for.

    exception_object_pointer_name

  • 8/8/2019 Building Applications Using VC

    39/54

    A name for an exception-object pointer that will be created bythe macro. You can use the pointer name to access theexception object within the AND_CATCH block.

    END_CATCH

    Marks the end of the last CATCH or AND_CATCH block.

    spawnl(var,exe file,arg1,path,NULL);

    This function is used to start new process or application

    _P_OVERLAY

    Overlays calling process with new process,destroying the callingprocess

    _P_WAIT

    Suspends calling thread until execution of new process iscomplete

    _P_NOWAIT

    Continues to execute calling process concurrently with newprocess

    _P_DETACH

    Continues to execute the calling process; new process is run inthe background with no access to the console or keyboard.

    For Example to start doc file in MS Word

    _spawnl(_P_NOWAIT,C:windows\\notepad.exe,*.doc,C:\\temp.txt,NULL)

  • 8/8/2019 Building Applications Using VC

    40/54

    CFileDialog

    #include

    The CFileDialog class encapsulates the Windows common file dialog box.Common file dialog boxes provide an easy way to implement File Open and

  • 8/8/2019 Building Applications Using VC

    41/54

    File Save As dialog boxes (as well as other file-selection dialog boxes) in amanner consistent with Windows standards.

    CFileDialog( BOOL bOpenFileDialog , LPCTSTR lpszDefExt = NULL,LPCTSTR lpszFileName = NULL, DWORD dwFlags =

    OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter =NULL, CWnd* pParentWnd = NULL );

    Where :

    bOpenFileDialog

    Set to TRUE to construct a File Open dialog box or FALSE to construct a FileSave As dialog box.

    lpszDefExt

    The default filename extension. If the user does not include an extension inthe Filename edit box, the extension specified by lpszDefExt is automaticallyappended to the filename. If this parameter is NULL , no file extension isappended.

    lpszFileName

    The initial filename that appears in the filename edit box. If NULL , nofilename initially appears.

    dwFlags

    A combination of one or more flags that allow you to customize the dialogbox.

    lpszFilter

    A series of string pairs that specify filters you can apply to the file. If youspecify file filters, only selected files will appear in the Files list box. See theRemarks section for more information on how to work with file filters.

    pParentWnd

    A pointer to the file dialog-box objects parent or owner window.

    Example :

    CFileDialog FDlg(1,"htm","hello.htm",1,"Html Files (*.htm)|*.htm|All Files |*.*||");

  • 8/8/2019 Building Applications Using VC

    42/54

    FDlg.DoModal();

    CFontDialog The CFontDialog class allows you to incorporate a font-selection dialog boxinto your application. A CFontDialog object is a dialog box with a list of fonts that are currently installed in the system. The user can select aparticular font from the list, and this selection is then reported back to theapplication.

  • 8/8/2019 Building Applications Using VC

    43/54

    Once a CFontDialog object has been constructed, you can use the m_cf structure to initialize the values or states of controls in the dialog box. Them_cf structure is of type CHOOSEFONT.

    CFontDialog( LPLOGFONT lplfInitial = NULL, DWORD dwFlags =

    CF_EFFECTS | CF_SCREENFONTS, CDC* pdcPrinter = NULL, CWnd* pParentWnd = NULL );

    Where :

    lplfInitial

    A pointer to a LOGFONT data structure that allows you to set some of thefonts characteristics.

    dwFlags

    Specifies one or more choose-font flags. One or more preset values can becombined using the bitwise OR operator.

    pdcPrinter

    A pointer to a printer-device context. If supplied, this parameter points to aprinter-device context for the printer on which the fonts are to be selected.

    Example :

    Show Font Dialog with default settings :CFontDialog dlg;

    dlg.DoModal();

    Sub Functions :

    DoModal Displays the dialog and allows the user to make a selection.

    GetCurrentFont Retrieves the name of the currently selected font.

    GetFaceName Returns the face name of the selected font.

    GetStyleName Returns the style name of the selected font.

    GetSize Returns the point size of the selected font.

    GetColor Returns the color of the selected font.

  • 8/8/2019 Building Applications Using VC

    44/54

    GetWeight Returns the weight of the selected font.

    IsStrikeOut Determines whether the font is displayed with strikeout.

    IsUnderline Determines whether the font is underlined.

    IsBold Determines whether the font is bold.

    IsItalic Determines whether the font is italic.

    CColorDialog

    The CColorDialog class allows you to incorporate a color-selection dialogbox into your application. A CColorDialog object is a dialog box with a list of colors that are defined for the display system. The user can select or createa particular color from the list, which is then reported back to the applicationwhen the dialog box exits.

  • 8/8/2019 Building Applications Using VC

    45/54

    Once the dialog box has been constructed, you can set or modify any valuesin the m_cc structure to initialize the values of the dialog boxs controls. Them_cc structure is of type CHOOSECOLOR.

    CColorDialog( COLORREF clrInit = 0, DWORD dwFlags = 0, CWnd*

    pParentWnd = NULL );

    Where :

    clrInit

    The default color selection. If no value is specified, the default is RGB(0,0,0)(black).

    dwFlags

    A set of flags that customize the function and appearance of the dialog box.pParentWnd

    A pointer to the dialog boxs parent or owner window.

    Example :

    CColorDialog Coldlg; Color dialog with all the default settings.

    Coldlg.DoModal();

    Sub Functions :

    DoModal Displays a color dialog box and allows the user to make aselection.

    GetColor Returns a COLORREF structure containing the values of theselected color.

    GetSavedCustomColors Retrieves custom colors created by the user.

    SetCurrentColor Forces the current color selection to the specified color.

  • 8/8/2019 Building Applications Using VC

    46/54

    CPageSetupDialog

    The CPageSetupDialog class encapsulates the services provided by theWindows common OLE Page Setup dialog box with additional support forsetting and modifying print margins. This class is designed to take the placeof the Print Setup dialog box.

    To use a CPageSetupDialog object, first create the object using theCPageSetupDialog constructor. Once the dialog box has been constructed,

    you can set or modify any values in the m_psd data member to initialize thevalues of the dialog box's controls. The m_psd structure is of typePAGESETUPDLG .

    Example :

    CPageSetupDialog Psdlg;

  • 8/8/2019 Building Applications Using VC

    47/54

    Psdlg.DoModal();

    Attributes & Sub Functions :

    m_psd A structure used to customize a CPageSetupDialog

    object.DoModal Displays the dialog box and allows the user make a selection.

    CreatePrinterDC Creates a device context for printing.

    GetDeviceName Returns the device name of the printer.

    GetDevMode Returns the current DEVMODE of the printer.

    GetDriverName Returns the driver used by the printer.

    GetMargins Returns the current margin settings of the printer.

    GetPortName Returns the output port name.

    GetPaperSize Returns the paper size of the printer.

  • 8/8/2019 Building Applications Using VC

    48/54

    CPrintDialog

    The CPrintDialog class encapsulates the services provided by the Windowscommon dialog box for printing. Common print dialog boxes provide an easyway to implement Print and Print Setup dialog boxes in a manner consistentwith Windows standards.

    To use a CPrintDialog object, first create the object using the CPrintDialogconstructor. Once the dialog box has been constructed, you can set ormodify any values in the m_pd structure to initialize the values of the dialogboxs controls. The m_pd structure is of type PRINTDLG.

  • 8/8/2019 Building Applications Using VC

    49/54

    Example :

    CPrintDialog PrtDlg(0); or PrtDlg(1);

    PrtDlg.DoModal();

    Sub Functions

    CreatePrinterDC Creates a printer device context without displaying thePrint dialog box

    DoModal Displays the dialog box and allows the user to make a selection.

    GetCopies Retrieves the number of copies requested.

    GetDefaults Retrieves device defaults without displaying a dialog box.

    GetDeviceName Retrieves the name of the currently selected printerdevice.

    GetDevMode Retrieves the DEVMODE structure.

    GetDriverName Retrieves the name of the currently selected printer driver.

    GetFromPage Retrieves the starting page of the print range.

    GetToPage Retrieves the ending page of the print range.

    GetPortName Retrieves the name of the currently selected printer port.

    GetPrinterDC Retrieves a handle to the printer device context.

    PrintAll Determines whether to print all pages of the document.

    PrintCollate Determines whether collated copies are requested.

    PrintRange Determines whether to print only a specified range of pages.

    PrintSelection Determines whether to print only the currently selecteditems.

  • 8/8/2019 Building Applications Using VC

    50/54

  • 8/8/2019 Building Applications Using VC

    51/54

    CFileFind The MFC class CFileFind performs local file searches and is the base classfor CGopherFileFind and CFtpFileFind , which perform Internet filesearches. CFileFind includes member functions that begin a search, locatea file, and return the title, name, or path of the file. For Internet searches,the member function GetFileURL returns the files URL.

    Example :

    CFileFind findexe;

    BOOL stat = findexe.FindFile("*.exe");

    while (stat)

    {

    stat = findexe.FindNextFile();

  • 8/8/2019 Building Applications Using VC

    52/54

    MessageBox(findexe.GetFileName());

    }

    _chmod, _wchmod ( include , )

    Change the file-permission settings.

    _chmod( const char *filename , int pmode );

    Where :

    filename Name of existing file

    pmode Permission setting for file

    _S_IWRITE Writing permitted

    _S_IREAD Reading permitted

    _S_IREAD | _S_IWRITE Reading and writing permitted

    _access, _waccess ( include , )

    Determine file-access permission.

    int _access( const char * path , int mode );

    Where :

    path File or directory path

    mode Permission setting

    mode ValueChecks File For

    00 Existence only

    02 Write permission

    04 Read permission

    06 Read and write permission

    To Get or Set the Current Directory

  • 8/8/2019 Building Applications Using VC

    53/54

    TCHAR cur[MAX_PATH]; used to get system buffer path

    MAX_PATH is system variable to access maximum path

    SetCurrentDirectory ("C:\\windows");

    GetCurrentDirectory (MAX_PATH,cur);

    MessageBox(cur);

    To get the SIZE of the file

    CFile::GetStatus

    CFileStatus st;

    CFile::GetStatus("f:\\drk.zip",st);

    CString str;

    str.Format("%ld",st.m_size);

    MessageBox(str);

  • 8/8/2019 Building Applications Using VC

    54/54