home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Loisirs 18
/
cd.iso
/
PLANETE
/
MUDWIN
/
SOURCE.ZIP
/
INIT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-03
|
10KB
|
350 lines
//
// MODULE Init.c
//
// PURPOSE Contains initialization code
//
// EXPORTS Housekeeping()
//
#include "defcon.h"
#include "global.h"
#pragma hdrstop
#include <commdlg.h>
#include <memory.h>
#include <ctype.h>
#include <string.h>
/* note when we were last compiled */
TS(Init)
// FUNCTION GoodbyeWorld
//
// PURPOSE Tells user why we are dying
//
// PARAMETERS wFmt --String table entry to use as format
// lpszItem -- Item for which initialization failed
//
// RETURNS FALSE to slightly simplify coding
BOOL NEAR
GoodbyeWorld(WORD wFmt, LPSTR lpszItem)
{
MsgBox(MB_ICONEXCLAMATION | MB_OK, wFmt, lpszItem);
return FALSE;
}
// FUNCTION InitializeApplication
//
// PURPOSE Performs application-wide initialization
//
// PARAMETERS None
//
// RETURNS TRUE if everything initialized OK,
// FALSE if something tragic happened
BOOL NEAR
InitializeApplication()
{
WNDCLASS wc;
// Initialize & register the various window classes
// Register the frame class
memset(&wc, 0, sizeof wc);
wc.lpfnWndProc = (WNDPROC) FrameWndProc;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(hInst, IDI_FRAME);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszMenuName = IDM_FRAME;
wc.lpszClassName = szFrame;
if (!RegisterClass(&wc))
return GoodbyeWorld(IDS_REGISTER, szFrame);
// Register the player class (a MDI child)
memset(&wc, 0, sizeof wc);
wc.lpfnWndProc = (WNDPROC) PlayerWndProc;
wc.hIcon = LoadIcon(hInst, IDI_CLIENT);
wc.cbWndExtra = sizeof(LPVOID);
wc.lpszClassName = szPlayer;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hInstance = hInst;
if (!RegisterClass(&wc))
return GoodbyeWorld(IDS_REGISTER, szPlayer);
#ifndef SKIP_TOOLBAR
/* register the tool bar class */
memset(&wc, 0, sizeof wc);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hInstance = hInst;
wc.lpfnWndProc = (WNDPROC) ToolsWndProc;
wc.lpszClassName = szTools;
wc.style = CS_OWNDC | CS_HREDRAW;
if (!RegisterClass(&wc))
return GoodbyeWorld(IDS_REGISTER, szTools);
#endif
#ifndef SKIP_STATUS
/* register the status line class */
memset(&wc, 0, sizeof wc);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hInstance = hInst;
wc.lpfnWndProc = (WNDPROC) StatusWndProc;
wc.lpszClassName = szStat;
wc.style = CS_OWNDC | CS_HREDRAW;
if (!RegisterClass(&wc))
return GoodbyeWorld(IDS_REGISTER, szStat);
#endif
#ifndef SKIP_YESNO
/* register the Yes/No class */
memset(&wc, 0, sizeof wc);
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hInstance = hInst;
wc.lpfnWndProc = (WNDPROC) YesNoWndProc;
wc.lpszClassName = szYesNo;
wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
if (!RegisterClass(&wc))
return GoodbyeWorld(IDS_REGISTER, szYesNo);
#endif
#ifndef SKIP_CMDLINE
/* Register private combobox control */
if (!GetClassInfo(NULL, "ComboBox", &wc))
return FALSE;
gComboProc = (WNDPROC) wc.lpfnWndProc;
wc.style &= ~CS_GLOBALCLASS;
wc.lpfnWndProc = (WNDPROC) ComboWndProc;
wc.hInstance = hInst;
wc.lpszClassName = szCombo;
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
if (!RegisterClass(&wc))
return GoodbyeWorld(IDS_REGISTER, szCombo);
#endif
/* Register private edit control */
if (!GetClassInfo(NULL, "Edit", &wc))
return FALSE;
gEditProc = (WNDPROC) wc.lpfnWndProc;
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.style &= ~CS_GLOBALCLASS;
wc.lpfnWndProc = (WNDPROC) EditWndProc;
wc.hInstance = hInst;
wc.lpszClassName = szEdit;
if (!RegisterClass(&wc))
return GoodbyeWorld(IDS_REGISTER, szEdit);
// Success!
return TRUE;
}
// FUNCTION ExistingApplication
//
// PURPOSE Pass command line to and pop open previous instance
//
// PARAMETERS lpCmdLine - Command line from user
// nCmdShow - How the window should be opened
//
// RETURNS TRUE if everything initialized OK,
// FALSE if something tragic happened
BOOL NEAR
ExistingApplication(LPSTR lpCmdLine, int nCmdShow)
{
HWND h;
HGLOBAL hDrop;
typedef struct tagDRAGHEADER {
UINT wStructSize;
UINT x, y;
BOOL fInPlayer;
} DRAGHEADER;
DRAGHEADER FAR *lpdh;
int n;
if (!(h = FindWindow(szFrame, NULL)))
return FALSE;
BringWindowToTop(h);
ShowWindow(h, nCmdShow);
if (lpCmdLine && *lpCmdLine) {
/* rather than messing with DDE, send a fake drop message */
n = sizeof(DRAGHEADER) + _fstrlen(lpCmdLine) + 2;
hDrop = GlobalAlloc(GMEM_DDESHARE | GMEM_ZEROINIT, n);
lpdh = (DRAGHEADER FAR *) GlobalLock(hDrop);
lpdh->wStructSize = sizeof(DRAGHEADER);
_fstrcpy((LPSTR) lpdh + sizeof(DRAGHEADER), lpCmdLine);
GlobalUnlock(hDrop);
SendMessage(h, WM_DROPFILES, hDrop, 0L);
GlobalFree(hDrop);
}
return TRUE;
}
// FUNCTION InitializeInstance
//
// PURPOSE Performs per-instance initialization
//
// PARAMETERS lpCmdLine - Command line from user
// nCmdShow - How the window should be opened
BOOL NEAR
InitializeInstance(LPSTR lpCmdLine, int nCmdShow)
{
char sz[80], *pCmdLine;
int i;
/* Register the FindReplace message. */
uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
/* Get the base window title */
LoadString(hInst, IDS_APPNAME, sz, sizeof(sz));
/* Create the frame (and MDI client window) */
hMainWnd = CreateWindowEx(WS_EX_DROPFILES, szFrame, sz,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL,
hInst, NULL);
if ((!hMainWnd) || (!hClient))
return GoodbyeWorld(IDS_CREATEWIN, szFrame);
#ifndef SKIP_YESNO
// Create the yes/no window
hYesNo = CreateWindow(szYesNo, NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER,
0, 0, 0, 0,
hMainWnd, // the parent
0, // ID for WM_COMMAND msgs
hInst, // This instance owns this window
NULL); // Pointer not needed
if (!hYesNo)
return GoodbyeWorld(IDS_CREATEWIN, szYesNo);
#endif
#ifndef SKIP_CMDLINE
// Create the command window
hCmdLine = CreateWindow(szCombo, NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER |
CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_VSCROLL,
0, 0, 0, 0,
hMainWnd, // the parent
-1, // ID for WM_COMMAND msgs
hInst, // This instance owns this window
NULL); // Pointer not needed
if (!hCmdLine)
return GoodbyeWorld(IDS_CREATEWIN, szCombo);
#endif
#ifndef SKIP_STATUS
// Create the status window
hStatBar = CreateWindow(szStat, NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER,
0, 0, 0, 0,
hMainWnd, // the parent
0, // ID for WM_COMMAND msgs
hInst, // This instance owns this window
NULL); // Pointer not needed
if (!hStatBar) {
(void) GoodbyeWorld(IDS_CREATEWIN, szStat);
wFlags &= ~SHOW_STATUS;
}
#endif
#ifndef SKIP_TOOLBAR
// Create the toolbar window
hToolBar = CreateWindow(szTools, NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER,
0, 0, 0, 0,
hMainWnd, // the parent
0, // ID for WM_COMMAND msgs
hInst, // This instance owns this window
NULL); // Pointer not needed
if (!hToolBar) {
(void) GoodbyeWorld(IDS_CREATEWIN, szTools);
wFlags &= ~SHOW_TOOLS;
}
#endif
// Load main menu accelerators */
if (!(hAccel = LoadAccelerators(hInst, IDA_FRAME)))
return FALSE;
// Display the frame window. The frame will receive a WM_SIZE
// message, whereupon it properly sizes all of its children
ShowWindow(hMainWnd, nCmdShow);
UpdateWindow(hMainWnd);
// ShowWindow(hToolBar, nCmdShow);
// UpdateWindow(hToolBar);
if (lpCmdLine && *lpCmdLine) {
AddFile(lpCmdLine);
}
for (i = 0; i < 16; i++) {
char szKey[8];
wsprintf(szKey, "Color%d", i);
aclrCustom[i] = GetPrivateRGB(NULL,
"Defaults", szKey, RGB(i,i,i));
}
return TRUE;
}
// FUNCTION Housekeeping
//
// PURPOSE Does all the grunt work to get everything running
//
// PARAMETERS lpCmdLine - Command line from user
// nCmdShow - How the window should be opened
//
// RETURNS TRUE if everything initialized OK,
// FALSE if