home *** CD-ROM | disk | FTP | other *** search
- /*==============================================================================
- CTRL.C :- Demo of TER as a custom control
- Sub Systems, Inc.
- Software License Agreement (1989)
- ----------------------------------
- This is a demo program. The program shows how you can utilize TERW.OBJ
- routine to perform text editing functions. The program will prompt you
- for the control variables to be passed to TERW.OBJ routine.
- ===============================================================================*/
-
- #define STRICT
-
- #include "windows.h"
- #include "stdio.h"
- #include "stdlib.h"
- #include "fcntl.h"
- #include "sys\types.h"
- #include "sys\stat.h"
- #include "io.h"
- #include "string.h"
-
- /******************************************************************************
- WIN32 specific defines
- *******************************************************************************/
- #if defined (_WIN32)
- #if !defined(WIN32)
- #define WIN32
- #endif
- #endif
- #if defined (WIN32)
- #undef huge
- #define huge
- #undef FreeProcInstance
- #define FreeProcInstance(x)
- #define GET_WM_COMMAND_ID(wp,lp) LOWORD(wp)
- #define CONTROL_ID(wp,lp) LOWORD(wp)
- #define NOTIFY_MSG(wp,lp) HIWORD(wp)
- #define farmalloc malloc
- #define farrealloc realloc
- #define farfree free
- #else
- #define GET_WM_COMMAND_ID(wp,lp) (wp)
- #define CONTROL_ID(wp,lp) (wp)
- #define NOTIFY_MSG(wp,lp) HIWORD(lp)
- #endif
-
- #include "ter.h"
-
- #include "ctrl.h"
-
- #include "ter_cmd.h" // include TER accelerator keys
-
- /****************************************************************************
- Main Windows Routine
- ****************************************************************************/
- int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
- {
- MSG msg;
- int i;
-
- hPrevInst=hPrevInstance;
- if (!hPrevInstance)
- if (!InitApplication(hInstance))
- return (FALSE);
-
- if (!InitInstance(hInstance, nCmdShow))
- return (FALSE);
-
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (msg.wParam);
- }
-
- /****************************************************************************
- Initialize window data and register window class
- ****************************************************************************/
-
- BOOL InitApplication(HINSTANCE hInstance)
- {
- WNDCLASS wc;
-
- wc.style = 0;
- wc.lpfnWndProc = (void far *)DemoWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = GetStockObject(WHITE_BRUSH);
- wc.lpszMenuName = "DemoMenu";
- wc.lpszClassName = "DemoCClass";
-
- return (RegisterClass(&wc));
- }
-
-
- /****************************************************************************
- Save instance handle and create main window
- ****************************************************************************/
-
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- HWND hwnd;
- int i;
- char DocFile[13];
- HFILE hFile;
- FILE *InStream;
- char huge *pBuf;
-
- hInst = hInstance;
-
- LoadTerControl(); // ensures the TER dll is actually loaded
-
- hwnd = CreateWindow(
- "DemoCClass",
- "TER Demonstration",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- NULL,
- NULL,
- hInstance,
- NULL
- );
-
- if (!hwnd)
- return (FALSE);
-
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
-
- // Read the DEMO.TER file in a buffer
- #if defined(WIN32)
- strcpy(DocFile,"DEMO.SSE");
- #else
- strcpy(DocFile,"DEMO.TER");
- #endif
- if (access(DocFile,6)==-1) return TRUE; // file not found
-
- // get the file length
- if (NULL==(InStream=fopen(DocFile,"rb"))) return TRUE; // open the file
- BufferLen=filelength(fileno(InStream));
- fclose(InStream);
-
- // read the file
- if (HFILE_ERROR==(hFile=_lopen(DocFile,OF_READ))) return TRUE;
-
- if ( NULL==(hBuf=GlobalAlloc(GMEM_MOVEABLE,BufferLen+1))
- || NULL==(pBuf=(char huge *)GlobalLock(hBuf)) ) return TRUE;
-
- if ((BufferLen=_hread(hFile,pBuf,BufferLen))==-1) return TRUE;
-
- GlobalUnlock(hBuf); // unlock the buffer
-
- _lclose(hFile); // close the demo document file
-
- return (TRUE);
- }
-
- /****************************************************************************
- Process Main Window messages
- ****************************************************************************/
- long CALLBACK _export DemoWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- DLGPROC lpProcParam;
- BOOL result;
- int i;
- int CommandId;
-
- switch (message) {
- case WM_COMMAND:
- // extract the command id from wParam
- CommandId=GET_WM_COMMAND_ID(wParam,lParam);
-
- switch (CommandId) {
- case IDM_EDIT: // show the edit dialog box
- lpProcParam = (DLGPROC) MakeProcInstance((FARPROC) DemoEditDlg, hInst);
- DialogBox(hInst,"DemoEditDlg",hWnd,lpProcParam);
- FreeProcInstance((FARPROC) lpProcParam);
-
- break;
-
- default:
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- break;
-
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
-
- default:
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- return (LRESULT)NULL;
- }
-
- /****************************************************************************
- DEMO DIALOG PROCEDURES
- ****************************************************************************/
-
- /****************************************************************************
- Process messages for "DemoEditDlg" dialog box
- This dialog box includes the TER edit control.
- ****************************************************************************/
- int CALLBACK _export DemoEditDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- HWND hWnd;
-
- switch (message) {
- case WM_INITDIALOG:
-
- // Set initial values of the parameters
- if (hBuf) SetTerBuffer(GetDlgItem(hDlg,IDC_EDIT),hBuf,BufferLen,"",FALSE);
-
- SetFocus(GetDlgItem(hDlg,IDC_EDIT));
-
- return (TRUE);
-
- case WM_COMMAND:
- hWnd=GetDlgItem(hDlg,IDC_EDIT); // TER window handle
- switch (CONTROL_ID(wParam,lParam)) {
- case IDOK:
- // Free the old buffer and retrieve the updated buffer
- if (hBuf) GlobalFree(hBuf);
- hBuf=GetTerBuffer(hWnd,&BufferLen);
-
- EndDialog(hDlg, TRUE);
- return (TRUE);
-
- case IDCANCEL:
- EndDialog(hDlg, FALSE);
- return (TRUE);
-
- // Send command message to the TER window
- case IDC_CUT:
- SendMessage(hWnd,WM_COMMAND,ID_CUT,0L);break;
- case IDC_COPY:
- SendMessage(hWnd,WM_COMMAND,ID_COPY,0L);break;
- case IDC_PASTE:
- SendMessage(hWnd,WM_COMMAND,ID_PASTE,0L);break;
- case IDC_SEARCH:
- SendMessage(hWnd,WM_COMMAND,ID_SEARCH,0L);break;
- case IDC_REPLACE:
- SendMessage(hWnd,WM_COMMAND,ID_REPLACE,0L);break;
- case IDC_UNDO:
- SendMessage(hWnd,WM_COMMAND,ID_UNDO,0L);break;
- case IDC_PRINT:
- SendMessage(hWnd,WM_COMMAND,ID_PRINT,0L);break;
- case IDC_PAGE_OPTIONS:
- SendMessage(hWnd,WM_COMMAND,ID_PAGE_OPTIONS,0L);break;
- case IDC_PRINT_OPTIONS:
- SendMessage(hWnd,WM_COMMAND,ID_PRINT_OPTIONS,0L);break;
- case IDC_CHAR_NORMAL:
- SendMessage(hWnd,WM_COMMAND,ID_CHAR_NORMAL,0L);break;
- case IDC_BOLD_ON:
- SendMessage(hWnd,WM_COMMAND,ID_BOLD_ON,0L);break;
- case IDC_ULINE_ON:
- SendMessage(hWnd,WM_COMMAND,ID_ULINE_ON,0L);break;
- case IDC_ITALIC_ON:
- SendMessage(hWnd,WM_COMMAND,ID_ITALIC_ON,0L);break;
- case IDC_STRIKE_ON:
- SendMessage(hWnd,WM_COMMAND,ID_STRIKE_ON,0L);break;
- case IDC_SUPSCR_ON:
- SendMessage(hWnd,WM_COMMAND,ID_SUPSCR_ON,0L);break;
- case IDC_SUBSCR_ON:
- SendMessage(hWnd,WM_COMMAND,ID_SUBSCR_ON,0L);break;
- case IDC_COLOR:
- SendMessage(hWnd,WM_COMMAND,ID_COLOR,0L);break;
- case IDC_FONTS:
- SendMessage(hWnd,WM_COMMAND,ID_FONTS,0L);break;
- case IDC_PARA_NORMAL:
- SendMessage(hWnd,WM_COMMAND,ID_PARA_NORMAL,0L);break;
- case IDC_CENTER:
- SendMessage(hWnd,WM_COMMAND,ID_CENTER,0L);break;
- case IDC_RIGHT_JUSTIFY:
- SendMessage(hWnd,WM_COMMAND,ID_RIGHT_JUSTIFY,0L);break;
- case IDC_LEFT_INDENT:
- SendMessage(hWnd,WM_COMMAND,ID_LEFT_INDENT,0L);break;
- case IDC_RIGHT_INDENT:
- SendMessage(hWnd,WM_COMMAND,ID_RIGHT_INDENT,0L);break;
- case IDC_HANGING_INDENT:
- SendMessage(hWnd,WM_COMMAND,ID_HANGING_INDENT,0L);break;
- case IDC_DOUBLE_SPACE:
- SendMessage(hWnd,WM_COMMAND,ID_DOUBLE_SPACE,0L);break;
-
- default:
- ;
- }
- break;
- }
- return (FALSE);
- }
-
-