home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windoware
/
WINDOWARE_1_6.iso
/
winutil
/
adg_7_8
/
sheet.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-21
|
9KB
|
257 lines
/****************************************************************************
Module name: Sheet.C
Programmer : Jeffrey M. Richter & Elvira Peretsman.
*****************************************************************************/
#include "..\nowindws.h"
#undef NOCOLOR
#undef NOGDI
#undef NOKERNEL
#undef NOLSTRING
#undef NOMB
#undef NOMDI
#undef NOMENUS
#undef NOUSER
#undef NOWINMESSAGES
#undef NOWINOFFSETS
#include <windows.h>
#include "mdi.h"
static char _szClassName[] = "Sheet";
typedef struct {
HMENU hMenu;
HANDLE hAccelTable;
} CLSEB;
LONG FAR PASCAL SheetProc (HWND hWnd, WORD wMsg, WORD wParam, LONG lParam) {
BOOL fCallDefProc = FALSE;
DWORD dwResult = 0;
WORD wTemp = 0;
HMENU hMenu;
char szBuf[100], szString[100], szCaption[25];
switch (wMsg) {
case WM_CREATE:
// If this window is first instance created of this class.
if (GETCLSEB(hWnd, CLSEB, hMenu) == NULL) {
// Initialize the menu and accelerator handles for this class.
wTemp = LoadMenu(_hInstance, _szClassName);
SETCLSEB(hWnd, CLSEB, hMenu, (HMENU) wTemp);
wTemp = LoadAccelerators(_hInstance, _szClassName);
SETCLSEB(hWnd, CLSEB, hAccelTable, (HANDLE) wTemp);
}
break;
case WM_MDIACTIVATE:
if (wParam == FALSE) break;
// Child is being activated.
// Set the menu bar and the accelerators to the appropriate ones
// for this window class.
ChangeMDIMenu(GETFRAME(hWnd), GetParent(hWnd),
(HMENU) GETCLSEB(hWnd, CLSEB, hMenu), IDM_WINDOWTILEVERT);
_hAccelTable = (HANDLE) GETCLSEB(hWnd, CLSEB, hAccelTable);
// For the Status bar at the bottom of the Frame window to be
// updated for this child's information.
InvalidateRect(GETFRAME(hWnd), NULL, TRUE);
break;
case WM_CLOSE:
// Make sure that it is OK to close this child window.
fCallDefProc = (BOOL) SendMessage(hWnd, WM_QUERYENDSESSION, TRUE, 0);
if (fCallDefProc) SendMessage(hWnd, WM_ENDSESSION, TRUE, 0);
break;
case WM_QUERYENDSESSION:
// Prompt user whether to save changes to this document.
// Usually, a dirty flag (stored in the window's extra bytes
// is used to determine if it is necessary to ask this question).
// Construct string including the document's name.
lstrcpy(szBuf, "Save changes to ");
wTemp = lstrlen(szBuf);
GetWindowText(hWnd, szBuf + wTemp, sizeof(szBuf) - wTemp);
lstrcat(szBuf, "?");
// Display message box to user. The message box should
// be system modal if the entire Windows session is being
// terminated. (wParam is FALSE).
wTemp = MessageBox(hWnd, szBuf, _szAppName,
MB_ICONQUESTION | MB_YESNOCANCEL |
(wParam ? MB_APPLMODAL : MB_SYSTEMMODAL));
switch (wTemp) {
case IDYES:
// Save the document and it's OK to quit.
dwResult = TRUE;
break;
case IDNO:
// Don't save the document and it's OK to quit.
dwResult = TRUE;
break;
case IDCANCEL:
// Don't save the document and it's NOT OK to quit.
dwResult = FALSE;
break;
}
break;
case WM_ENDSESSION:
// Do any last minute cleanup during this message.
break;
case WM_DESTROY:
// Notify the Frame window that a child has been destroyed after
// the child is actually destroyed. (That's why we use
// PostMessage instead of SendMessage here).
PostMessage(GETFRAME(hWnd), FW_MDICHILDDESTROY, hWnd, 0);
fCallDefProc = TRUE;
break;
case AC_PAINTSTATBAR:
// Message sent by the Frame window when the status bar needs to
// be repainted.
// wParam = HDC, lParam = LPPAINTSTRUCT to status area in frame.
// Construct status bar string for display.
LoadString(_hInstance, IDS_SHEETSTATUSBAR, szBuf, sizeof(szBuf));
// Draw the horizontal dividing line separating the Status bar
// from the MDICLIENT window.
((LPPAINTSTRUCT) lParam)->rcPaint.top += (int)
SendMessage(GETFRAME(hWnd), FW_DRAWSTATUSDIVIDE, 0,
(LONG) (LPPAINTSTRUCT) lParam);
// Paint the text in the status bar.
TextOut((HDC) wParam, 0, ((LPPAINTSTRUCT) lParam)->rcPaint.top,
szBuf, lstrlen(szBuf));
break;
case WM_MENUSELECT:
// Normally, only MDI Child system menu options could appear
// in this message. But the Frame window forces WM_MENUSELECT
// messages to appear here whenever a menu selection occurs.
if (lParam == MAKELONG(-1, 0)) {
// User has stopped using the menu system. Notify Frame window
// so that the status bar will be invalidated.
SendMessage(GETFRAME(hWnd), FW_SETMENUHELP, 0, 0);
break;
}
switch (LOWORD(lParam) & (MF_POPUP | MF_SYSMENU)) {
case 0:
// wParam is a menu item ID NOT on the Child's system menu.
// If wParam is any of the MDI Children listed in the
// "Window" menu, display the same help text.
if ((wParam > IDM_WINDOWCHILD) && (wParam <= IDM_WINDOWCHILD + 9))
wParam = IDM_WINDOWCHILD;
// Tell the Frame that this window should display the help
// text and the identifier for the help text.
wTemp = IDS_SHEETMENUID + wParam;
break;
case MF_POPUP:
// wParam is handle to popup menu.
// Calculate the index of the top-level menu.
hMenu = GetMenu(GETFRAME(hWnd));
wTemp = GetMenuItemCount(hMenu);
while (wTemp--)
if (GetSubMenu(hMenu, wTemp) == (HMENU) wParam) break;
wTemp += IDS_SHEETPOPUPID;
if (!IsZoomed(hWnd)) wTemp++;
break;
case MF_SYSMENU:
// wParam is menu item ID from MDI Child's system menu.
wTemp = IDS_SHEETMENUID + ((wParam & 0x0FFF) >> 4);
break;
case MF_POPUP | MF_SYSMENU:
// wParam is handle to MDI Child's sys menu.
wTemp = IDS_SHEETPOPUPID;
break;
}
// Tell the Frame that this window should display the help
// text and the identifier for the help text.
SendMessage(GETFRAME(hWnd), FW_SETMENUHELP, hWnd, wTemp);
break;
case WM_ENTERIDLE:
// User stopped moving around in the help system, make the Frame
// believe that it received this message directly.
SendMessage(GETFRAME(hWnd), wMsg, wParam, lParam);
break;
case AW_PAINTMENUHELP:
// Message sent from Frame window to notify child that it should
// paint the status bar text for the last highlighted menu item.
// lParam = LPPAINTSTRUCT of Frame's status bar.
// Ask the Frame window what the last selected menu ID was.
// This value was sent to the frame by this window during the
// processing for the WM_MENUSELECT message.
dwResult = SendMessage(GETFRAME(hWnd), FW_GETMENUHELP, 0, 0);
// Draw the horizontal dividing line separating the Status bar
// from the MDICLIENT window.
((LPPAINTSTRUCT) lParam)->rcPaint.top += (int)
SendMessage(GETFRAME(hWnd), FW_DRAWSTATUSDIVIDE, 0,
(LONG) (LPPAINTSTRUCT) lParam);
// Construct the string that is to be displayed.
LoadString(_hInstance, LOWORD(dwResult), szString, sizeof(szString));
GetWindowText(hWnd, szCaption, sizeof(szCaption));
wsprintf(szBuf, szString, (LPSTR) szCaption);
// Paint the menu help text in the status bar.
TextOut(((LPPAINTSTRUCT) lParam)->hdc,
0, ((LPPAINTSTRUCT) lParam)->rcPaint.top, szBuf, lstrlen(szBuf));
break;
case WM_COMMAND:
// Any menu options NOT processed by the Frame are passed to the
// active child.
MessageBox(hWnd, "Option not implemented.", _szAppName, MB_OK);
break;
default: fCallDefProc = TRUE; break;
}
if (fCallDefProc)
dwResult = DefMDIChildProc(hWnd, wMsg, wParam, lParam);
return(dwResult);
}
BOOL FAR PASCAL RegisterSheetWndClass (void) {
WNDCLASS wc;
wc.style = 0;
wc.lpfnWndProc = SheetProc;
// Number of class extra bytes used by structure.
wc.cbClsExtra = sizeof(CLSEB);
wc.cbWndExtra = 0;
wc.hInstance = _hInstance;
wc.hIcon = LoadIcon(_hInstance, _szClassName);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = COLOR_WINDOW + 1;
wc.lpszMenuName = NULL;
wc.lpszClassName = _szClassName;
return(RegisterClass(&wc));
}