dialog box

Upload: rajesh1158

Post on 30-May-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Dialog Box

    1/14

    DIAOLOG BOXES AND

    CONTROLS

    M.SUSHMERA

    Lecturer in IT Department

  • 8/9/2019 Dialog Box

    2/14

    Dialog box

    It is a temporary window created by anapplication to retrieve user input.

    A dialog box contains one or more childwindow controls with which the user canenter text, choose options or direct theaction of the command

    The advantage of using dialog box is thatit can be constructed easily using a dialogbox editor program.

  • 8/9/2019 Dialog Box

    3/14

    TYPES OF DIALOG BOXES

    The two kinds of dialogs are modal and modeless.

    The CDialog base class supports both modal and modeless dialogs

    Modal Dialog Box:

    The user cannot work elsewhere in the same application (more correctly, in thesame user interface thread) until the dialog is closed. Example: Open File dialog

    Modeless Dialog

    The user can work in another window in the application while the dialog remainson the screen

    Example: Microsoft Word's Find and Replace dialog is a good example of a

    modeless dialog; you can edit your document while the dialog is open.

    Controls.

    A dialog contains a number of elements called controls. Dialog controls include editcontrols, buttons, list boxes, combo boxes, static text, tree views, progressindicators, sliders, and so forth.

  • 8/9/2019 Dialog Box

    4/14

    CREATING A DIALOG BOX

    Design a dialog box using the dialog box editor. All theprograms resources are saved in a single rc file.

    Each child window control within the dialog box is givenan ID number.

    Each dialog box requires a message passing function tobe added to the program.

    The program activates the dialog box by calling theDialogbox function, passing the dialog box name and thedialog box function address or parameters.

    The dialog box stays on the screen until the EndDialogfunction is called from within the dialog box function. Thiscloses the dialog box and returns control to the windowthat called the dialog box.

  • 8/9/2019 Dialog Box

    5/14

    Creation and Initializing Dialog

    Box Use either one of these constructors to construct a resource-

    based modal dialog box. One form of the constructor providesaccess to the dialog resource by template name. The otherconstructor provides access by template ID number, usuallywith an IDD_ prefix (for example, IDD_DIALOG1).

    1.CDialog( LPCTSTR lpszTemplateName, CWnd*pParentWnd = NULL );

    2. CDialog( UINT nIDTemplate, CWnd* pParentWnd =NULL );

    3. CDialog( );

    Initialisation1. virtual BOOL OnInitDialog( );

    2. virtual int DoModal( ) Call this member function to invoke the modaldialog box and return the dialog-box result when the done.

  • 8/9/2019 Dialog Box

    6/14

    CONTROL MFC Class

    Push button,check

    box,radio button

    CButton

    Edit Control CEditBox

    ListBox CListBox

    ComboBox CComboBox

    TreeControl CTreeCtrl

    ScrollBar CScrollBar

    Static text,outline of a

    rectangle

    CStatic

    CONTROLS IN DIALOG BOX

  • 8/9/2019 Dialog Box

    7/14

    Retrieving data from the dialog object

    1. GetDlgItem( int nID, HWND* phWnd ) ;nID Specifies the identifier of the control or child

    window to be retrieved.

    phWnd A pointer to a child window.

    2. int GetDlgItemText( int nID, LPTSTR lpStr, int

    nMaxCount ) ;nID Specifies the integer identifier of the control

    whose title is to be retrieved.

    lpStr Points to the buffer to receive the controls title or text.

    nMaxCount Specifies the maximum length (in bytes) of the

    string to be copied to lpStr. If the string is longer thannMaxCount, it is truncated.

    3. void SetDlgItemText( int nID, LPCTSTR lpszString );

    nID Identifies the control whose text is to be set.

    lpszString Points to a CString object or null-terminated stringthat contains the text to be copied to the control.

  • 8/9/2019 Dialog Box

    8/14

    CONTROL CLASSES-CButton Class

    1. CButton ClassBOOL OnInitDialog()

    {

    CButton *OK,*CANCEL;

    OK=(CButton *)GetDlgItem(IDOK);

    CANCEL=(CButton *)GetDlgItem(CANCEL);

    OK->EnableWindow(FALSE);

    Return TRUE;

    }

  • 8/9/2019 Dialog Box

    9/14

    2. CEditBox Class

    The CEdit class provides the functionality of a Windows editcontrol. An edit control is a rectangular child window in whichthe user can enter text.

    Message-map entries and a description of the cases in which theywould be sent to the parent:

    ON_EN_KILLFOCUS The edit control loses the input/keyboardfocus.

    ON_EN_SETFOCUS Sent when an edit control receives the inputfocus.

    ON_EN_UPDATE The edit control is about to display altered text.Sent after the control has formatted the text but before it screens thetext so that the window size can be altered, if necessary.

  • 8/9/2019 Dialog Box

    10/14

    3. CListBox Class

    The CListBox class provides the functionality of a Windowslist box. A list box displays a list of items, such as filenames,that the user can view and select.

    In a single-selection list box, the user can select only one item.In a multiple-selection list box, a range of items can be

    selected. When the user selects an item, it is highlighted andthe list box sends a notification message to the parent window.

    FUNCTIONS

    GetText(LPSTR) ---to get the text given in the edit box

    SetText(LPSTR)-- to get the text given in the edit box

    SetFocus-focus the cursor to the particular control.

    int AddString(LPSTR)-calls the member function to addastring to a list box.

  • 8/9/2019 Dialog Box

    11/14

    4.ScrollBar Scroll bar is a rectangle that contains a scroll box and has direction arrows at both ends. Scroll

    bar sends a notification message to its parents whenever the user clicks the mouse in thecontrol.

    void GetScrollRange( LPINT lpMinPos, LPINT lpMaxPos ) const;

    lpMinPos Points to the integer variable that is to receive the minimum position.

    lpMaxPos Points to the integer variable that is to receive the maximum position.

    void SetScrollRange( int nMinPos, int nMaxPos, BOOL bRedraw = TRUE );

    Call this member function to set minimum and maximum position values for the givenscroll bar. Set nMinPos and nMaxPos to 0 to hide standard scroll bars.

    int GetScrollPos( int nBar ) const;

    Specifies the current position of the scroll box in the scroll bar if successful; otherwise 0.

    nBar Specifies the scroll bar to examine. The parameter can take one of the followingvalues:

    SB_HORZ Retrieves the position of the horizontal scroll bar.

    SB_VERT Retrieves the position of the vertical scroll bar.

    BOOL OnInitDialog()

    { CScrollBar *sb;

    sb=(CScrollBar *)GetDlgItem(IDC_SCROLLBAR1);

    sb->SetScrollRange(1,100,TRUE);

    sb->SetScrollPos(1,TRUE);

    Return TRUE;

    }

  • 8/9/2019 Dialog Box

    12/14

    5. Tree Control

    This control is a window that display the hierarchicalList of items such as the heading in and document

    and the entries in an index or the files and directorieson the text. Each item consists of a label and anoptional bitmap. Each item can have associated subitem bit, by clicking the item, the user can expand theassociated list of items.

    To manipulate with the tree control, MFC hasprovided a class called CTreeCtrl.

  • 8/9/2019 Dialog Box

    13/14

    CTreeCtrl Control

    FUNCTIONS

    HTREEITEM InsertItem( LPCTSTR lpszItem, HTREEITEMhParent = TVI_ROOT, HTREEITEM hInsertAfter =

    TVI_LAST );lpszItem Address of a string containing the items text.

    hParent ->Handle of the inserted items parent.

    hInsertAfter -> Handle of the item after which the new itemis to be inserted.

    BOOL DeleteItem(HTREEITEM)the provided handle toremove.

    BOOL DeleteAllItem()all items in the tree control will beremoved.

  • 8/9/2019 Dialog Box

    14/14

    THANK YOU