DIALOG BOXES AND CONTROLS - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

DIALOG BOXES AND CONTROLS

Description:

A dialog box is a temporary window that Windows creates for special-purpose ... A modeless dialog box allows the user to supply information and return to the ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 13
Provided by: gae5
Category:
Tags: and | boxes | controls | dialog | box

less

Transcript and Presenter's Notes

Title: DIALOG BOXES AND CONTROLS


1
DIALOG BOXES AND CONTROLS
2
Dialog Boxes
  • A dialog box is a temporary window that Windows
    creates for special-purpose input and then
    destroys immediately after use. An application
    typically uses a dialog box to prompt the user
    for additional information about a current
    command selection.

3
Types of Dialog Boxes
  • A modeless dialog box allows the user to supply
    information and return to the previous task
    without canceling or removing the dialog box.
  • A modal dialog box requires the user to respond
    to a request or supply information before the
    application can continue. We will create a MODAL
    dialog box.

4
What Are They For?
  • A Dialog Box is simply a window that holds
    controls provided to allow the user to
    communicate with the program.
  • CONTROLS are actually what communicates with the
    program - Not the Dialog Box.

5
Controls
  • Text Box (where user can type text)
  • Drop Down List Box
  • Combo Box (both text and drop down list)
  • Check Boxes
  • Radio Buttons (grouped-only one selected at a
    time)
  • Scroll Bars
  • Buttons - OK, CANCEL, Buttons on Button Bar
  • Menu Items
  • Any item intended to receive info from the user
    to be sent back to the program.

6
Creating a Dialog Box
  • Select the Resource Workshop and/or open the .rc
    file associated with your project.
  • Select Resource, New, then select Dialog.
  • Select the type of Dialog Box you want to create.
  • A Dialog Box will appear. You will use
    drag-n-drop to assign controls to it.

7
Adding Controls to a Dialog Box
  • Use the Tools bar to select and drop controls
    such as Check Boxes or Buttons onto the Dialog
    Box.
  • Double Click each control to make changes to its
    style, name and id.
  • Right Click the background of the Dialog Box and
    select Style to change the title that appears on
    the Dialog Box or Test to test the Dialog Box.
  • Resource, Edit as text to change the name used
    by the program to access the dialog box.
  • Save the Resource Project after making any
    changes or additions to your resources.

8
Processing Dialog Box Messages
  • Dialog Box controls receive messages from the
    mouse or keyboard and send them to your program.
    You must process these messages in your code.
  • The first step is to write a new function to
    process dialog box messages. It will have a
    switch statement that handles the IDs of the
    controls on your dialog box very similar to
    MainWndProc.

9
Write a Simple Dialog Procedure
  • BOOL CALLBACK Pizza ( HWND hDlg, UINT message,
    WPARAM wParam, LPARAM lParam )
  • switch ( message )
  • case WM_INITDIALOG / message initialize
    dialog box /
  • return ( TRUE )
  • case WM_COMMAND / message received
    a command /
  • switch (wParam)
  • case IDOK
  • MessageBox( hWnd, "You clicked OK",
    "Response", MB_OK)
  • break
  • case IDCANCEL
  • EndDialog ( hDlg, TRUE ) /
    Exits the dialog box /
  • return ( TRUE )
  • return ( FALSE ) / Didn't process a
    message /

10
In MainWndProc
  • Use MakeProcInstance to get a handle to (or
    memory for) your dialog box procedure.
  • Use the DialogBox function to load the dialog box
    resource and show the box on the screen (the
    DialogBox function creates a MODAL dialog box).
  • Use FreeProcInstance to clean up after the
    program is finished with the dialog box.

11
Add a Call toYour Dialog Procedure
  • LRESULT CALLBACK MainWndProc ( HWND hWnd, UINT
    message,WPARAM wParam,


  • LPARAM
    lParam)
  • DLGPROC dlgPizza
  • switch ( message )
  • case WM_COMMAND
  • switch (wParam)
  • case CM_EXIT
  • DestroyWindow ( hWnd )
  • case CM_ORDER
  • dlgPizza (DLGPROC)
    MakeProcInstance ( (FARPROC)Pizza, hInst )
  • DialogBox ( hInst, "PIZZA_DIALOG",
    hWnd, dlgPizza )
  • FreeProcInstance ( (FARPROC)
    dlgPizza )
  • default
  • return ( DefWindowProc ( hWnd, message,
    wParam, lParam ) )
  • default
  • return ( DefWindowProc ( hWnd,
    message, wParam, lParam ) )

12
Dialog Boxes are Stubborn
  • Processing messages received by your Dialog Box
    is your job as the programmer. The Dialog Box
    wont do anything you dont tell it to do.
Write a Comment
User Comments (0)
About PowerShow.com