home *** CD-ROM | disk | FTP | other *** search
- /*==============================================================================
- DEMO-TER.C :- TER Demo Program (Window3 Version of TER.C).
- 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"
- #if defined (_WIN32)
- #if !defined(WIN32)
- #define WIN32
- #endif
- #endif
- #if !defined(WIN32)
- #include "print.h"
- #if defined (__TURBOC__)
- typedef unsigned short USHORT; // missing in compiler
- #endif
- #endif
-
- #include "stdio.h"
- #include "stdlib.h"
- #include "fcntl.h"
- #include "sys\types.h"
- #include "sys\stat.h"
- #include "io.h"
- #include "string.h"
-
- #include "commdlg.h"
-
- /******************************************************************************
- WIN32 specific defines
- *******************************************************************************/
- #if defined (WIN32)
- #undef huge
- #define huge
- #undef FreeProcInstance
- #define FreeProcInstance(x)
- #define GET_WM_COMMAND_ID(wp,lp) LOWORD(wp)
- #define farmalloc malloc
- #define farrealloc realloc
- #define farfree free
- #else
- #define GET_WM_COMMAND_ID(wp,lp) (wp)
- #endif
-
- #include "ter.h"
-
- #include "demo.h"
-
- char DemoCfmtSign[30]="~`!@#$%^&*()-+|=-TeCfMt"; // string that signifies the beginning of formatting information
-
- /****************************************************************************
- Main Windows Routine
- ****************************************************************************/
- int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
- {
- MSG msg;
- int i;
-
- #ifndef WIN32
- int QueueLength=96;
- while (!SetMessageQueue(QueueLength) && (QueueLength-=8));
- #endif
-
- SetMessageQueue(96); // needed for OLE2
-
- 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 = "DemoWClass";
-
- return (RegisterClass(&wc));
- }
-
-
- /****************************************************************************
- Save instance handle and create main window
- ****************************************************************************/
-
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- int i;
- HDC hDC;
-
- hInst = hInstance;
-
- hDemoWnd = CreateWindow(
- "DemoWClass",
- "TER Demonstration",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- NULL,
- NULL,
- hInstance,
- NULL
- );
-
- if (!hDemoWnd)
- return (FALSE);
-
- ShowWindow(hDemoWnd, nCmdShow);
- UpdateWindow(hDemoWnd);
-
-
- //****** initialize the structure variables to open an editor window *********
- for (i=0;i<MAX_WINDS;i++) {
- arg[i].x=40; // Initial X position of TER edit window
- arg[i].y=40; // Initial Y position of TER edit window
- arg[i].width=550; // Initial edit window width
- arg[i].height=300; // Initial edit window height
- arg[i].LineLimit=0; // set to 0 for unlimited number of lines
- arg[i].InitLine=1; // Initial line number to position on
- arg[i].WordWrap=TRUE; // Word wrap on?
- arg[i].PrintView=FALSE; // Wrap at window width
- arg[i].PageMode=FALSE; // Edit continuous
- arg[i].InputType='F'; // Input type: (F)ile or (B)uffer
- arg[i].ShowStatus=TRUE; // display the status
- arg[i].ShowMenu=TRUE; // display menu
- arg[i].ShowVerBar=TRUE; // display vertical scroll bar
- arg[i].ShowHorBar=FALSE; // display horizontal scroll bar (N/A with word wrap)
- arg[i].UserCanClose=TRUE; // user can close this window
- arg[i].ruler=TRUE; // show the ruler
- arg[i].ToolBar=TRUE; // show the tool bar
- arg[i].BorderMargins=TRUE; // display margins around border
- arg[i].ReadOnly=FALSE; // Allow edits
- #if defined(WIN32)
- strcpy(arg[i].file,"DEMO.SSE");// Text file name if the input type is 'F'
- #else
- strcpy(arg[i].file,"DEMO.TER");// Text file name if the input type is 'F'
- #endif
- arg[i].hBuffer=0; // handle to the input/output buffer
- arg[i].SaveFormat=SAVE_DEFAULT; // format of the output file (keep it save as input)
- arg[i].hInst=hInst; // Current application instant handle
- arg[i].hParentWnd=hDemoWnd; // let this be the parent of the editor window
- arg[i].style=WS_OVERLAPPEDWINDOW; // Editor window style
- strcpy(arg[i].FontTypeFace,"Arial"); // default font type faces
- arg[i].PointSize=12; // point size of the default font
- arg[i].open=FALSE; // all window closed in the beginning
- }
-
- //****** initialize the structure variables to demonstrate printing of a
- // file or buffer *********
-
- // define the printing area rectangle
- PrtRect.left=50; // distance (mm) from the left edge of the paper
- PrtRect.right=150; // distance (mm) from the right edge of the paper
- PrtRect.top=75; // distance (mm) from the top edge of the paper
- PrtRect.bottom=175; // distance (mm) from the bottom edge of the paper
-
- // fill the StrPrint structure
- prt.InputType='F'; // pass data in a file
- #if defined(WIN32)
- lstrcpy(prt.file,"DEMO.SSE"); // default file to print
- #else
- lstrcpy(prt.file,"DEMO.TER"); // default file to print
- #endif
-
- prt.hBuffer=0; // buffer handle when InputType = 'B'
- prt.BufferLen=0; // length of the buffer
- prt.delim=13; // line delimiter in the buffer
- prt.hDC=NULL; // printer device context
- prt.rect=&PrtRect; // printing area on the page
- prt.StartPos=0; // starting character position
- prt.OnePage=TRUE; // print first page only
- prt.NextPos=0; // this value is filled by the TerMergePrint function
- prt.hInst=hInst; // instance of the demo program
- prt.hParentWnd=hDemoWnd; // let demo receive any messages
- prt.PrintHiddenText=TRUE; // print hidden text if any
- prt.MergeFields="CompanyName|FirstName|LastName|StreetAddress|city|st|zip"; // field name list
- prt.MergeData="Computer Designs, Inc.|Jim|Grady|200 South Street|Madison|MA|02180"; // field data list
-
- // initialize the search replace parameters
- search[0]=replace[0]=0;
- SearchFlags=SRCH_SEARCH|SRCH_CASE|SRCH_SCROLL;
- SearchCurPos=SearchEndPos=SearchSize=0;
-
- // get the screen resolution
- hDC=GetDC(hDemoWnd);
- ResX=GetDeviceCaps(hDC,LOGPIXELSX); // pixels per inch
- ResY=GetDeviceCaps(hDC,LOGPIXELSY);
- ReleaseDC(hDemoWnd,hDC);
-
- return (TRUE);
- }
-
- /****************************************************************************
- Process Main Window messages
- ****************************************************************************/
-
- LRESULT CALLBACK _export DemoWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- DLGPROC lpProcParam;
- BOOL bCallTer,result;
- int i;
- struct StrHyperLink far *link;
- int CommandId,OpenCount=0;
-
- switch (message) {
-
- case WM_COMMAND:
- // extract the command id from wParam
- CommandId=GET_WM_COMMAND_ID(wParam,lParam);
- switch (CommandId) {
- case IDM_OPEN: // open a new window
- // find an unused window parameter block
- for (CurWnd=0;CurWnd<MAX_WINDS;CurWnd++) if (!arg[CurWnd].open) break;
- if (CurWnd==MAX_WINDS) {
- MessageBox(hWnd,"All window parameter blocks in use!",NULL,MB_OK);
- break;
- }
-
- lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoOpenDlg, hInst);
- bCallTer=DialogBox(hInst,"DemoOpenDlg",hWnd,lpProcParam);
- FreeProcInstance((FARPROC)lpProcParam);
-
- if (bCallTer) CallTer(hWnd);// Prepare parameters and call TER routine
- break;
-
- case IDM_CLOSE: // close a TER window
- for (i=0;i<MAX_WINDS;i++) {
- if (arg[i].open) {
- OpenCount++;
- CurWnd=i;
- }
- }
- if (OpenCount==0) break;
-
- if (OpenCount>1) {
- lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoCloseDlg, hInst);
- CurWnd=DialogBox(hInst,"DemoCloseDlg",hWnd,lpProcParam);
- FreeProcInstance((FARPROC)lpProcParam);
- }
-
- if (CurWnd>=0) CloseTer(arg[CurWnd].hTextWnd,TRUE);
- break;
-
- case IDM_RESET: // reset a TER window
- for (i=0;i<MAX_WINDS;i++) {
- if (arg[i].open) {
- OpenCount++;
- CurWnd=i;
- }
- }
- if (OpenCount==0) break;
-
- if (OpenCount>1) {
- lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoResetDlg, hInst);
- CurWnd=DialogBox(hInst,"DemoResetDlg",hWnd,lpProcParam);
- FreeProcInstance((FARPROC)lpProcParam);
- }
-
- if (CurWnd>=0) { // call the SetTerBuffer function
- MakeBuffer(hWnd);
- SetTerBuffer(arg[CurWnd].hTextWnd,arg[CurWnd].hBuffer,arg[CurWnd].BufferLen,"REFRESHED",TRUE);
- }
- break;
-
- case IDM_FIELDS: // monitor window variables
- for (i=0;i<MAX_WINDS;i++) {
- if (arg[i].open) {
- OpenCount++;
- CurWnd=i;
- }
- }
- if (OpenCount==0) break;
-
- if (OpenCount>1) {
- lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoSelectWin, hInst);
- CurWnd=DialogBox(hInst,"DemoSelectWin",hWnd,lpProcParam);
- FreeProcInstance((FARPROC)lpProcParam);
- }
-
- if (CurWnd>=0) { // retrieve and set window variables
- GetTerFields(arg[CurWnd].hTextWnd,&field); // get internal fields
- lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoFields, hInst);
- result=DialogBox(hInst,"DemoFields",hWnd,lpProcParam);
- FreeProcInstance((FARPROC)lpProcParam);
- if (result) SetTerFields(arg[CurWnd].hTextWnd,&field); // set internal fields
- }
- break;
-
- case IDM_INSERT: // insert text at the specified location
- for (i=0;i<MAX_WINDS;i++) {
- if (arg[i].open) {
- OpenCount++;
- CurWnd=i;
- }
- }
- if (OpenCount==0) break;
-
- // select window to insert text into
- if (OpenCount>1) {
- lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoSelectWin, hInst);
- CurWnd=DialogBox(hInst,"DemoSelectWin",hWnd,lpProcParam);
- FreeProcInstance((FARPROC)lpProcParam);
- }
-
- if (CurWnd>=0) { // retrieve and set window variables
- lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoInsertText, hInst);
- result=DialogBox(hInst,"DemoInsertText",hWnd,lpProcParam);
- if (result) InsertText(arg[CurWnd].hTextWnd);// insert the new text
- FreeProcInstance((FARPROC)lpProcParam);
- }
- break;
-
- case IDM_PRINT: // print a buffer
- PrintText(hWnd); // print the buffer
- break;
-
- case IDM_SEARCH: // search/replace
- OpenCount=0;
- for (i=0;i<MAX_WINDS;i++) {
- if (arg[i].open) {
- CurWnd=i;
- OpenCount++; // atleast one window open
- }
- }
- if (OpenCount==0) break;
-
- if (OpenCount>1) { // select an open window
- lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoSelectWin, hInst);
- CurWnd=DialogBox(hInst,"DemoSelectWin",hWnd,lpProcParam);
- FreeProcInstance((FARPROC)lpProcParam);
- }
-
- if (CurWnd>=0) { // retrieve and set window variables
- lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoSearchDlg, hInst);
- DialogBox(hInst,"DemoSearchDlg",hWnd,lpProcParam);
- FreeProcInstance((FARPROC)lpProcParam);
- }
- break;
-
- case IDM_PREVIEW: // draw the image of the first page
- for (i=0;i<MAX_WINDS;i++) {
- if (arg[i].open) {
- OpenCount++;
- CurWnd=i;
- }
- }
- if (OpenCount==0) break;
-
- if (OpenCount>1) {
- lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoSelectWin, hInst);
- CurWnd=DialogBox(hInst,"DemoSelectWin",hWnd,lpProcParam);
- FreeProcInstance((FARPROC)lpProcParam);
- }
-
- if (CurWnd>=0) DemoPreview();
-
- break;
-
-
- case IDM_OTHER: // demonstrate other API functions
- DemoGetTerLine(hWnd); // GetTerLine and SetTerLine
- DemoGetFontInfo(hWnd); // GetFontInfo
- break;
-
- default:
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- break;
-
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
-
- case WM_CLOSE: // close all TER windows
- for (i=0;i<MAX_WINDS;i++) {
- if (arg[i].open) CloseTer(arg[i].hTextWnd,TRUE);
- }
- DestroyWindow(hWnd);
- if (hPrtDC) DeleteDC(hPrtDC); // delete the printer device context
- break;
-
- /********************************************************************
- Messages coming from the TER Window
- *********************************************************************/
- case TER_CLOSE: // TER sends this message before closing
- for (i=0;i<MAX_WINDS;i++) { // mark this window as closed
- if (arg[i].open && arg[i].hTextWnd==(HWND)wParam) {
- arg[i].open=FALSE;
- arg[i].hBuffer=0;
- if (arg[i].InputType=='B') { // get the updated buffer
- arg[i].hBuffer=GetTerBuffer(arg[i].hTextWnd,&arg[i].BufferLen);
- }
- break;
- }
- }
- break;
-
- case TER_MODIFIED: // TER sends this message when the text is modified
- for (i=0;i<MAX_WINDS;i++) { // mark this window as modified for information purposes
- if (arg[i].open && arg[i].hTextWnd==(HWND)wParam) {
- arg[i].modified=TRUE;
- break;
- }
- }
- break;
-
- case TER_LINK: // demo of editor hyper link
- link=(struct StrHyperLink far *)(DWORD)lParam;
- if (lstrlen(link->code)>0) {
- MessageBox(hWnd,link->text, link->code,MB_OK);
- return TRUE; // hyperlink processed
- }
- else return FALSE; // hyperlink not processed
-
- case TER_MERGE: // example of providing mail merge data
- if (lstrcmpi((LPSTR)lParam,"date")==0) return (long)(LPSTR)"Jan 1, 1995";
- break;
-
- default:
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- return (LRESULT)NULL;
- }
-
- /******************************************************************************
- Read the input file if necessary and call the TER routine
- *******************************************************************************/
- void CallTer(hWnd)
- HANDLE hWnd;
- {
-
- if (arg[CurWnd].InputType=='B') { /* In a real life application, you will use the
- buffer option when the data is located in
- a buffer form in a data base. For the purpose
- of this demo, we will make a buffer from
- the file name you just supplied. */
- arg[CurWnd].delim=13; // use a ASCII 13 character for the line delimiter
-
- if (arg[CurWnd].hBuffer==0) { // make a buffer if it does not already exist
- MakeBuffer(hWnd);
- }
- else {
- if (strcmp(arg[CurWnd].file,PrevFile)!=0) {
- GlobalFree(arg[CurWnd].hBuffer);
- arg[CurWnd].hBuffer=0;
- MakeBuffer(hWnd);
- }
- }
- }
-
- CreateTerWindow(&arg[CurWnd]); //open the ter window with these values
- }
-
- /*****************************************************************************
- Read the text file into a buffer to be passed to the Ter routine.
- *****************************************************************************/
- void MakeBuffer(HWND hWnd)
- {
- char huge *buffer;
- long FileSize;
- FILE *InStream; // to read the input file
-
- if (access(arg[CurWnd].file,6)==-1) { // if a new file
- arg[CurWnd].hBuffer=GlobalAlloc(GMEM_MOVEABLE,1);
- buffer=GlobalLock(arg[CurWnd].hBuffer);
- buffer[0]=arg[CurWnd].delim;
- GlobalUnlock(arg[CurWnd].hBuffer);
- arg[CurWnd].BufferLen=1;
- return;
- }
-
- InStream=fopen(arg[CurWnd].file,"rb"); // open the file
- if (!InStream) {
- MessageBox(hWnd,"Error in opening file",NULL,MB_OK);return;}
-
- FileSize=filelength(fileno(InStream));
- if (NULL==(arg[CurWnd].hBuffer=GlobalAlloc(GMEM_MOVEABLE,FileSize))
- || (NULL==(buffer=(char huge *)GlobalLock(arg[CurWnd].hBuffer)))) {
- MessageBox(hWnd,"Ran Out of Memory.",NULL,MB_OK);
- return;
- }
-
- arg[CurWnd].BufferLen=0;
-
- while (fread(DemoLine,1,1,InStream)==1) {
- /* read one byte at a time because 'fread' wouldn't work with
- a 'far' buffer in the small model */
- buffer[arg[CurWnd].BufferLen]=DemoLine[0];
- (arg[CurWnd].BufferLen)++;
- }
-
- fclose(InStream);
-
- if (arg[CurWnd].BufferLen==0) {buffer[0]=arg[CurWnd].delim;arg[CurWnd].BufferLen=1;}
- GlobalUnlock(arg[CurWnd].hBuffer);
- }
-
- /*****************************************************************************
- InsertText:
- This routine inserts the given text into the specified position in the
- specified window.
- *****************************************************************************/
- BOOL InsertText(HWND hWnd)
- {
- long NewLine;
- int NewCol;
-
-
- // insert text and get new cursor position
- SetTerCursorPos(hWnd,CurLine,CurCol,FALSE); // set cursor pos, don't refresh
- GetTerCursorPos(hWnd,&CurLine,&CurCol); // get cursor pos, don't refresh
-
- InsertTerText(hWnd,NewText,FALSE); // insert text, don't refresh screen
- NewCol=0;
- GetTerCursorPos(hWnd,&NewLine,&NewCol);
-
- // highlight the new text and apply new font
- SelectTerText(hWnd,CurLine,CurCol,NewLine,NewCol,FALSE); // highlight the new text
- SetTerFont(hWnd,CurTypeface,FALSE);
- SetTerPointSize(hWnd,CurPointSize,FALSE);
- SetTerCharStyle(hWnd,CurStyle,TRUE,FALSE);
- SetTerColor(hWnd,CurColor,TRUE);
-
- return TRUE;
- }
-
- /******************************************************************************
- EditFont:
- Show the common dialog to accept new font/color for the text
- ******************************************************************************/
- BOOL EditFont(HWND hWnd)
- {
- int i,ResY,NewFont,SaveHeight,SaveWidth,GroupItem;
- CHOOSEFONT cFont;
- LOGFONT lFont;
- int font;
-
- // Fill the lFont structure
- memset(&lFont,0,sizeof(lFont));
- ResY=GetDeviceCaps(GetDC(hWnd),LOGPIXELSY);
- lFont.lfHeight=-(int)(((long)CurPointSize*ResY)/72);
- lFont.lfWeight=CurStyle&BOLD ? 700 : 400;
- lFont.lfItalic=(BYTE)(CurStyle&ITALIC ? TRUE : FALSE);
- lFont.lfUnderline=(BYTE)(CurStyle&ULINE ? TRUE : FALSE);
- lFont.lfStrikeOut=(BYTE)(CurStyle&STRIKE ? TRUE : FALSE);
- lFont.lfCharSet=ANSI_CHARSET;
- lFont.lfOutPrecision=OUT_DEFAULT_PRECIS;
- lFont.lfClipPrecision=CLIP_DEFAULT_PRECIS;
- lFont.lfQuality=DRAFT_QUALITY;
- lFont.lfPitchAndFamily=DEFAULT_PITCH|FF_DONTCARE;
- lstrcpy(lFont.lfFaceName,CurTypeface);
-
- // fill the CHOOSEFONT structure
- memset(&cFont,0,sizeof(CHOOSEFONT));
- cFont.lStructSize=sizeof(CHOOSEFONT);
- cFont.hwndOwner=hWnd;
- cFont.hDC=0; // print device context
- cFont.lpLogFont=&lFont;
- cFont.Flags=CF_BOTH|CF_EFFECTS|CF_INITTOLOGFONTSTRUCT;
- cFont.rgbColors=CurColor;
-
- if (!ChooseFont(&cFont)) return FALSE;
-
- // Extract the chosen properties
- lstrcpy(CurTypeface,lFont.lfFaceName);
- CurPointSize=(int)(((long)lFont.lfHeight*(long)72)/ResY);
- if (CurPointSize<0) CurPointSize=-CurPointSize;
- CurColor=cFont.rgbColors;
-
- CurStyle=0;
-
- if (lFont.lfWeight>400) CurStyle|=BOLD;
- if (lFont.lfItalic) CurStyle|=ITALIC;
- if (lFont.lfUnderline) CurStyle|=ULINE;
- if (lFont.lfStrikeOut) CurStyle|=STRIKE;
-
- return TRUE;
- }
-
- /*****************************************************************************
- PrintText:
- This routine prints the specified file or buffer to the given printer.
- *****************************************************************************/
- BOOL PrintText(HWND hWnd)
- {
- BOOL result;
- DLGPROC lpProcParam;
- char JobName[32];
-
- // open the current printer if not already open
- if (!hPrtDC) hPrtDC=OpenCurPrinter(hWnd);
-
- lpProcParam = (DLGPROC) MakeProcInstance((FARPROC)DemoPrintDlg, hInst);
- result=DialogBox(hInst,"DemoPrintDlg",hWnd,lpProcParam);
- FreeProcInstance((FARPROC)lpProcParam);
- if (!result) return TRUE;
-
- // specify the output device
- if (PrtOutput==IDC_DEF_PRINTER) prt.hDC=NULL; // print to default printer
- else if (PrtOutput==IDC_SPEC_PRINTER)prt.hDC=hPrtDC; // print to specified printer DC
- else if (PrtOutput==IDC_SPEC_WINDOW) prt.hDC=GetDC(hWnd);// print to specified window DC
-
- // Create a file buffer if the file is to passed as a buffer
- if (prt.InputType=='B') {
- CurWnd=MAX_WINDS-1; // prepare to call MakeBuffer
- arg[CurWnd].hBuffer=prt.hBuffer;
- arg[CurWnd].BufferLen=prt.BufferLen;
- arg[CurWnd].delim=prt.delim;
- lstrcpy(arg[CurWnd].file,prt.file);
- if (arg[CurWnd].hBuffer==0) { // make a buffer if it does not already exist
- MakeBuffer(hWnd);
- }
- else {
- if (strcmp(arg[CurWnd].file,PrevFile)!=0) {
- GlobalFree(arg[CurWnd].hBuffer);
- arg[CurWnd].hBuffer=0;
- MakeBuffer(hWnd);
- }
- }
- prt.hBuffer=arg[CurWnd].hBuffer;
- prt.BufferLen=arg[CurWnd].BufferLen;
- }
-
-
- // begin the print job when printing to our printer device context
- if (PrtOutput==IDC_SPEC_PRINTER) {
- strcpy(JobName,"Demo Ter Print");
- Escape(hPrtDC,STARTDOC,strlen(JobName),JobName,0L); // begin print job
- }
-
- // call the DLL to print
- if (TerMergePrint(&prt)) {
- prt.StartPos=prt.NextPos; // Starting position for the next page
-
- if (PrtOutput==IDC_SPEC_PRINTER) { // end the printing job when printing to our printer DC
- Escape(hPrtDC,NEWFRAME,0,0L,0L);
- Escape(hPrtDC,ENDDOC,0,0L,0L); // end of print job
- }
- }
- else if (PrtOutput==IDC_SPEC_PRINTER) Escape(hPrtDC,ABORTDOC,0,0L,0L); // printing aborted
-
- if (PrtOutput==IDC_SPEC_WINDOW) ReleaseDC(hWnd,prt.hDC); // release the window handle
-
- return TRUE;
- }
-
- /*****************************************************************************
- DemoPreview:
- Preview the first page of the document.
- *****************************************************************************/
- BOOL DemoPreview()
- {
- int PrtResX,PrtResY,WinWidth,WinHeight,RectWidth,ResX,ResY;
- POINT pt;
- float PageWidth,PageHeight;
- RECT rect;
- HDC hDC;
- HPEN hOldPen;
- HBRUSH hOldBrush;
-
- // open the current printer if not already open
- if (!hPrtDC) hPrtDC=OpenCurPrinter(hDemoWnd);
- hDC=GetDC(hDemoWnd); // screen device context
-
- // get the printer page width/height
- PrtResX=GetDeviceCaps(hPrtDC,LOGPIXELSX); // number of pixels per inch of X direction
- PrtResY=GetDeviceCaps(hPrtDC,LOGPIXELSY); // number of pixels per inch of Y direction
-
- Escape(hPrtDC,GETPHYSPAGESIZE,0,NULL,&pt);
- PageWidth=(float)pt.x/PrtResX; // actual page size
- PageHeight=(float)pt.y/PrtResY;
-
- // get the size of the rectangle
- GetClientRect(hDemoWnd,&rect);
- WinWidth=rect.right-rect.left;
- WinHeight=rect.bottom-rect.top;
- RectWidth=(int)((WinHeight*PageWidth)/PageHeight);
-
- // adjust width for different x y resolution
- ResX=GetDeviceCaps(hDC,LOGPIXELSX); // number of pixels per inch of X direction
- ResY=GetDeviceCaps(hDC,LOGPIXELSY); // number of pixels per inch of Y direction
-
- RectWidth=(int)(((long)RectWidth*ResX)/(long)ResY);
-
- // center the rectangle
- rect.left=(WinWidth-RectWidth)/2;
- rect.right=rect.left+RectWidth;
-
-
- // display the page
- hOldPen=SelectObject(hDC,GetStockObject(BLACK_PEN));
- hOldBrush=SelectObject(hDC,GetStockObject(WHITE_BRUSH));
- Rectangle(hDC,rect.left,rect.top,rect.right,rect.bottom); // draw the frame
- SelectObject(hDC,hOldPen);
- SelectObject(hDC,hOldBrush);
-
- TerPrintPreview(arg[CurWnd].hTextWnd,hDC,&rect,-1,TRUE); // preview the current page
-
- // release the resources
- ReleaseDC(hDemoWnd,hDC);
-
- return TRUE;
- }
-
- /*****************************************************************************
- DemoGetTerLine:
- This routines demonstrate retrieving lines from the first window and
- pasting it to the second window using the 'GetTerLine' and 'SetTerLine'
- functions.
- *****************************************************************************/
- BOOL DemoGetTerLine(HWND hWnd)
- {
- long l;
- char text[300],font[300];
-
- if (arg[0].open && arg[1].open) {
- for (l=0;;l++) {
- if (GetTerLine(arg[0].hTextWnd,l,text,font)==-1) break;
- SetTerLine(arg[1].hTextWnd,l,text,font);
- }
- }
-
- return TRUE;
- }
-
- /*****************************************************************************
- DemoGetFontInfo:
- This routines demonstrate retrieving the font information for the
- first font for the first TER window.
- *****************************************************************************/
- BOOL DemoGetFontInfo(HWND hWnd)
- {
- char string[300],typeface[32];
- int PointSize;
- UINT style;
-
- if (arg[0].open) {
- if (GetFontInfo(arg[0].hTextWnd,0,typeface,&PointSize,&style)) {
- wsprintf(string,"Typeface: %s, Point Size: %d, Styles: %X",(LPSTR)typeface,PointSize,style);
- MessageBox(hWnd,string,"Font Id: 0 Data",MB_OK);
- }
- }
- return TRUE;
- }
-
- /******************************************************************************
- OpenCurPrinter:
- Open the current printer. This function returns the device context of
- the printer.
- *******************************************************************************/
- HDC OpenCurPrinter(HWND hWnd)
- {
- char PrinterName[60], // name of the printer
- PrinterDriver[60], // printer driver
- PrinterPort[60]; // printer port
- HDC hPrtDC;
-
- if (!CurrentPrinter(PrinterName,PrinterDriver,PrinterPort)) return NULL; // get current printer info
-
- // Open the printer device context
- PrinterDriver[lstrlen(PrinterDriver)-4]=0; // strip the .drv extension
- if (NULL==(hPrtDC=CreateDC(PrinterDriver,PrinterName,PrinterPort,NULL))) {
- MessageBox(NULL,"Can not initialize printing","Device Context Error",MB_OK);
- return NULL;
- }
-
- return hPrtDC;
- }
-
- /******************************************************************************
- CurrentPrinter:
- Get information (name,driver,port) for the currently selected printer.
- The function returns FALSE if the current printer not set.
- ******************************************************************************/
- BOOL CurrentPrinter(LPSTR name,LPSTR driver,LPSTR port)
- {
- char PrintData[80],ext[5];
- LPSTR temp,name1,driver1=0,port1=0;
- int len;
-
- name[0]=driver[0]=port[0]=0; // initialized the output variables
-
- if (!GetProfileString("windows","device",(LPSTR) "",PrintData,80)) return FALSE;
-
- temp=name1=PrintData; // beginning pointer for the scan
-
- while(*temp) { // scan until a NULL is found
- if (*temp==',') { // a delimited found
- *temp=0; // NULL terminate the previous string, and advance the pointer
- temp++;
- while (*temp==' ') temp=AnsiNext(temp); // skip leading spaces
- if (!driver1) driver1=temp; // Initiate the driver string if not found yet
- else { // else it is the last string, i.e. the port string
- port1=temp;
- break; // all strings parsed
- }
- }
- else temp=AnsiNext(temp); // advance the pointer
- }
-
- lstrcpy(name,name1); // copy the strings to the user specified area
- lstrcpy(port,port1);
- lstrcpy(driver,driver1);
-
- // add .drv extension to the driver name, if necessary
- len=lstrlen(driver);
- if (len<=4) lstrcat(driver,".drv");
- else {
- lstrcpy(ext,&driver[len-4]);
- if (lstrcmpi(ext,".DRV")!=0) lstrcat(driver,".DRV");
- }
-
- return TRUE;
- }
-
-
- /******************************************************************************
- Helper Routines
- *******************************************************************************/
-
- /******************************************************************************
- HugeMemMove:
- Use this function to move data from one buffer to another when the
- buffer may be larger than 64K. For buffer smaller than 64K, the
- FarMove function will provide much better performance.
- *******************************************************************************/
- void HugeMemMove(char huge *src,char huge * dest, UINT count)
- {
- UINT i;
-
- for (i=0;i<count;i++) dest[i]=src[i];
- return;
- }
-
- /******************************************************************************
- AssignIntValue:
- Extract an integer value from the dialog item. Display error if a non-
- numeric value is encountered and return a false result.
- *******************************************************************************/
- BOOL AssignIntValue(HWND hWin,int ControlId,LPINT pInt)
- {
- BOOL ErrorFlag;
-
- *pInt=GetDlgItemInt(hWin,ControlId,&ErrorFlag,(BOOL) 0);
- if (!ErrorFlag) {
- MessageBox(hWin,"Must Enter a Valid Number",NULL,MB_OK);
- SetFocus(GetDlgItem(hWin,ControlId));
- return (FALSE);
- }
- return TRUE;
- }
-
- /******************************************************************************
- AssignLongValue:
- Extract a long value from the dialog item. Display error if a non-
- numeric value is encountered and return a false result.
- *******************************************************************************/
- BOOL AssignLongValue(HWND hWin,int ControlId,LPLONG pLong)
- {
- char string[20];
- int i;
-
- GetDlgItemText(hWin,ControlId,string,sizeof(string)-1); // get the number
-
- for (i=0;i<strlen(string);i++) { // check for non numeric characters
- if (string[i]=='-') continue;
- if (string[i]<'0' || string[i]>'9') {
- MessageBox(hWin,"Must Enter a Valid Number",NULL,MB_OK);
- SetFocus(GetDlgItem(hWin,ControlId));
- return (FALSE);
- }
- }
-
- (*pLong)=atol(string); // convert to long
-
- return TRUE;
- }
-
- /******************************************************************************
- SetDemoLong:
- Set a long value to a dialog field.
- *******************************************************************************/
- BOOL SetDemoLong(HWND hDlg,int ControlId,long value)
- {
- char string[20];
-
- wsprintf(string,"%ld",value);
- SetDlgItemText(hDlg,ControlId,string);
-
- return TRUE;
- }
-
- /******************************************************************************
- GetDemoLong:
- Gety a long value from a dialog field.
- *******************************************************************************/
- BOOL GetDemoLong(HWND hDlg,int ControlId,long *value)
- {
- GetDlgItemText(hDlg,ControlId,DemoLine,19);
- (*value)=atol(DemoLine);
-
- return TRUE;
- }
-
- /******************************************************************************
- OurPrintf:
- This routine formats and display a given set of arguments. The format
- is given by the first argument. The argument 2 to n contain the
- arguments for the specified format. The function uses MessageBox to
- display the formatted string.
- ******************************************************************************/
- int OurPrintf(LPSTR fmt,...)
- {
- LPSTR ArgStart;
- char string[MAX_WIDTH+2];
-
- ArgStart=(LPSTR) &fmt; // pointer to first argument
- ArgStart=&ArgStart[4]; // go past the first argument
- wvsprintf(string,fmt,ArgStart);
- if (FindWindow("DBWin",NULL)) { // debug window open
- lstrcat(string,"\n");
- OutputDebugString(string); // send to the debug terminal
- }
- else MessageBox(NULL,string,NULL,MB_OK);
- return TRUE;
- }
-
-
- /****************************************************************************
- DEMO DIALOG PROCEDURES
- ****************************************************************************/
-
- /****************************************************************************
- Process messages for "DemoOpenDlg" dialog box
- This dialog box accepts the parameters to be passed to TER routine.
- Finally this routines makes a call to TER routine to open a window.
- ****************************************************************************/
- int CALLBACK _export DemoOpenDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- BOOL flag;
-
- switch (message) {
- case WM_INITDIALOG:
- // Set initial values of the parameters
- SetDlgItemInt(hDlg,IDC_X,arg[CurWnd].x,0);
- SetDlgItemInt(hDlg,IDC_Y,arg[CurWnd].y,0);
- SetDlgItemInt(hDlg,IDC_WIDTH,arg[CurWnd].width,0);
- SetDlgItemInt(hDlg,IDC_HEIGHT,arg[CurWnd].height,0);
- SetDemoLong(hDlg,IDC_MAX_LINES,arg[CurWnd].LineLimit);
- SetDemoLong(hDlg,IDC_INIT_LINE,arg[CurWnd].InitLine);
- SendMessage(GetDlgItem(hDlg,IDC_WORD_WRAP),BM_SETCHECK, arg[CurWnd].WordWrap, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_PRINT_VIEW),BM_SETCHECK, arg[CurWnd].PrintView, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_PAGE_MODE),BM_SETCHECK, arg[CurWnd].PageMode, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_RULER),BM_SETCHECK, arg[CurWnd].ruler, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_TOOL_BAR),BM_SETCHECK, arg[CurWnd].ToolBar, 0L);
- if (arg[CurWnd].InputType=='F') flag=FALSE;else flag=TRUE;
- SendMessage(GetDlgItem(hDlg,IDC_FILE_OPT),BM_SETCHECK, flag, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_STATUS_LINE),BM_SETCHECK, arg[CurWnd].ShowStatus, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_MENU),BM_SETCHECK, arg[CurWnd].ShowMenu, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_VER_BAR),BM_SETCHECK, arg[CurWnd].ShowVerBar, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_HOR_BAR),BM_SETCHECK, arg[CurWnd].ShowHorBar, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_USER_CLOSE),BM_SETCHECK, arg[CurWnd].UserCanClose, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_BORDER),BM_SETCHECK, arg[CurWnd].BorderMargins, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_READ_ONLY),BM_SETCHECK, arg[CurWnd].ReadOnly, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_CHILD),BM_SETCHECK, arg[CurWnd].style&WS_CHILD?TRUE:FALSE, 0L);
-
- strcpy(PrevFile,arg[CurWnd].file); // store the previous file name
- SetDlgItemText(hDlg,IDC_FILE_NAME,arg[CurWnd].file);
-
- // set output file format
- SendMessage(GetDlgItem(hDlg,IDC_SAVE_DEFAULT),BM_SETCHECK, arg[CurWnd].SaveFormat==SAVE_DEFAULT, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_SAVE_TER),BM_SETCHECK, arg[CurWnd].SaveFormat==SAVE_TER, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_SAVE_RTF),BM_SETCHECK, arg[CurWnd].SaveFormat==SAVE_RTF, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_SAVE_TEXT),BM_SETCHECK, arg[CurWnd].SaveFormat==SAVE_TEXT, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_SAVE_TEXT_LINES),BM_SETCHECK, arg[CurWnd].SaveFormat==SAVE_TEXT_LINES, 0L);
-
- return (TRUE);
-
- case WM_COMMAND:
- switch (wParam) {
- case IDOK:
- if (!AssignIntValue(hDlg,IDC_X,&arg[CurWnd].x)) return (TRUE);
- if (!AssignIntValue(hDlg,IDC_Y,&arg[CurWnd].y)) return (TRUE);
- if (!AssignIntValue(hDlg,IDC_WIDTH,&arg[CurWnd].width)) return (TRUE);
- if (!AssignIntValue(hDlg,IDC_HEIGHT,&arg[CurWnd].height)) return (TRUE);
- if (!AssignLongValue(hDlg,IDC_MAX_LINES,&arg[CurWnd].LineLimit)) return (TRUE);
- if (!AssignLongValue(hDlg,IDC_INIT_LINE,&arg[CurWnd].InitLine)) return (TRUE);
- arg[CurWnd].WordWrap=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_WORD_WRAP),BM_GETCHECK, 0, 0L);
- arg[CurWnd].PrintView=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_PRINT_VIEW),BM_GETCHECK, 0, 0L);
- arg[CurWnd].PageMode=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_PAGE_MODE),BM_GETCHECK, 0, 0L);
- arg[CurWnd].ruler=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_RULER),BM_GETCHECK, 0, 0L);
- arg[CurWnd].ToolBar=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_TOOL_BAR),BM_GETCHECK, 0, 0L);
- flag=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_FILE_OPT),BM_GETCHECK, 0, 0L);
- if (flag) arg[CurWnd].InputType='B';else arg[CurWnd].InputType='F';
- arg[CurWnd].ShowStatus=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_STATUS_LINE),BM_GETCHECK, 0, 0L);
- arg[CurWnd].ShowMenu=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_MENU),BM_GETCHECK, 0, 0L);
- arg[CurWnd].ShowVerBar=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_VER_BAR),BM_GETCHECK, 0, 0L);
- arg[CurWnd].ShowHorBar=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_HOR_BAR),BM_GETCHECK, 0, 0L);
- arg[CurWnd].UserCanClose=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_USER_CLOSE),BM_GETCHECK, 0, 0L);
- arg[CurWnd].BorderMargins=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_BORDER),BM_GETCHECK, 0, 0L);
- arg[CurWnd].ReadOnly=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_READ_ONLY),BM_GETCHECK, 0, 0L);
-
- flag=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_CHILD),BM_GETCHECK, 0, 0L);
- if (flag) arg[CurWnd].style=WS_CHILD|WS_THICKFRAME|WS_BORDER|WS_CAPTION|WS_MINIMIZEBOX|WS_MAXIMIZEBOX;
- else arg[CurWnd].style=WS_OVERLAPPEDWINDOW;
-
- GetDlgItemText(hDlg,IDC_FILE_NAME,arg[CurWnd].file,100);
-
- // get output file format
- if (SendMessage(GetDlgItem(hDlg,IDC_SAVE_DEFAULT),BM_GETCHECK, 0, 0L)) arg[CurWnd].SaveFormat=SAVE_DEFAULT;
- else if (SendMessage(GetDlgItem(hDlg,IDC_SAVE_TER),BM_GETCHECK, 0, 0L)) arg[CurWnd].SaveFormat=SAVE_TER;
- else if (SendMessage(GetDlgItem(hDlg,IDC_SAVE_RTF),BM_GETCHECK, 0, 0L)) arg[CurWnd].SaveFormat=SAVE_RTF;
- else if (SendMessage(GetDlgItem(hDlg,IDC_SAVE_TEXT),BM_GETCHECK, 0, 0L)) arg[CurWnd].SaveFormat=SAVE_TEXT;
- else if (SendMessage(GetDlgItem(hDlg,IDC_SAVE_TEXT_LINES),BM_GETCHECK, 0, 0L)) arg[CurWnd].SaveFormat=SAVE_TEXT_LINES;
-
- EndDialog(hDlg, TRUE);
- return (TRUE);
-
- case IDCANCEL:
- EndDialog(hDlg, FALSE);
- return (TRUE);
- default:
- ;
- }
- break;
- }
- return (FALSE);
- }
-
- /****************************************************************************
- Process messages for "DemoPrintDlg" dialog box
- ****************************************************************************/
- int FAR PASCAL _export DemoPrintDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- BOOL flag,FullPage,OnePage;
-
- switch (message) {
- case WM_INITDIALOG:
- // Set the buffer/file option
- if (prt.InputType=='F') flag=FALSE;else flag=TRUE;
- SendMessage(GetDlgItem(hDlg,IDC_FILE_OPT),BM_SETCHECK, flag, 0L);
- strcpy(PrevFile,prt.file); // store the previous file name
- SetDlgItemText(hDlg,IDC_FILE_NAME,prt.file);
-
- // set output device
- SendMessage(GetDlgItem(hDlg,IDC_DEF_PRINTER), BM_SETCHECK, PrtOutput==IDC_DEF_PRINTER, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_SPEC_PRINTER),BM_SETCHECK, PrtOutput==IDC_SPEC_PRINTER, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_SPEC_WINDOW), BM_SETCHECK, PrtOutput==IDC_SPEC_WINDOW, 0L);
-
- // set printing area parameters
- SetDlgItemInt(hDlg,IDC_X,PrtRect.left,0);
- SetDlgItemInt(hDlg,IDC_Y,PrtRect.top,0);
- SetDlgItemInt(hDlg,IDC_WIDTH,PrtRect.right-PrtRect.left,0);
- SetDlgItemInt(hDlg,IDC_HEIGHT,PrtRect.bottom-PrtRect.top,0);
- if (PrtOutput==IDC_SPEC_WINDOW) prt.rect=NULL; // full window by default
- if (prt.rect==NULL) {
- SendMessage(GetDlgItem(hDlg,IDC_FULL_PAGE),BM_SETCHECK, TRUE, 0L);
- EnableWindow(GetDlgItem(hDlg,IDC_X),FALSE); // disable
- EnableWindow(GetDlgItem(hDlg,IDC_Y),FALSE); // disable
- EnableWindow(GetDlgItem(hDlg,IDC_WIDTH),FALSE); // disable
- EnableWindow(GetDlgItem(hDlg,IDC_HEIGHT),FALSE); // disable
- }
-
- // set other variables
- SetDemoLong(hDlg,IDC_START_POS,prt.StartPos);
- SendMessage(GetDlgItem(hDlg,IDC_ONE_PAGE),BM_SETCHECK, prt.OnePage, 0L);
-
- return (TRUE);
-
- case WM_COMMAND:
- switch (wParam) {
- case IDC_SPEC_WINDOW: // print to a specified window
- SendMessage(GetDlgItem(hDlg,IDC_FULL_PAGE),BM_SETCHECK, TRUE, 0L); // full page by default
-
- case IDC_FULL_PAGE:
- FullPage=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_FULL_PAGE),BM_GETCHECK, 0, 0L);
- EnableWindow(GetDlgItem(hDlg,IDC_X),!FullPage);
- EnableWindow(GetDlgItem(hDlg,IDC_Y),!FullPage);
- EnableWindow(GetDlgItem(hDlg,IDC_WIDTH),!FullPage);
- EnableWindow(GetDlgItem(hDlg,IDC_HEIGHT),!FullPage);
- break;
-
- case IDOK:
- if (!AssignLongValue(hDlg,IDC_START_POS,&(prt.StartPos))) return (TRUE);
-
- FullPage=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_FULL_PAGE),BM_GETCHECK, 0, 0L);
- if (FullPage) prt.rect=NULL;
- else {
- prt.rect=&PrtRect; // pointer to the printing area rectangle
- if (!AssignIntValue(hDlg,IDC_X,(LPINT)&PrtRect.left)) return (TRUE);
- if (!AssignIntValue(hDlg,IDC_Y,(LPINT)&PrtRect.top)) return (TRUE);
- if (!AssignIntValue(hDlg,IDC_WIDTH,(LPINT)&PrtRect.right)) return (TRUE);
- if (!AssignIntValue(hDlg,IDC_HEIGHT,(LPINT)&PrtRect.bottom)) return (TRUE);
- PrtRect.right+=PrtRect.left; // convert width to right coordinate
- PrtRect.bottom+=PrtRect.top; // convert height to bottom coordinate
- }
-
- flag=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_FILE_OPT),BM_GETCHECK, 0, 0L);
- if (flag) prt.InputType='B';else prt.InputType='F';
- GetDlgItemText(hDlg,IDC_FILE_NAME,prt.file,100);
-
- // get output device;
- if ((BOOL) SendMessage(GetDlgItem(hDlg,IDC_DEF_PRINTER),BM_GETCHECK,0,0L)) PrtOutput=IDC_DEF_PRINTER;
- if ((BOOL) SendMessage(GetDlgItem(hDlg,IDC_SPEC_PRINTER),BM_GETCHECK,0,0L)) PrtOutput=IDC_SPEC_PRINTER;
- if ((BOOL) SendMessage(GetDlgItem(hDlg,IDC_SPEC_WINDOW),BM_GETCHECK,0,0L)) PrtOutput=IDC_SPEC_WINDOW;
-
- prt.OnePage=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_ONE_PAGE),BM_GETCHECK, 0, 0L);
-
- // set the rectangle when printing to the window
- if (PrtOutput==IDC_SPEC_WINDOW && prt.rect==NULL) {// print to the demo window
- prt.rect=&PrtRect; // always specify the rectanble
- GetClientRect(hDemoWnd,&PrtRect); // print to entire client area
- // convert from pixel units to mm units
- PrtRect.left=PixelToMmX(PrtRect.left);
- PrtRect.right=PixelToMmX(PrtRect.right);
- PrtRect.top=PixelToMmY(PrtRect.top);
- PrtRect.bottom=PixelToMmY(PrtRect.bottom);
- }
-
- EndDialog(hDlg, TRUE);
- return (TRUE);
-
- case IDCANCEL:
- EndDialog(hDlg, FALSE);
- return (TRUE);
- default:
- ;
- }
- break;
- }
- return (FALSE);
- }
-
- /****************************************************************************
- DemoCloseDlg:
- This dialog box allows you to select a TER window to close. The index
- of the selected window is returned.
- ****************************************************************************/
- int FAR PASCAL _export DemoCloseDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- int i,j;
- char string[64];
-
- switch (message) {
- case WM_INITDIALOG:
- // insert the open file names in the dialog box
- for (i=0;i<MAX_WINDS;i++) {
- if (arg[i].open) {
- if (arg[i].file[0]==0) SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_ADDSTRING, 0, (DWORD)(LPSTR)"UNNAMED");
- else SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_ADDSTRING, 0, (DWORD)(LPSTR)arg[i].file);
- }
- }
- SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_SETCURSEL, 0,0L);
- SetFocus(GetDlgItem(hDlg,IDC_BOX));
- return (FALSE);
-
- case WM_COMMAND:
- switch (wParam) {
- case IDC_BOX:
- if (HIWORD(lParam)!=LBN_DBLCLK) break;
-
- case IDOK:
- j=(int)SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_GETCURSEL, 0,0L);
- SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_GETTEXT, j,(DWORD)(LPSTR)string);
- if (lstrcmp(string,"UNNAMED")==0) string[0]=0;
- for (i=0;i<MAX_WINDS;i++) {
- if (arg[i].open && lstrcmp(arg[i].file,string)==0) {
- EndDialog(hDlg, i);
- return (TRUE);
- }
- }
- EndDialog(hDlg, -1);
- return (TRUE);
-
- case IDCANCEL:
- EndDialog(hDlg, -1);
- return (TRUE);
- default:
- ;
- }
- break;
- }
- return (FALSE);
- }
-
- /****************************************************************************
- DemoResetDlg:
- This dialog box allows you to select a TER window to be reset. The
- reset example is meant to demonstrate the use of the 'SetTerBuffer'
- function.
- ****************************************************************************/
-
- int FAR PASCAL _export DemoResetDlg(HWND hDlg, UINT message,WPARAM wParam,LPARAM lParam)
- {
- int i,j;
- char string[64];
-
- switch (message) {
- case WM_INITDIALOG:
- // insert the open file names in the dialog box
- for (i=0;i<MAX_WINDS;i++) {
- if (arg[i].open) {
- if (arg[i].file[0]==0) SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_ADDSTRING, 0, (DWORD)(LPSTR)"UNNAMED"); // file name not provided
- else SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_ADDSTRING, 0, (DWORD)(LPSTR)arg[i].file);
- }
- }
- SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_SETCURSEL, 0,0L);
- SetFocus(GetDlgItem(hDlg,IDC_BOX));
- return (FALSE);
-
- case WM_COMMAND:
- switch (wParam) {
- case IDC_BOX:
- if (HIWORD(lParam)!=LBN_DBLCLK) break;
-
- case IDOK:
- j=(int)SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_GETCURSEL, 0,0L);
- SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_GETTEXT, j,(DWORD)(LPSTR)string);
- if (lstrcmp(string,"UNNAMED")==0) string[0]=0;
- for (i=0;i<MAX_WINDS;i++) {
- if (arg[i].open && lstrcmp(arg[i].file,string)==0) {
- if (arg[i].InputType!='B') {
- MessageBox(hDlg,"File Type Window Can Not be Refreshed!",NULL,MB_OK);
- return (TRUE);
- }
- EndDialog(hDlg, i);
- return (TRUE);
- }
- }
- EndDialog(hDlg, -1);
- return (TRUE);
-
- case IDCANCEL:
- EndDialog(hDlg, -1);
- return (TRUE);
- default:
- ;
- }
- break;
- }
- return (FALSE);
- }
-
- /****************************************************************************
- DemoSelectWin:
- This dialog box allows you to select a TER window.
- ****************************************************************************/
- int FAR PASCAL _export DemoSelectWin(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- int i,j;
- char string[64];
-
- switch (message) {
- case WM_INITDIALOG:
- // insert the open file names in the dialog box
- for (i=0;i<MAX_WINDS;i++) {
- if (arg[i].open) {
- if (arg[i].file[0]==0) SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_ADDSTRING, 0, (DWORD)(LPSTR)"UNNAMED");
- else SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_ADDSTRING, 0, (DWORD)(LPSTR)arg[i].file);
- }
- }
- SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_SETCURSEL, 0,0L);
- SetFocus(GetDlgItem(hDlg,IDC_BOX));
- return (FALSE);
-
- case WM_COMMAND:
- switch (wParam) {
- case IDC_BOX:
- if (HIWORD(lParam)!=LBN_DBLCLK) break;
-
- case IDOK:
- j=(int)SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_GETCURSEL, 0,0L);
- SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_GETTEXT, j,(DWORD)(LPSTR)string);
- if (lstrcmp(string,"UNNAMED")==0) string[0]=0;
- for (i=0;i<MAX_WINDS;i++) {
- if (arg[i].open && lstrcmp(arg[i].file,string)==0) {
- EndDialog(hDlg, i);
- return (TRUE);
- }
- }
- EndDialog(hDlg, -1);
- return (TRUE);
-
- case IDCANCEL:
- EndDialog(hDlg, -1);
- return (TRUE);
- default:
- ;
- }
- break;
- }
- return (FALSE);
- }
-
- /****************************************************************************
- DemoFields:
- This dialog box shows the internal variables for the current window, and
- let to modify them.
- ****************************************************************************/
- int FAR PASCAL _export DemoFields(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- int i,j;
-
- switch (message) {
- case WM_INITDIALOG:
- // Set read/write dialog fields
- // Position variables
- SetDemoLong(hDlg,IDC_CUR_ROW,field.CurRowW);
- SetDlgItemInt(hDlg,IDC_CUR_COL,field.CurColW,0);
- SetDemoLong(hDlg,IDC_CUR_LINE,field.CurLineW);
- SetDemoLong(hDlg,IDC_BEGIN_LINE,field.BeginLineW);
-
- // Color variables
- SetDemoLong(hDlg,IDC_TEXT_BK_COLOR,(long)field.TextBkColorW);
- SetDemoLong(hDlg,IDC_STATUS_COLOR,(long)field.StatusColorW);
- SetDemoLong(hDlg,IDC_STATUS_BK_COLOR,(long)field.StatusBkColorW);
- SetDemoLong(hDlg,IDC_LINK_COLOR,(long)field.LinkColorW);
- SendDlgItemMessage(hDlg,IDC_MODIFY_PROTECT_COLOR, BM_SETCHECK, field.ModifyProtectColorW, 0L);
-
- // Highlight variables
- if (field.HilightTypeW==HILIGHT_OFF) SendMessage(GetDlgItem(hDlg,IDC_HILIGHT_TYPE_OFF), BM_SETCHECK, TRUE, 0L);
- if (field.HilightTypeW==HILIGHT_LINE) SendMessage(GetDlgItem(hDlg,IDC_HILIGHT_TYPE_LINE),BM_SETCHECK, TRUE, 0L);
- if (field.HilightTypeW==HILIGHT_CHAR) SendMessage(GetDlgItem(hDlg,IDC_HILIGHT_TYPE_CHAR),BM_SETCHECK, TRUE, 0L);
- SetDemoLong(hDlg,IDC_HILIGHT_BEG_ROW,field.HilightBegRowW);
- SetDemoLong(hDlg,IDC_HILIGHT_END_ROW,field.HilightEndRowW);
- SetDlgItemInt(hDlg,IDC_HILIGHT_BEG_COL,field.HilightBegColW,0);
- SetDlgItemInt(hDlg,IDC_HILIGHT_END_COL,field.HilightEndColW,0);
- SendMessage(GetDlgItem(hDlg,IDC_STRETCH_HILIGHT),BM_SETCHECK, field.StretchHilightW, 0L);
-
- // Text data variables
- SetDlgItemText(hDlg,IDC_TEXT,field.text);
- SetDlgItemInt(hDlg,IDC_LINE_LEN,field.LineLenW,0);
- SetDlgItemInt(hDlg,IDC_PFMT,(int)field.pfmtW,0);
- if (field.TextApply==APPLY_IGNORE) SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_IGNORE),BM_SETCHECK, TRUE, 0L);
- if (field.TextApply==APPLY_MOD_CUR_LINE) SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_CUR),BM_SETCHECK, TRUE, 0L);
- if (field.TextApply==APPLY_BEF_CUR_LINE) SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_BEF),BM_SETCHECK, TRUE, 0L);
- if (field.TextApply==APPLY_AFT_CUR_LINE) SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_AFT),BM_SETCHECK, TRUE, 0L);
-
- //* Paint/wrapping and other flag
- SendMessage(GetDlgItem(hDlg,IDC_PAINT_ENABLED),BM_SETCHECK, field.PaintEnabledW, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_WRAP),BM_SETCHECK, field.WrapFlagW!=WRAP_OFF, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_LINK_DBL_CLICK),BM_SETCHECK, field.LinkDblClickW, 0L);
- SendMessage(GetDlgItem(hDlg,IDC_SHOW_PROTECT_CARET),BM_SETCHECK, field.ShowProtectCaretW, 0L);
- SetDlgItemInt(hDlg,IDC_LINK_STYLE,field.LinkStyleW,0);
-
- // Set read Only dialog fields
- SetDemoLong(hDlg,IDC_TOTAL_LINES,field.TotalLinesW);
- SetDlgItemInt(hDlg,IDC_TOTAL_PFMTS,field.TotalPfmtsW,0);
- SetDlgItemInt(hDlg,IDC_TOTAL_FONTS,field.TotalFontsW,0);
- SendMessage(GetDlgItem(hDlg,IDC_MODIFIED),BM_SETCHECK, field.modified, 0L);
-
- SetFocus(GetDlgItem(hDlg,IDCANCEL));
- return (FALSE);
-
- case WM_COMMAND:
- switch (wParam) {
- case IDOK:
- // retrieve dialog fields
- // Position variables
- if (!AssignLongValue(hDlg,IDC_CUR_ROW,&field.CurRowW)) return TRUE;
- if (!AssignIntValue(hDlg,IDC_CUR_COL,&field.CurColW)) return TRUE;
- if (!AssignLongValue(hDlg,IDC_CUR_LINE,&field.CurLineW)) return TRUE;
- if (!AssignLongValue(hDlg,IDC_BEGIN_LINE,&field.BeginLineW)) return TRUE;
-
- // Color variables
- GetDemoLong(hDlg,IDC_TEXT_BK_COLOR,(long *)&field.TextBkColorW);
- GetDemoLong(hDlg,IDC_STATUS_COLOR,(long *)&field.StatusColorW);
- GetDemoLong(hDlg,IDC_STATUS_BK_COLOR,(long *)&field.StatusBkColorW);
- GetDemoLong(hDlg,IDC_LINK_COLOR,(long *)&(field.LinkColorW));
- field.ModifyProtectColorW=(BOOL)SendDlgItemMessage(hDlg,IDC_MODIFY_PROTECT_COLOR,BM_GETCHECK, 0, 0L);
-
- // Highlight variables
- field.HilightTypeW=HILIGHT_OFF;
- if (SendMessage(GetDlgItem(hDlg,IDC_HILIGHT_TYPE_LINE),BM_GETCHECK, 0, 0L)) field.HilightTypeW=HILIGHT_LINE;
- if (SendMessage(GetDlgItem(hDlg,IDC_HILIGHT_TYPE_CHAR),BM_GETCHECK, 0, 0L)) field.HilightTypeW=HILIGHT_CHAR;
- if (!AssignLongValue(hDlg,IDC_HILIGHT_BEG_ROW,&field.HilightBegRowW)) return TRUE;
- if (!AssignLongValue(hDlg,IDC_HILIGHT_END_ROW,&field.HilightEndRowW)) return TRUE;
- if (!AssignIntValue(hDlg,IDC_HILIGHT_BEG_COL,&field.HilightBegColW)) return TRUE;
- if (!AssignIntValue(hDlg,IDC_HILIGHT_END_COL,&field.HilightEndColW)) return TRUE;
- field.StretchHilightW=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_STRETCH_HILIGHT),BM_GETCHECK, 0, 0L);
-
- // Text data variables
- GetDlgItemText(hDlg,IDC_TEXT,field.text,MAX_WIDTH);
- field.LineLenW=strlen(field.text);
-
- if (!AssignIntValue(hDlg,IDC_PFMT,&i)) return TRUE;
- field.pfmtW=(BYTE)i;
-
- field.TextApply=APPLY_IGNORE;
- if (SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_CUR),BM_GETCHECK, 0, 0L)) field.TextApply=APPLY_MOD_CUR_LINE;
- if (SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_BEF),BM_GETCHECK, 0, 0L)) field.TextApply=APPLY_BEF_CUR_LINE;
- if (SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_AFT),BM_GETCHECK, 0, 0L)) field.TextApply=APPLY_AFT_CUR_LINE;
-
- // Paint enable and other flag
- field.PaintEnabledW=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_PAINT_ENABLED),BM_GETCHECK, 0, 0L);
- if (SendMessage(GetDlgItem(hDlg,IDC_WRAP),BM_GETCHECK, 0, 0L))
- field.WrapFlagW=WRAP_WIN;
- else field.WrapFlagW=WRAP_OFF;
- field.LinkDblClickW=(BOOL)SendDlgItemMessage(hDlg,IDC_LINK_DBL_CLICK,BM_GETCHECK, 0, 0L);
- field.ShowProtectCaretW=(BOOL)SendDlgItemMessage(hDlg,IDC_SHOW_PROTECT_CARET,BM_GETCHECK, 0, 0L);
-
- if (!AssignIntValue(hDlg,IDC_LINK_STYLE,&(field.LinkStyleW))) return TRUE;
-
- EndDialog(hDlg, TRUE);
- return (TRUE);
-
- case IDCANCEL:
- EndDialog(hDlg, FALSE);
- return (TRUE);
- default:
- ;
- }
- break;
- }
- return (FALSE);
- }
-
- /****************************************************************************
- DemoInsertText:
- This dialog box accepts text (with attributes) to insert into the
- chosen TER window.
- ****************************************************************************/
- int FAR PASCAL _export DemoInsertText(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- int i,j;
-
- switch (message) {
- case WM_INITDIALOG:
- // set current row/col
- GetTerCursorPos(arg[CurWnd].hTextWnd,&CurLine,&CurCol);
- SetDemoLong(hDlg,IDC_INSERT_LINE,CurLine);
- SetDlgItemInt(hDlg,IDC_INSERT_COL,CurCol,0);
-
- SetFocus(GetDlgItem(hDlg,IDC_INSERT_TEXT));
- return (FALSE);
-
- case WM_COMMAND:
- switch (wParam) {
- case IDC_INSERT_FONT:
- EditFont(hDlg);
- break;
-
- case IDOK:
- if (!AssignLongValue(hDlg,IDC_INSERT_LINE,&CurLine)) return TRUE;
- if (!AssignIntValue(hDlg,IDC_INSERT_COL,&CurCol)) return TRUE;
- GetDlgItemText(hDlg,IDC_INSERT_TEXT,NewText,2*MAX_WIDTH);
- NewText[2*MAX_WIDTH]=0;
-
- EndDialog(hDlg, TRUE);
- return (TRUE);
-
- case IDCANCEL:
- EndDialog(hDlg, FALSE);
- return (TRUE);
- default:
- ;
- }
- break;
- }
- return (FALSE);
- }
-
- /****************************************************************************
- DemoSearchDlg:
- This dialog box accepts the parameters for the search/replace api
- ****************************************************************************/
- int FAR PASCAL _export DemoSearchDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- int i,j;
- BOOL result;
-
- switch (message) {
- case WM_INITDIALOG:
- // set current values
- SetDlgItemText(hDlg,IDC_SEARCH,search);
- SetDlgItemText(hDlg,IDC_REPLACE,replace);
-
- SendDlgItemMessage(hDlg,IDC_FLAG_SCROLL,BM_SETCHECK, SearchFlags&SRCH_SCROLL, 0L);
- SendDlgItemMessage(hDlg,IDC_FLAG_SEARCH,BM_SETCHECK, SearchFlags&SRCH_SEARCH, 0L);
- SendDlgItemMessage(hDlg,IDC_FLAG_REPLACE,BM_SETCHECK, SearchFlags&SRCH_REPLACE, 0L);
- SendDlgItemMessage(hDlg,IDC_FLAG_RETRIEVE,BM_SETCHECK, SearchFlags&SRCH_RETRIEVE, 0L);
- SendDlgItemMessage(hDlg,IDC_FLAG_CASE,BM_SETCHECK, SearchFlags&SRCH_CASE, 0L);
- SendDlgItemMessage(hDlg,IDC_FLAG_WORD,BM_SETCHECK, SearchFlags&SRCH_WORD, 0L);
-
- SetDemoLong(hDlg,IDC_POS_CUR,SearchCurPos);
- SetDemoLong(hDlg,IDC_POS_END,SearchEndPos);
- SetDemoLong(hDlg,IDC_SEARCH_SIZE,SearchSize);
-
- SetFocus(GetDlgItem(hDlg,IDCANCEL));
-
- return (FALSE);
-
- case WM_COMMAND:
- switch (wParam) {
-
- case IDOK:
- // retrieve the updated values
- GetDlgItemText(hDlg,IDC_SEARCH,search,sizeof(search)-1);
- GetDlgItemText(hDlg,IDC_REPLACE,replace,sizeof(replace)-1);
-
- SearchFlags=0;
- if ((BOOL)SendDlgItemMessage(hDlg,IDC_FLAG_SCROLL,BM_GETCHECK, 0, 0L)) SearchFlags|=SRCH_SCROLL;
- if ((BOOL)SendDlgItemMessage(hDlg,IDC_FLAG_SEARCH,BM_GETCHECK, 0, 0L)) SearchFlags|=SRCH_SEARCH;
- if ((BOOL)SendDlgItemMessage(hDlg,IDC_FLAG_REPLACE,BM_GETCHECK, 0, 0L)) SearchFlags|=SRCH_REPLACE;
- if ((BOOL)SendDlgItemMessage(hDlg,IDC_FLAG_RETRIEVE,BM_GETCHECK, 0, 0L)) SearchFlags|=SRCH_RETRIEVE;
- if ((BOOL)SendDlgItemMessage(hDlg,IDC_FLAG_CASE,BM_GETCHECK, 0, 0L)) SearchFlags|=SRCH_CASE;
- if ((BOOL)SendDlgItemMessage(hDlg,IDC_FLAG_WORD,BM_GETCHECK, 0, 0L)) SearchFlags|=SRCH_WORD;
-
- if (!AssignLongValue(hDlg,IDC_POS_CUR,&SearchCurPos)) return TRUE;
- if (!AssignLongValue(hDlg,IDC_POS_END,&SearchEndPos)) return TRUE;
- if (!AssignLongValue(hDlg,IDC_SEARCH_SIZE,&SearchSize)) return TRUE;
-
- // make the API call
- result=TerSearchReplace(arg[CurWnd].hTextWnd,search,replace,SearchFlags,SearchCurPos,&SearchEndPos,&SearchSize);
-
- if (result) SetDlgItemText(hDlg,IDC_RESULT,"True");
- else SetDlgItemText(hDlg,IDC_RESULT,"False");
-
- // redisplay the updated values
- DemoSearchDlg(hDlg,WM_INITDIALOG,0,0L);
-
- break;
-
- case IDCANCEL:
- EndDialog(hDlg, FALSE);
- return (TRUE);
- default:
- ;
- }
- break;
- }
- return (FALSE);
- }
-
-