home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Loisirs 18
/
cd.iso
/
PLANETE
/
MUDWIN
/
SOURCE.ZIP
/
FRAME.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-03
|
18KB
|
687 lines
//
// MODULE Frame.c
//
// PURPOSE Window procedures for the top-most window
//
// EXPORTS FrameWndProc
//
#include "defcon.h"
#include "global.h"
#pragma hdrstop
#include <string.h>
/* Private constants. */
#define DESIRED_WINSOCK_VERSION 0x0101 // we'd like version 1.1.
/* note when we were last compiled */
TS(Frame)
/* local procs */
VOID NEAR SetToolBar(BOOL);
VOID NEAR SetStatusLine(BOOL);
VOID NEAR SetCommandLine(BOOL);
// FUNCTION AskAllChildren
//
// PURPOSE Send a message to all MDI children
//
// PARAMETERS None
//
// RETURNS TRUE if all children agree to the query,
// FALSE if any one of them disagrees
BOOL FAR
AskAllChildren(UINT nMessage, WPARAM wParam)
{
register HWND hwndT;
for (hwndT = GetWindow(hClient, GW_CHILD); hwndT;
hwndT = GetWindow(hwndT, GW_HWNDNEXT)) {
/* Skip if an icon title window */
if (GetWindow(hwndT, GW_OWNER))
continue;
if (!SendMessage(hwndT, nMessage, wParam, 0L))
return FALSE;
}
return TRUE;
}
// FUNCTION Frame_MDIMessageForwarder
//
// PURPOSE Forwards message to DefFrameProc
//
// PARAMETERS hwnd - Window handle
// nMessage - The message
// wParam - The first message parameter
// lParam - The second message parameter
//
// RETURNS LRESULT - Depends on the actual message
LRESULT
Frame_MDIMessageForwarder(HWND hwnd, UINT nMessage,
WPARAM wParam, LPARAM lParam)
{
return DefFrameProc(hwnd, hClient, nMessage, wParam, lParam);
}
//-------------------------------------------------------------------
#pragma argsused
void NEAR
Frame_OnClose(HWND hwnd)
{
/* don't close if any children cancel the operation */
if (AskAllChildren(WM_QUERYENDSESSION, 0))
DestroyWindow(hwnd);
}
//-------------------------------------------------------------------
#pragma argsused
VOID NEAR
Frame_OnCommand(HWND hwnd,
INT id,
HWND hwndCtl,
UINT codeNotify)
{
switch (id) {
case IDM_FILE_NEW:
AddFile(NULL);
break;
case IDM_FILE_OPEN:
// Prompt the user for an existing file
{
char szFile[MAX_PATH];
if (ShowFileBox(hMainWnd, FALSE,
szFile, sizeof szFile))
AddFile(szFile);
}
break;
case IDM_FILE_SAVEALL:
AskAllChildren(WM_COMMAND, IDM_FILE_SAVE);
break;
case IDM_FILE_SETUP:
ShowSetupBox(hwnd);
break;
case IDM_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case IDM_OPTION_TOOLS:
SetToolBar(!(wFlags & SHOW_TOOLS));
break;
case IDM_OPTION_STAT:
SetStatusLine(!(wFlags & SHOW_STATUS));
break;
case IDM_OPTION_ABOVE:
SetCommandLine(!(wFlags & SHOW_ABOVE));
break;
case IDM_WINDOW_CASCADE:
(void) FORWARD_WM_MDICASCADE(hClient, 0, SendMessage);
break;
case IDM_WINDOW_TILE_VERTICALLY:
(void) FORWARD_WM_MDITILE(hClient, MDITILE_VERTICAL, SendMessage);
break;
case IDM_WINDOW_TILE_HORIZONTALLY:
(void) FORWARD_WM_MDITILE(hClient, MDITILE_HORIZONTAL, SendMessage);
break;
case IDM_WINDOW_ARRANGE_ICONS:
FORWARD_WM_MDIICONARRANGE(hClient, SendMessage);
break;
case IDM_WINDOW_CLOSE_ALL:
AskAllChildren(WM_QUERYENDSESSION, 0);
break;
case IDM_HELP_ABOUT:
AboutDialog(hwnd);
break;
case IDM_HELP_CONTENTS:
ShellExecute(hwnd, NULL, "mudwin.wri", NULL, ".",
SW_SHOWMAXIMIZED);
break;
case IDM_FILE_PAGE:
MsgBox(MB_OK, IDS_NEXTTIME);
break;
case IDM_FILE_SAVE:
case IDM_FILE_SAVEAS:
case IDM_FILE_PRINT:
case IDM_EDIT_UNDO:
case IDM_EDIT_CUT:
case IDM_EDIT_COPY:
case IDM_EDIT_PASTE:
case IDM_EDIT_SEND:
case IDM_EDIT_SELECT:
case IDM_EDIT_CLEAR:
case IDM_SEARCH_FIND:
case IDM_SEARCH_NEXT:
case IDM_SEARCH_PREV:
case IDM_SEARCH_REPLACE:
case IDM_SEARCH_ALTER:
case IDM_OPTION_LECHO:
case IDM_OPTION_MECHO:
case IDM_OPTION_WRAP:
case IDM_OPTION_FONT:
case IDM_OPTION_COLOR:
if (hActive)
FORWARD_WM_COMMAND(hActive, id, hwndCtl, codeNotify,
SendMessage);
else
MsgBox(MB_ICONSTOP | MB_OK, IDS_DEBUGNOTE,
(LPSTR) "No active window!");
break;
default:
FORWARD_WM_COMMAND(hwnd, id, hwndCtl, codeNotify,
Frame_MDIMessageForwarder);
break;
}
}
//-------------------------------------------------------------------
#pragma argsused
BOOL NEAR
Frame_OnCreate(HWND hwnd,
CREATESTRUCT FAR * pCreateStruct)
{
CLIENTCREATESTRUCT ccs;
WSADATA wsadata;
SOCKERR serr;
HDC hdc;
TEXTMETRIC tm;
wFlags = GetPrivateInt(NULL,
"Session", "Options", SHOW_INITIAL);
#ifndef SKIP_TCPIP
// Initialize the sockets library
serr = WSAStartup(DESIRED_WINSOCK_VERSION, &wsadata);
if (serr != 0) {
MsgBox(MB_ICONSTOP | MB_OK, IDS_SOCKINIT,
serr, SockerrToString(serr));
return FALSE;
}
if (wsadata.wVersion != DESIRED_WINSOCK_VERSION) {
MsgBox(MB_ICONSTOP | MB_OK, IDS_SOCKVER,
LOBYTE(wsadata.wVersion),
HIBYTE(wsadata.wVersion),
LOBYTE(DESIRED_WINSOCK_VERSION),
HIBYTE(DESIRED_WINSOCK_VERSION));
return FALSE;
}
// Save the WinSock description for the "About..." box
lpszWinSockDesc = (LPSTR) GlobalAllocPtr(GPTR,
strlen(wsadata.szDescription) + 1);
_fstrcpy(lpszWinSockDesc, wsadata.szDescription);
#else
lpszWinSockDesc = "Dummy WinSock Description";
#endif
// Get textmetric data
hdc = GetDC(hwnd);
GetTextMetrics(hdc, &tm);
ReleaseDC(hwnd, hdc);
#ifndef SKIP_PRINT
if ((hdc = GetPrinterDC()) != 0)
DeleteDC(hdc);
#endif
// Create the MDI client window
ccs.hWindowMenu = GetSubMenu(GetMenu(hwnd), WINDOWMENU);
ccs.idFirstChild = IDM_WINDOW_FIRST_CHILD;
hClient = CreateWindow("mdiclient", NULL,
WS_CHILD | WS_CLIPCHILDREN |
WS_VSCROLL | WS_HSCROLL,
0, 0, pCreateStruct->cx, pCreateStruct->cy,
hwnd, 0, hInst, (LPSTR) & ccs);
if (hClient == NULL)
return FALSE;
hbrHilite = CreateSolidBrush(GetSysColor(COLOR_BTNHIGHLIGHT));
hbrNormal = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
hbrShadow = CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
tmWidth = tm.tmAveCharWidth;;
tmHeight = tm.tmHeight + tm.tmExternalLeading;
tmHt5 = tmHeight + 5;
tmHt6 = tmHeight + 6;
tmHt7 = tmHeight + 7;
tmHt8 = tmHeight + 8;
// Success!
ShowWindow(hClient, SW_SHOW);
return TRUE;
}
//-------------------------------------------------------------------
#pragma argsused
VOID NEAR
Frame_OnDestroy(HWND hwnd)
{
#ifndef SKIP_TCPIP
// Disconnect from the sockets library before terminating
WSACleanup();
#endif
if (hbrHilite)
DeleteObject(hbrHilite);
if (hbrNormal)
DeleteObject(hbrNormal);
if (hbrShadow)
DeleteObject(hbrShadow);
PostQuitMessage(0);
}
//-------------------------------------------------------------------
#pragma argsused
void NEAR
Frame_OnDevModeChange(HWND hwnd, LPCSTR lpszDeviceName)
{
HDC hdc;
#ifndef SKIP_PRINT
if ((hdc = GetPrinterDC()) != 0)
DeleteDC(hdc);
#endif
}
//-------------------------------------------------------------------
#pragma argsused
void NEAR
Frame_OnDropFiles(HWND hwnd, HDROP hdrop)
{
char szFile[MAX_PATH];
WORD i, n = DragQueryFile(hdrop, 0xFFFF, NULL, 0);
for (i = 0; i < n; i++) {
DragQueryFile(hdrop, i, szFile, sizeof szFile);
AddFile(szFile);
}
DragFinish(hdrop);
}
//-------------------------------------------------------------------
// FUNCTION : Frame_OnEraseBkgnd(hwnd, hdc)
#pragma argsused
BOOL NEAR
Frame_OnEraseBkgnd(HWND hwnd, HDC hdc)
{
return TRUE;
}
//-------------------------------------------------------------------
// FUNCTION : Frame_OnGetMinMaxInfo(hwnd, lpMinMaxInfo)
#pragma argsused
void NEAR
Frame_OnGetMinMaxInfo(HWND hwnd, MINMAXINFO FAR* lpMinMaxInfo)
{
#define OPT(F,V) ((wFlags & (F)) ? (V) : 0)
lpMinMaxInfo->ptMinTrackSize.x = 60 * tmWidth;
lpMinMaxInfo->ptMinTrackSize.y = 8 * tmHeight +
OPT(SHOW_TOOLS,48) + OPT(SHOW_STATUS,tmHt8);
#undef OPT
}
//-----------------------------------