Lecture 10

Post on 05-Jan-2016

16 views 0 download

description

Lecture 10. Multiple Document Interface (MDI). MDI - introduction. User can work with more than one document at one time Each document is displayed in child window Each child window is contained within client area of application’s main window. MDI - windows. MDI - windows. - PowerPoint PPT Presentation

Transcript of Lecture 10

Lecture 10

Multiple Document Interface (MDI)

MDI - introduction• User can work with more than one document at

one time

• Each document is displayed in child window

• Each child window is contained within client area of application’s main window

MDI - windows

MDI - windows• Frame window is main application window, it has

• sizing border

• title bar, window menu

• minimize and maximze buttons

• Frame window must be registered by application (by call to RegisterClass or RegisterClassEx)

MDI - windows• MDI client window

• uses predefined class MDICLIENT

• it serves as background for child windows

• it manages child windows, it can:

• create child window

• activate child window

• maximize and minimize child windows

• cascade and tile child windows

MDI - windows• MDI child window

• MDI child window has:

• sizing border

• title bar

• minimize, maximize buttons

• MDI child window class must be registered by application

MDI – window procedures• MDI application must register at least two

window classes and use two window procedures:

• for the frame window

• for the MDI child window

• Frame window procedure must call DefFrameProc instead of DefWindowProc

• MDI child window procedure must call DefMDIChildProc instead of DefWindowProc

MDI – step by step• Create frame window procedure

• Create MDI child window procedure

• Register frame window class

• Register MDI child window class

• Create main application window

• Create MDI client window

• Modify message loop and add call to TranslateMDISysAccel

Create MDI client windowcase WM_CREATE:

{

CLIENTCREATESTRUCT ccs;

ccs.hWindowMenu = GetSubMenu(GetMenu(hWnd), 1);

ccs.idFirstChild = 10000;

hMDIClient = CreateWindow( "MDICLIENT", "",

WS_CHILD | WS_CLIPCHILDREN |

WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,

0, 0, 0, 0,

hWnd, (HMENU)1, hInst, &ccs);

}

...

default:

return DefFrameProc(hWnd, hMDIClient,

message, wParam, lParam);

Modify message loopwhile (GetMessage(&msg, NULL, 0, 0))

{

if (!TranslateMDISysAccel(hMDIClient, &msg) &&

!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

}

MDI menu• MDI child window names are automatically

added to window menu.

• Selecting menu item corresponding to MDI child window activates the window

• Handle to menu where MDI child window names should be added is passed to MDICLIENT window

• If there are more than 10 MDI child windows – “more windows” menu item is displayed

Standard MDI commands• Standard MDI commands like Cascade, Tile are

handled by sending messages to MDI child window

case ID_WINDOW_TILE_HORZ:

SendMessage( hMDIClient, WM_MDITILE,

MDITILE_HORIZONTAL, 0 );

break;

case ID_WINDOW_CASCADE:

SendMessage( hMDIClient, WM_MDICASCADE, 0, 0 );

break;

case ID_WINDOW_ARRANGE:

SendMessage( hMDIClient, WM_MDIICONARRANGE, 0, 0 );

break;