0% found this document useful (0 votes)
134 views14 pages

Dialog Box Essentials for IT Students

Dialog boxes are temporary windows created by applications to retrieve user input from the user. There are two types of dialog boxes: modal dialog boxes, which prevent the user from interacting with other parts of the application until the dialog is closed, and modeless dialog boxes, which allow interaction with other parts of the application while open. Dialog boxes contain controls like edit boxes, buttons, list boxes, etc. to accept input. The MFC provides classes for common controls like CButton, CEdit, CListBox, and CTreeCtrl to facilitate creating dialog boxes and handling user input.

Uploaded by

michael.ferraris
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views14 pages

Dialog Box Essentials for IT Students

Dialog boxes are temporary windows created by applications to retrieve user input from the user. There are two types of dialog boxes: modal dialog boxes, which prevent the user from interacting with other parts of the application until the dialog is closed, and modeless dialog boxes, which allow interaction with other parts of the application while open. Dialog boxes contain controls like edit boxes, buttons, list boxes, etc. to accept input. The MFC provides classes for common controls like CButton, CEdit, CListBox, and CTreeCtrl to facilitate creating dialog boxes and handling user input.

Uploaded by

michael.ferraris
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

DIAOLOG BOXES AND

CONTROLS

[Link]
Lecturer in IT Department
Dialog box
• It is a temporary window created by an
application to retrieve user input.
• A dialog box contains one or more child
window controls with which the user can
enter text, choose options or direct the
action of the command
• The advantage of using dialog box is that
it can be constructed easily using a dialog
box editor program.
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 the
same 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 remains
on 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
edit controls, buttons, list boxes, combo boxes, static text, tree views, progress
indicators, sliders, and so forth.
CREATING A DIALOG BOX
 Design a dialog box using the dialog box editor. All the
programs resources are saved in a single rc file.
 Each child window control within the dialog box is given
an ID number.
 Each dialog box requires a message passing function to
be added to the program.
 The program activates the dialog box by calling the
Dialogbox function, passing the dialog box name and the
dialog box function address or parameters.
 The dialog box stays on the screen until the EndDialog
function is called from within the dialog box function. This
closes the dialog box and returns control to the window
that called the dialog box.
Creation and Initializing Dialog
Box
 Use either one of these constructors to construct a resource-
based modal dialog box. One form of the constructor provides
access to the dialog resource by template name. The other
constructor provides access by template ID number, usually
with an IDD_ prefix (for example, IDD_DIALOG1).
[Link]( LPCTSTR lpszTemplateName, CWnd*
pParentWnd = NULL );
2. CDialog( UINT nIDTemplate, CWnd* pParentWnd =
NULL );
3. CDialog( );
Initialisation
1. virtual BOOL OnInitDialog( );
2. virtual int DoModal( ) Call this member function to invoke the modal
dialog box and return the dialog-box result when the done.
CONTROLS IN DIALOG BOX

CONTROL MFC Class


Push button,check CButton
box,radio button
Edit Control CEditBox
ListBox CListBox
ComboBox CComboBox
TreeControl CTreeCtrl
ScrollBar CScrollBar
Static text,outline of a CStatic
rectangle
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 control’s title or text.
nMaxCount Specifies the maximum length (in bytes) of the
string to be copied to lpStr. If the string is longer than
nMaxCount, 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 string
that contains the text to be copied to the control.
CONTROL CLASSES-CButton Class

1. CButton Class
BOOL OnInitDialog()
{
CButton *OK,*CANCEL;
OK=(CButton *)GetDlgItem(IDOK);
CANCEL=(CButton *)GetDlgItem(CANCEL);
OK->EnableWindow(FALSE);
Return TRUE;
}
2. CEditBox Class
 The CEdit class provides the functionality of a Windows edit
control. An edit control is a rectangular child window in which
the user can enter text.

Message-map entries and a description of the cases in which they


would be sent to the parent:
• ON_EN_KILLFOCUS   The edit control loses the input/keyboard
focus.
• ON_EN_SETFOCUS   Sent when an edit control receives the input
focus.
• ON_EN_UPDATE   The edit control is about to display altered text.
Sent after the control has formatted the text but before it screens the
text so that the window size can be altered, if necessary.
3. CListBox Class
 The CListBox class provides the functionality of a Windows
list 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 and
the 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 set the text given in the edit box
 SetFocus-focus the cursor to the particular control.
 int AddString(LPSTR)-calls the member function to add
astring to a list box.
[Link]
 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 the
control.

 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 given scroll
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 following
values:
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;
}
5. Tree Control
 This control is a window that display the hierarchical
List of items such as the heading in and document
and the entries in an index or the files and directories
on the text. Each item consists of a label and an
optional bitmap. Each item can have associated sub
item bit, by clicking the item, the user can expand the
associated list of items.
 To manipulate with the tree control, MFC has
provided a class called CTreeCtrl.
CTreeCtrl Control
FUNCTIONS

 HTREEITEM InsertItem( LPCTSTR lpszItem, HTREEITEM


hParent = TVI_ROOT, HTREEITEM hInsertAfter =
TVI_LAST );
lpszItem Address of a string containing the item’s text.
hParent ->Handle of the inserted item’s parent.
hInsertAfter -> Handle of the item after which the new item
is to be inserted.
 BOOL DeleteItem(HTREEITEM)—the provided handle to
remove.
 BOOL DeleteAllItem()—all items in the tree control will be
removed.
THANK YOU

You might also like