home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #1
/
monster.zip
/
monster
/
PROG_C
/
COOLWORX.ZIP
/
DEMO
/
COOLEDIT
/
COOLEDIT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-11
|
10KB
|
276 lines
/*****************************************
* CoolEdit -- The CoolWorx Editor *
* *
* Copyright 1994 by Al Williams Comp. *
* You may use portions of CoolEdit in *
* your own code, but you may not *
* distribute CoolEdit by itself. *
* *
*****************************************/
#include <windows.h>
#include "cooledit.h"
#include "cw.h"
/* Forward reference */
long WINAPI _export win_proc(HWND hWnd, UINT message,
UINT wParam, LONG lParam);
int init(HANDLE,HANDLE,int);
#define WINDOWMENU 4
HANDLE hInst;
HWND mainw;
char ini[]="cooledit.ini";
/* Main entry point */
int PASCAL WinMain(HANDLE hInstance, HANDLE prev,
LPSTR cmdline, int show)
{
HANDLE acc=NULL; /* use MDI accel */
hInst=hInstance;
cw_BeginIcons(hInst,LoadIcon(hInst,MAKEINTRESOURCE(APPICON)),
LoadIcon(hInst,MAKEINTRESOURCE(EDITICON)));
if (!init(hInst,prev,show)) return FALSE;
/* Vanilla event loop */
cw_Run(mainw,cw_MDIGetClientWindow(mainw),1,&acc,TRUE,TRUE);
cw_End(hInst);
return FALSE;
}
/* Create window here */
int init(HANDLE hInstance, HANDLE prev,int nCmdShow)
{
HWND hWnd;
/* Create a main window */
mainw=hWnd=cw_MDICreateFrame("CoolEdit","MMENU",0,
hInstance,(FARPROC)win_proc,FALSE,2000,
MAKEINTRESOURCE(MENUBAR),NULL,
NULL,MAKEINTRESOURCE(STATUS_BAR),
LoadAccelerators(hInst,"MMENU"),
CWRIBBON_TOP,0);
if (!hWnd)
return FALSE;
/* Make the window visible, update its client area,
and return "success"
if we should show normal, use stored window position */
if (nCmdShow==SW_SHOWNORMAL)
cw_IniPosSet(ini,"Main",hWnd);
else
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
/* Create new (empty) child window */
void new_child(HWND hWnd)
{
static int untitled=0; // keep track of #
char title[66];
wsprintf(title,"Untitled - %d",++untitled);
cw_MDICreateChild("CWEDITCLASS",title,
CW_MDIWIN|CE_HSCROLL|CE_VSCROLL|CW_USEHELP|CW_USEPROG,
CW_USEDEFAULT,0,CW_USEDEFAULT,0,
"EMENU",hWnd,hInst,WINDOWMENU,
LoadAccelerators(hInst,"EMENU"),
MAKEINTRESOURCE(EMENUBAR),CWRIBBON_TOP,NULL);
}
/* Window procedure */
long WINAPI _export win_proc(HWND hWnd, UINT message,
UINT wParam, LONG lParam)
{
switch (message)
{
case WM_INITMENU:
/* Set up most recently opened menu
-- if child active, put at location 6 of menu 0 (file)
-- if no child windows, put at location 2 of menu 0 */
cw_IniOpenMenu(ini,
GetMenu(hWnd),0,
cw_MDIGetActive(hWnd)?6:2,4000);
/* Send WM_INITMENU to child window (if any) */
cw_MDISendActive(hWnd,WM_INITMENU,wParam,
lParam);
/* Update toolbar/statusbar visibility */
CheckMenuItem (GetMenu (hWnd), VIEW_TB,
MF_BYCOMMAND|
(cw_GetRibbon(hWnd,CWRIBBON_TOP)
? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem (GetMenu (hWnd),
VIEW_SB, MF_BYCOMMAND
| (cw_GetRibbon(hWnd,CWRIBBON_BOTTOM)
? MF_CHECKED : MF_UNCHECKED));
break;
#if 0 // enable to have an inital window
case CW_MDICREATE:
new_child(hWnd);
break;
#endif
/* Handle help window messages */
case CW_HELPID:
{
static HWND sb;
static int oldid;
/* If first time, find status bar and quit */
if (!sb)
{
sb=cw_GetRibbon(hWnd,CWRIBBON_BOTTOM);
/* Skip the first one so (c) message appears */
return 0;
}
/* Filter out redundant help messages */
if (oldid==wParam) return 0;
oldid=wParam;
/* Load help from resource file or defaults */
cw_StatusHelp(hInst,sb,STATUS_PANE,oldid);
break;
}
/* Update status bar/toolbar, etc */
case CW_IDLE:
{
static unsigned divide=0;
HWND w=cw_MDIGetActive(hWnd);
/* Only update time every 600 ticks */
if (divide++%600==0)
cw_StatusTime(hWnd,CWRIBBON_BOTTOM,
TIME_PANE);
/* Update status keys */
cw_StatusKeys(hWnd,CWRIBBON_BOTTOM,
CAP_STATIC,NUM_STATIC,NULL,NULL);
/* Give child a chance to init toolbar and show status */
if (w)
{
SendMessage(w,CW_INITTOOL,0,(DWORD)hWnd);
cw_EditStatus(hWnd,CWRIBBON_BOTTOM,w,
EDSTAT_PANE,FALSE);
}
else
{
/* No child so clear edit status pane */
SendMessage(
GetDlgItem(
cw_GetRibbon(hWnd,CWRIBBON_BOTTOM),
EDSTAT_PANE),WM_SETTEXT,0,(DWORD)"");
}
break;
}
/* Menu commands */
case WM_COMMAND:
/* Check for most recently used files */
if (wParam>=4000&&wParam<=4010)
{
char fn[66];
cw_IniOpenGet(ini,4000,
wParam,fn,sizeof(fn));
if (*fn)
{
if (cw_EditOpenFileName(hWnd,
CW_USEPROG|CW_USEHELP|CE_HSCROLL|CE_VSCROLL,
"EMENU",WINDOWMENU,
fn,FALSE,LoadAccelerators(hInst,
"EMENU"),MAKEINTRESOURCE(EMENUBAR),
CWRIBBON_TOP))
cw_IniOpenSet(ini,fn);
}
break;
}
/* Ask child if it can handle this message */
if (!cw_MDISendActive(
hWnd,CW_STDMENU,wParam,0))
/* If not, we must do it.... */
switch (wParam)
{
case VIEW_FONT:
{
/* change font */
HWND w=cw_MDIGetActive(hWnd);
if (w) cw_EditSetFont(w,NULL);
break;
}
case VIEW_TB:
{
/* Hide/show toolbar */
cw_MDIShowToolBar (hWnd, CWRIBBON_TOP,
!cw_GetRibbon(hWnd,CWRIBBON_TOP));
break;
}
case VIEW_SB:
{
/* Hide/show status bar */
static HWND sb;
if (!sb)
sb = cw_GetRibbon (hWnd, CWRIBBON_BOTTOM);
cw_MDIShowRibbon (sb,
!cw_GetRibbon(hWnd,CWRIBBON_BOTTOM));
break;
}
/* Create new child */
case CM_FILENEW:
new_child(hWnd);
break;
/* Open new child */
case CM_FILEOPEN:
{
char fn[66];
if (cw_EditOpenFile(hWnd,
CW_USEPROG|CW_USEHELP|CE_HSCROLL|CE_VSCROLL,
"EMENU",WINDOWMENU,
fn,sizeof(fn),
LoadAccelerators(hInst,
"EMENU"),
MAKEINTRESOURCE(EMENUBAR),
CWRIBBON_TOP))
/* Register file name with most recently opened */
cw_IniOpenSet(ini,fn);
}
break;
/* Toggle NUMLOCK */
case NUM_BUTTON:
cw_ToggleKeyState(VK_NUMLOCK);
break;
/* Toggle CAPS LOCK */
case CAP_BUTTON:
cw_ToggleKeyState(VK_CAPITAL);
break;
case CM_HELPABOUT:
/* Use CoolDialog for about box -- no callback is needed
and there isn't any data to transfer */
cw_DialogBox(hInst,"ABTBOX",
mainw,NULL,cw_NullCDlgTemp());
break;
}
break;
/* On exit, save window position */
case WM_DESTROY:
cw_IniPosSave(ini,"Main",hWnd);
PostQuitMessage(0);
break;
}
/* Use CoolWorx default -- not windows! */
return (cw_DefFrameProc(hWnd, message,
wParam, lParam));
}