Listing 3: The tmdi_frame_window member functions
tmdi_frame_window *the_frame_window = 0;
LRESULT CALLBACK _export FrameWndProc (HWND hwnd,
UINT message,WPARAM wParam,LPARAM lParam) {
return (long) (the_frame_window->
handle_message (hwnd, message, wParam, lParam));}
tmdi_frame_window::tmdi_frame_window (HINSTANCE
hInstance,LRESULT CALLBACK window_proc,
int window_extra,LPCSTR menu_name,
LPCSTR title_name,LPCSTR class_name,
LPCSTR icon_name,tmdi_type_list_struct
*child_types,int init_show_about):
twindow (hInstance,window_proc,window_extra,
menu_name,title_name,class_name,icon_name){
mdi_children_types = child_types;
show_about = init_show_about; };
int tmdi_frame_window::respond_wm_create (HWND hwnd){
int width,height;
HINSTANCE hInst = wndclass.hInstance;
clientcreate.hWindowMenu = frame_submenu ;
clientcreate.idFirstChild = IDM_FIRSTCHILD ;
width = GetSystemMetrics (SM_CXSCREEN);
height = GetSystemMetrics (SM_CYSCREEN);
hwndClient = CreateWindow ("MDICLIENT", NULL,
WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
0, 0, width, height, hwnd, (HMENU)1, hInst,
(LPSTR) &clientcreate) ;
hwindow = hwnd;
if (show_about) respond_wm_about();
return 1 ; }
void tmdi_frame_window::set_global_ptr () {
the_frame_window = this; }
void tmdi_frame_window::set_mdicreate
(LPCSTR the_class,LPCSTR the_title) {
mdicreate.szClass = the_class;
mdicreate.szTitle = the_title;
mdicreate.hOwner = wndclass.hInstance;
mdicreate.x = CW_USEDEFAULT ;
mdicreate.y = CW_USEDEFAULT ;
mdicreate.cx = CW_USEDEFAULT ;
mdicreate.cy = CW_USEDEFAULT ;
mdicreate.style = 0 ;
mdicreate.lParam = NULL ;
hwndChild = (HWND) SendMessage (hwndClient,
WM_MDICREATE, 0,
(LPARAM) (LPMDICREATESTRUCT) &mdicreate) ; }
int tmdi_frame_window::respond_wm_command
(WPARAM wParam, LPARAM lParam) {
tmdi_type_list_struct *child_type =
mdi_children_types;
HINSTANCE hInst = wndclass.hInstance;
while (child_type) {
if (wParam == child_type->type_id) {
set_mdicreate (child_type->the_class,
child_type->the_title);
return 1; } // end if
child_type = child_type->next;
} // end while
switch (wParam) {
case IDM_ABOUT:
respond_wm_about();
return 1;
case IDM_CLOSE: // Get the active window & close it
hwndChild =(HWND) (LOWORD (SendMessage
(hwndClient,WM_MDIGETACTIVE, 0, 0L)));
if (SendMessage(hwndChild,WM_QUERYENDSESSION,
0,0L)) SendMessage (hwndClient,
WM_MDIDESTROY,(WPARAM)hwndChild,0L);
return 1 ;
case IDM_EXIT:
SendMessage (hwindow,WM_CLOSE,0,0L);
return 1 ;
case IDM_TILE:
SendMessage (hwndClient,WM_MDITILE,0,0L);
return 1 ;
case IDM_CASCADE:
SendMessage (hwndClient,WM_MDICASCADE,0,0L);
return 1 ;
case IDM_ARRANGE:
SendMessage (hwndClient,WM_MDIICONARRANGE,0,0L);
return 1 ;
case IDM_CLOSEALL: // Attempt to close all children
EnumChildWindows (hwndClient,
(WNDENUMPROC)close_all_proc, 0L) ;
return 1 ;
default: // Pass to active child
hwndChild = (HWND)((SendMessage (hwndClient,
WM_MDIGETACTIVE, 0, 0L))) ;
if (IsWindow (hwndChild))
SendMessage (hwndChild, WM_COMMAND,wParam,
lParam) ;
return 0 ; } // and then to DefFrameProc
}
int tmdi_frame_window::respond_wm_about () {
about_dialog (hwndClient);
return 1; }
int tmdi_frame_window::respond_wm_queryendsession(){
return respond_wm_close (); }
int tmdi_frame_window::respond_wm_close () {
SendMessage(hwindow,WM_COMMAND,IDM_CLOSEALL,0L);
if (GetWindow (hwndClient, GW_CHILD))
return 1 ;
return 0; } // ie, call default_window_proc
int tmdi_frame_window::respond_wm_destroy (HWND) {
PostQuitMessage (0) ;
return 1; }
LRESULT CALLBACK tmdi_frame_window::default_window_proc
(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
return (LRESULT CALLBACK)DefFrameProc (hwnd, hwndClient,
message, wParam,lParam) ; }
void tmdi_frame_window::init_menu (HINSTANCE hinst,
LPCSTR menu_rc_name,WPARAM window_submenu_pos) {
frame_menu = LoadMenu (hinst,menu_rc_name);
frame_submenu = GetSubMenu (frame_menu,
window_submenu_pos); }
//End of File