1 / 12

Dialog boxes

Dialog boxes. Modal and modeless dialog boxes Displaying about dialog box: case WM_COMMAND : switch (LOWORD (wParam)) { case IDM_APP_ABOUT : DialogBox (hInstance, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break ; } return 0 ;.

ziya
Download Presentation

Dialog boxes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dialog boxes • Modal and modeless dialog boxes • Displaying about dialog box: case WM_COMMAND : switch (LOWORD (wParam)) { case IDM_APP_ABOUT : DialogBox (hInstance, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break ; } return 0 ;

  2. BOOL CALLBACK About (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG : return TRUE ; case WM_COMMAND : switch (LOWORD (wParam)) { case IDOK : case IDCANCEL : EndDialog (hDlg, 0) ; return TRUE ; } break ; } return FALSE ; }

  3. Modal dialog box • Created using: • DialogBox, DialogBoxIndirect, DialogBoxParam, DialogBoxIndirectParam • Disables dialog window owner until the dialog is closed • Closed by the EndDialog function. • Result of the DialogBox function is the argument passed to the EndDialog function

  4. Dialog procedure • Similar to window procedure • Returns TRUE if it message was processed FALSE if not • Does not call DefWindowProc • Should not process WM_PAINT, WM_DESTROY messages • Does not receive WM_CREATE, instead it receives WM_INITDIALOG message

  5. WM_INITDIALOG • WM_CREATE is sent to the window right after it has been created • WM_INITDIALOG is sent to the dialog after all its controls have been created. • In WM_INITDIALOG application can access controls, e.g.: • enable or disable controls • fill controls with data (e.g. ListBoxes) • set initial values of Edit controls • set initial state of checkboxes and radio buttons

  6. Controls • Controls are regular windows (child windows) • They have window handle and process messages like any other window • To get window handle for the control use GetDlgItem function HWND GetDlgItem(HWND hDlg, int itemId); itemId is the child window number. For dialogs created from resource template this will be the control id from the resource file - Any function that operates on window handle can be used on a control, e.g.: • MoveWindow- move window on the screen • ShowWindow- show / hide window • EnableWindow - enable / disable window

  7. Using controls • To set/get text from EDIT control: • SetWindowText or SetDlgItemText • GetWindowText or GetDlgItemText • To set/get checkbox and radio button selection: • CheckDlgButton • IsDlgButtonChecked • To add elements to LISTBOX • Send LB_ADDSTRING message to add element to LISTBOX • Send LB_SETCURSEL message to select element in a LISTBOX

  8. Using controls • LISTBOX example: HWND hListWnd = GetDlgItem( hDlg, IDC_LIST ); SendMessage( hListWnd, LB_ADDSTRING, 0, (LPARAM)"item 1" ); SendMessage( hListWnd, LB_ADDSTRING, 0, (LPARAM)"item 2" ); SendMessage( hListWnd, LB_ADDSTRING, 0, (LPARAM)"item 3" ); SendMessage( hListWnd, LB_ADDSTRING, 0, (LPARAM)"item 4" ); SendMessage( hListWnd, LB_ADDSTRING, 0, (LPARAM)"item 5" ); SendMessage( hListWnd, LB_SETCURSEL, 2, 0 );

  9. Dialog boxes • Dialog box is a regular window, so any function that operates on windows works for dialog boxes (e.g. MoveWindow) • Area covered by controls is painted by controls. Dialog cannot paint over the area occupied by controls (usually dialog does not paint at all) • If mouse cursor is over the control, the control handles mouse messages • All keyboard messages are processed by the dialog and some of them are passed to controls • Modal dialog box has its own message loop

  10. Modeless dialog boxes • Modeless dialog boxes don’t disable parent window, so user can work in both windows • To create modeless dialog box use: HWND CreateDialog(HINSTANCE hInstance, LPCSTR template, HWND parent, DLGPROC lpDialogFunc ); • This function does not wait for the dialog box to close (it works like CreateWindow) • The window must be destroyed using DestroyWindow function (don’t call EndDialog!)

  11. Modeless dialog boxes • Modeless dialog box requires change to the application message queue: while (GetMessage (&msg, NULL, 0, 0)) { if (hDlgModeless == 0 ¦¦ !IsDialogMessage (hDlgModeless, &msg)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } }

  12. IsDialogMessage • IsDialogMessage – checks if message is intended for the dialog box and if so, processes the message • TAB key moves focus to the next group of controls • DOWN key moves focus to the next control in a group • ENTER key pushes the default pushbutton for the dialog • IsDialogMessage can be used for any type of window

More Related