Download - Lecture 10

Transcript
Page 1: Lecture 10

Lecture 10

Multiple Document Interface (MDI)

Page 2: Lecture 10

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

Page 3: Lecture 10

MDI - windows

Page 4: Lecture 10

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)

Page 5: Lecture 10

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

Page 6: Lecture 10

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

Page 7: Lecture 10

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

Page 8: Lecture 10

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

Page 9: Lecture 10

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);

Page 10: Lecture 10

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

{

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

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

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

}

Page 11: Lecture 10

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

Page 12: Lecture 10

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;