home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / tedevkit / demo.c < prev    next >
C/C++ Source or Header  |  1995-09-11  |  69KB  |  1,565 lines

  1. /*==============================================================================
  2.    DEMO-TER.C :- TER Demo Program (Window3 Version of TER.C).
  3.    Sub Systems, Inc.
  4.    Software License Agreement  (1989)              
  5.    ----------------------------------
  6.    This is a demo program.  The program shows how you can utilize TERW.OBJ 
  7.    routine to perform text editing functions. The program will prompt you 
  8.    for the control variables to be passed to TERW.OBJ routine.
  9. ===============================================================================*/
  10. #define  STRICT
  11.  
  12. #include "windows.h"
  13. #if defined (_WIN32)
  14.    #if !defined(WIN32)
  15.      #define WIN32
  16.    #endif
  17. #endif
  18. #if !defined(WIN32) 
  19.   #include "print.h"
  20.   #if defined (__TURBOC__)
  21.     typedef unsigned short USHORT;     // missing in compiler
  22.   #endif
  23. #endif
  24.  
  25. #include "stdio.h"
  26. #include "stdlib.h"
  27. #include "fcntl.h"
  28. #include "sys\types.h"
  29. #include "sys\stat.h"
  30. #include "io.h"
  31. #include "string.h"
  32.  
  33. #include "commdlg.h"
  34.  
  35. /******************************************************************************
  36.     WIN32 specific defines
  37. *******************************************************************************/
  38. #if defined (WIN32)
  39.    #undef  huge
  40.    #define huge
  41.    #undef  FreeProcInstance 
  42.    #define FreeProcInstance(x) 
  43.    #define GET_WM_COMMAND_ID(wp,lp) LOWORD(wp)
  44.    #define farmalloc  malloc
  45.    #define farrealloc realloc
  46.    #define farfree    free
  47. #else
  48.    #define GET_WM_COMMAND_ID(wp,lp) (wp)
  49. #endif
  50.  
  51. #include "ter.h"
  52.  
  53. #include "demo.h"
  54.  
  55. char DemoCfmtSign[30]="~`!@#$%^&*()-+|=-TeCfMt"; // string that signifies the beginning of formatting information 
  56.  
  57. /****************************************************************************
  58.    Main Windows Routine
  59. ****************************************************************************/
  60. int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
  61. {
  62.     MSG msg;
  63.     int i;
  64.  
  65.     #ifndef WIN32
  66.       int QueueLength=96;
  67.       while (!SetMessageQueue(QueueLength) && (QueueLength-=8));
  68.     #endif
  69.  
  70.     SetMessageQueue(96);   // needed for OLE2
  71.  
  72.     hPrevInst=hPrevInstance;
  73.     if (!hPrevInstance)
  74.         if (!InitApplication(hInstance))
  75.             return (FALSE);
  76.  
  77.     if (!InitInstance(hInstance, nCmdShow))
  78.         return (FALSE);
  79.  
  80.     while (GetMessage(&msg, NULL, 0, 0)) {
  81.         TranslateMessage(&msg);
  82.         DispatchMessage(&msg);
  83.     }
  84.     return (msg.wParam);
  85. }
  86.  
  87. /****************************************************************************
  88.    Initialize window data and register window class
  89. ****************************************************************************/
  90.  
  91. BOOL InitApplication(HINSTANCE hInstance)
  92. {
  93.     WNDCLASS  wc;
  94.  
  95.     wc.style = 0;
  96.     wc.lpfnWndProc = (void far *)DemoWndProc;
  97.     wc.cbClsExtra = 0;
  98.     wc.cbWndExtra = 0;
  99.     wc.hInstance = hInstance;
  100.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  101.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  102.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  103.     wc.lpszMenuName =  "DemoMenu";
  104.     wc.lpszClassName = "DemoWClass";
  105.  
  106.     return (RegisterClass(&wc));
  107. }
  108.  
  109.  
  110. /****************************************************************************
  111.     Save instance handle and create main window
  112. ****************************************************************************/
  113.  
  114. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  115. {
  116.     int i;
  117.     HDC hDC;
  118.  
  119.     hInst = hInstance;
  120.  
  121.     hDemoWnd = CreateWindow(
  122.         "DemoWClass",
  123.         "TER Demonstration",
  124.         WS_OVERLAPPEDWINDOW,
  125.         CW_USEDEFAULT,
  126.         CW_USEDEFAULT,
  127.         CW_USEDEFAULT,
  128.         CW_USEDEFAULT,
  129.         NULL,
  130.         NULL,
  131.         hInstance,
  132.         NULL
  133.     );
  134.  
  135.     if (!hDemoWnd)
  136.         return (FALSE);
  137.  
  138.     ShowWindow(hDemoWnd, nCmdShow);
  139.     UpdateWindow(hDemoWnd);
  140.     
  141.  
  142.     //****** initialize the structure variables to open an editor window *********
  143.     for (i=0;i<MAX_WINDS;i++) {   
  144.         arg[i].x=40;                 // Initial X position of TER edit window 
  145.         arg[i].y=40;                 // Initial Y position of TER edit window 
  146.         arg[i].width=550;            // Initial edit window width 
  147.         arg[i].height=300;           // Initial edit window height 
  148.         arg[i].LineLimit=0;          // set to 0 for unlimited number of lines 
  149.         arg[i].InitLine=1;           // Initial line number to position on 
  150.         arg[i].WordWrap=TRUE;        // Word wrap on? 
  151.         arg[i].PrintView=FALSE;      // Wrap at window width
  152.         arg[i].PageMode=FALSE;       // Edit continuous
  153.         arg[i].InputType='F';        // Input type: (F)ile or (B)uffer 
  154.         arg[i].ShowStatus=TRUE;      // display the status 
  155.         arg[i].ShowMenu=TRUE;        // display menu 
  156.         arg[i].ShowVerBar=TRUE;      // display vertical scroll bar 
  157.         arg[i].ShowHorBar=FALSE;     // display horizontal scroll bar (N/A with word wrap) 
  158.         arg[i].UserCanClose=TRUE;    // user can close this window 
  159.         arg[i].ruler=TRUE;           // show the ruler
  160.         arg[i].ToolBar=TRUE;         // show the tool bar
  161.         arg[i].BorderMargins=TRUE;   // display margins around border
  162.         arg[i].ReadOnly=FALSE;       // Allow edits
  163.         #if defined(WIN32) 
  164.            strcpy(arg[i].file,"DEMO.SSE");// Text file name if the input type is 'F' 
  165.         #else
  166.            strcpy(arg[i].file,"DEMO.TER");// Text file name if the input type is 'F' 
  167.         #endif
  168.         arg[i].hBuffer=0;            // handle to the input/output buffer 
  169.         arg[i].SaveFormat=SAVE_DEFAULT; // format of the output file (keep it save as input)
  170.         arg[i].hInst=hInst;          // Current application instant handle 
  171.         arg[i].hParentWnd=hDemoWnd;      // let this be the parent of the editor window 
  172.         arg[i].style=WS_OVERLAPPEDWINDOW;    //  Editor window style 
  173.         strcpy(arg[i].FontTypeFace,"Arial"); // default font type faces 
  174.         arg[i].PointSize=12;         //  point size of the default font 
  175.         arg[i].open=FALSE;           // all window closed in the beginning 
  176.     }
  177.  
  178.     //****** initialize the structure variables to demonstrate printing of  a 
  179.     // file or buffer *********
  180.     
  181.     // define the printing area rectangle
  182.     PrtRect.left=50;                    // distance (mm) from the left edge of the paper
  183.     PrtRect.right=150;                  // distance (mm) from the right edge of the paper
  184.     PrtRect.top=75;                     // distance (mm) from the top edge of the paper
  185.     PrtRect.bottom=175;                 // distance (mm) from the bottom edge of the paper
  186.  
  187.     // fill the StrPrint structure
  188.     prt.InputType='F';               // pass data in a file
  189.     #if defined(WIN32) 
  190.        lstrcpy(prt.file,"DEMO.SSE");    // default file to print
  191.     #else
  192.        lstrcpy(prt.file,"DEMO.TER");    // default file to print
  193.     #endif
  194.  
  195.     prt.hBuffer=0;                   // buffer handle when InputType = 'B'
  196.     prt.BufferLen=0;                 // length of the buffer
  197.     prt.delim=13;                    // line delimiter in the buffer
  198.     prt.hDC=NULL;                    // printer device context
  199.     prt.rect=&PrtRect;               // printing area on the page
  200.     prt.StartPos=0;                  // starting character position
  201.     prt.OnePage=TRUE;                // print first page only
  202.     prt.NextPos=0;                   // this value is filled by the TerMergePrint function
  203.     prt.hInst=hInst;                 // instance of the demo program
  204.     prt.hParentWnd=hDemoWnd;             // let demo receive any messages
  205.     prt.PrintHiddenText=TRUE;        // print hidden text if any
  206.     prt.MergeFields="CompanyName|FirstName|LastName|StreetAddress|city|st|zip"; // field name list
  207.     prt.MergeData="Computer Designs, Inc.|Jim|Grady|200 South Street|Madison|MA|02180";    // field data list
  208.  
  209.     // initialize the search replace parameters
  210.     search[0]=replace[0]=0;
  211.     SearchFlags=SRCH_SEARCH|SRCH_CASE|SRCH_SCROLL;
  212.     SearchCurPos=SearchEndPos=SearchSize=0;
  213.  
  214.     // get the screen resolution
  215.     hDC=GetDC(hDemoWnd);
  216.     ResX=GetDeviceCaps(hDC,LOGPIXELSX);   // pixels per inch
  217.     ResY=GetDeviceCaps(hDC,LOGPIXELSY);
  218.     ReleaseDC(hDemoWnd,hDC);
  219.  
  220.     return (TRUE);
  221. }
  222.  
  223. /****************************************************************************
  224.     Process Main Window messages
  225. ****************************************************************************/
  226.  
  227. LRESULT CALLBACK _export DemoWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  228. {
  229.     DLGPROC lpProcParam;
  230.     BOOL bCallTer,result;
  231.     int i;
  232.     struct StrHyperLink far *link;
  233.     int  CommandId,OpenCount=0;
  234.  
  235.     switch (message) {
  236.  
  237.         case WM_COMMAND:
  238.            // extract the command id from wParam
  239.            CommandId=GET_WM_COMMAND_ID(wParam,lParam);
  240.            switch (CommandId) {
  241.               case IDM_OPEN:                 // open a new window 
  242.                  // find an unused window parameter block 
  243.                  for (CurWnd=0;CurWnd<MAX_WINDS;CurWnd++) if (!arg[CurWnd].open) break;
  244.                  if (CurWnd==MAX_WINDS) {
  245.                     MessageBox(hWnd,"All window parameter blocks in use!",NULL,MB_OK);
  246.                     break;
  247.                  }
  248.  
  249.                  lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoOpenDlg, hInst);
  250.                  bCallTer=DialogBox(hInst,"DemoOpenDlg",hWnd,lpProcParam);
  251.                  FreeProcInstance((FARPROC)lpProcParam);
  252.                  
  253.                  if (bCallTer) CallTer(hWnd);// Prepare parameters and call TER routine 
  254.                  break;
  255.               
  256.               case IDM_CLOSE:                // close a TER window 
  257.                  for (i=0;i<MAX_WINDS;i++) {
  258.                     if (arg[i].open) {
  259.                        OpenCount++;
  260.                        CurWnd=i;
  261.                     }
  262.                  }
  263.                  if (OpenCount==0) break;
  264.  
  265.                  if (OpenCount>1) {
  266.                     lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoCloseDlg, hInst);
  267.                     CurWnd=DialogBox(hInst,"DemoCloseDlg",hWnd,lpProcParam);
  268.                     FreeProcInstance((FARPROC)lpProcParam);
  269.                  }
  270.                  
  271.                  if (CurWnd>=0) CloseTer(arg[CurWnd].hTextWnd,TRUE);  
  272.                  break;
  273.  
  274.               case IDM_RESET:                // reset a TER window 
  275.                  for (i=0;i<MAX_WINDS;i++) {
  276.                     if (arg[i].open) {
  277.                        OpenCount++;
  278.                        CurWnd=i;
  279.                     }
  280.                  }
  281.                  if (OpenCount==0) break;
  282.                  
  283.                  if (OpenCount>1) {
  284.                     lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoResetDlg, hInst);
  285.                     CurWnd=DialogBox(hInst,"DemoResetDlg",hWnd,lpProcParam);
  286.                     FreeProcInstance((FARPROC)lpProcParam);
  287.                 }
  288.                  
  289.                  if (CurWnd>=0) {                 // call the SetTerBuffer function 
  290.                     MakeBuffer(hWnd);
  291.                     SetTerBuffer(arg[CurWnd].hTextWnd,arg[CurWnd].hBuffer,arg[CurWnd].BufferLen,"REFRESHED",TRUE);  
  292.                  }
  293.                  break;
  294.               
  295.               case IDM_FIELDS:               // monitor window variables 
  296.                  for (i=0;i<MAX_WINDS;i++) {
  297.                     if (arg[i].open) {
  298.                        OpenCount++;
  299.                        CurWnd=i;
  300.                     }
  301.                  }
  302.                  if (OpenCount==0) break;
  303.                  
  304.                  if (OpenCount>1) {
  305.                     lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoSelectWin, hInst);
  306.                     CurWnd=DialogBox(hInst,"DemoSelectWin",hWnd,lpProcParam);
  307.                     FreeProcInstance((FARPROC)lpProcParam);
  308.                  }
  309.                  
  310.                  if (CurWnd>=0) {                 // retrieve and set window variables 
  311.                     GetTerFields(arg[CurWnd].hTextWnd,&field); // get internal fields  
  312.                     lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoFields, hInst);
  313.                     result=DialogBox(hInst,"DemoFields",hWnd,lpProcParam);
  314.                     FreeProcInstance((FARPROC)lpProcParam);
  315.                     if (result) SetTerFields(arg[CurWnd].hTextWnd,&field); // set internal fields  
  316.                  }
  317.                  break;
  318.  
  319.               case IDM_INSERT:               // insert text at the specified location
  320.                  for (i=0;i<MAX_WINDS;i++) {
  321.                     if (arg[i].open) {
  322.                        OpenCount++;
  323.                        CurWnd=i;
  324.                     }
  325.                  }
  326.                  if (OpenCount==0) break;
  327.                  
  328.                  // select window to insert text into 
  329.                  if (OpenCount>1) {
  330.                     lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoSelectWin, hInst);
  331.                     CurWnd=DialogBox(hInst,"DemoSelectWin",hWnd,lpProcParam);
  332.                     FreeProcInstance((FARPROC)lpProcParam);
  333.                  }
  334.                  
  335.                  if (CurWnd>=0) {                 // retrieve and set window variables 
  336.                     lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoInsertText, hInst);
  337.                     result=DialogBox(hInst,"DemoInsertText",hWnd,lpProcParam);
  338.                     if (result) InsertText(arg[CurWnd].hTextWnd);// insert the new text
  339.                     FreeProcInstance((FARPROC)lpProcParam);
  340.                  }
  341.                  break;
  342.  
  343.               case IDM_PRINT:              // print a buffer
  344.                  PrintText(hWnd);          // print the buffer
  345.                  break;
  346.  
  347.               case IDM_SEARCH:            // search/replace
  348.                  OpenCount=0;
  349.                  for (i=0;i<MAX_WINDS;i++) {
  350.                     if (arg[i].open) {
  351.                        CurWnd=i;
  352.                        OpenCount++;       // atleast one window open 
  353.                     }
  354.                  }
  355.                  if (OpenCount==0) break;
  356.                  
  357.                  if (OpenCount>1) {      // select an open window 
  358.                     lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoSelectWin, hInst);
  359.                     CurWnd=DialogBox(hInst,"DemoSelectWin",hWnd,lpProcParam);
  360.                     FreeProcInstance((FARPROC)lpProcParam);
  361.                  }
  362.                  
  363.                  if (CurWnd>=0) {                 // retrieve and set window variables 
  364.                     lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoSearchDlg, hInst);
  365.                     DialogBox(hInst,"DemoSearchDlg",hWnd,lpProcParam);
  366.                     FreeProcInstance((FARPROC)lpProcParam);
  367.                  }
  368.                  break;
  369.  
  370.               case IDM_PREVIEW:                  // draw the image of the first page
  371.                  for (i=0;i<MAX_WINDS;i++) {
  372.                     if (arg[i].open) {
  373.                        OpenCount++;
  374.                        CurWnd=i;
  375.                     }
  376.                  }
  377.                  if (OpenCount==0) break;
  378.                  
  379.                  if (OpenCount>1) {
  380.                     lpProcParam = (DLGPROC)MakeProcInstance((FARPROC)DemoSelectWin, hInst);
  381.                     CurWnd=DialogBox(hInst,"DemoSelectWin",hWnd,lpProcParam);
  382.                     FreeProcInstance((FARPROC)lpProcParam);
  383.                  }
  384.                  
  385.                  if (CurWnd>=0) DemoPreview();
  386.  
  387.                  break;
  388.  
  389.  
  390.               case IDM_OTHER:              // demonstrate other API functions
  391.                  DemoGetTerLine(hWnd);     // GetTerLine and SetTerLine
  392.                  DemoGetFontInfo(hWnd);    // GetFontInfo
  393.                  break;
  394.  
  395.               default:
  396.                 return (DefWindowProc(hWnd, message, wParam, lParam));
  397.            }
  398.            break;
  399.  
  400.         case WM_DESTROY:
  401.             PostQuitMessage(0);
  402.             break;
  403.         
  404.         case WM_CLOSE:                       // close all TER windows 
  405.             for (i=0;i<MAX_WINDS;i++) {
  406.                 if (arg[i].open) CloseTer(arg[i].hTextWnd,TRUE);
  407.             }
  408.             DestroyWindow(hWnd);
  409.             if (hPrtDC) DeleteDC(hPrtDC);    // delete the printer device context
  410.             break;
  411.  
  412.         /********************************************************************
  413.                             Messages coming from the TER Window
  414.         *********************************************************************/
  415.         case TER_CLOSE:                      // TER sends this message before closing 
  416.             for (i=0;i<MAX_WINDS;i++) {      // mark this window as closed 
  417.                 if (arg[i].open && arg[i].hTextWnd==(HWND)wParam) {
  418.                     arg[i].open=FALSE;
  419.                     arg[i].hBuffer=0;
  420.                     if (arg[i].InputType=='B') { // get the updated buffer 
  421.                         arg[i].hBuffer=GetTerBuffer(arg[i].hTextWnd,&arg[i].BufferLen);
  422.                     }
  423.                     break;
  424.                 }
  425.             }
  426.             break;
  427.         
  428.         case TER_MODIFIED:                   // TER sends this message when the text is modified 
  429.             for (i=0;i<MAX_WINDS;i++) {      // mark this window as modified for information purposes 
  430.                 if (arg[i].open && arg[i].hTextWnd==(HWND)wParam) {
  431.                     arg[i].modified=TRUE;
  432.                     break;
  433.                 }
  434.             }
  435.             break;
  436.  
  437.         case TER_LINK:                       // demo of editor hyper link
  438.             link=(struct StrHyperLink far *)(DWORD)lParam;
  439.             if (lstrlen(link->code)>0) {
  440.                MessageBox(hWnd,link->text, link->code,MB_OK);
  441.                return TRUE;                  // hyperlink processed
  442.             }
  443.             else return FALSE;               // hyperlink not processed
  444.  
  445.         case TER_MERGE:                      // example of providing mail merge data
  446.             if (lstrcmpi((LPSTR)lParam,"date")==0) return (long)(LPSTR)"Jan 1, 1995";
  447.             break;
  448.  
  449.         default:
  450.             return (DefWindowProc(hWnd, message, wParam, lParam));
  451.     }
  452.     return (LRESULT)NULL;
  453. }
  454.  
  455. /******************************************************************************
  456.      Read the input file if necessary and call the TER routine
  457. *******************************************************************************/
  458. void CallTer(hWnd)
  459. HANDLE hWnd;
  460. {
  461.  
  462.    if (arg[CurWnd].InputType=='B') {  /* In a real life application, you will use the 
  463.                                          buffer option when the data is located in 
  464.                                          a buffer form in a data base.  For the purpose 
  465.                                          of this demo, we will make a buffer from 
  466.                                          the file name you just supplied. */
  467.       arg[CurWnd].delim=13;           // use a ASCII 13 character for the line delimiter 
  468.  
  469.       if (arg[CurWnd].hBuffer==0) {    // make a buffer if it does not already exist 
  470.          MakeBuffer(hWnd);
  471.       }
  472.       else {
  473.          if (strcmp(arg[CurWnd].file,PrevFile)!=0) {
  474.             GlobalFree(arg[CurWnd].hBuffer);
  475.             arg[CurWnd].hBuffer=0;
  476.             MakeBuffer(hWnd);
  477.          }
  478.       }
  479.    }
  480.  
  481.    CreateTerWindow(&arg[CurWnd]);    //open the ter window with these values 
  482. }
  483.  
  484. /*****************************************************************************
  485.      Read the text file into a buffer to be passed to the Ter routine.
  486. *****************************************************************************/
  487. void MakeBuffer(HWND hWnd)
  488. {
  489.     char huge *buffer;
  490.     long     FileSize;
  491.     FILE *InStream;                    // to read the input file
  492.  
  493.     if (access(arg[CurWnd].file,6)==-1) {      // if a new file 
  494.        arg[CurWnd].hBuffer=GlobalAlloc(GMEM_MOVEABLE,1);
  495.        buffer=GlobalLock(arg[CurWnd].hBuffer);
  496.        buffer[0]=arg[CurWnd].delim;
  497.        GlobalUnlock(arg[CurWnd].hBuffer);
  498.        arg[CurWnd].BufferLen=1;
  499.        return;
  500.     }
  501.  
  502.     InStream=fopen(arg[CurWnd].file,"rb"); // open the file
  503.     if (!InStream) {
  504.         MessageBox(hWnd,"Error in opening file",NULL,MB_OK);return;}
  505.  
  506.     FileSize=filelength(fileno(InStream));
  507.     if   (NULL==(arg[CurWnd].hBuffer=GlobalAlloc(GMEM_MOVEABLE,FileSize)) 
  508.       || (NULL==(buffer=(char huge *)GlobalLock(arg[CurWnd].hBuffer)))) {
  509.         MessageBox(hWnd,"Ran Out of Memory.",NULL,MB_OK);
  510.         return;
  511.     }
  512.  
  513.     arg[CurWnd].BufferLen=0;
  514.     
  515.     while (fread(DemoLine,1,1,InStream)==1) {
  516.       /* read one byte at a time because 'fread' wouldn't work with
  517.          a 'far' buffer in the small model */
  518.       buffer[arg[CurWnd].BufferLen]=DemoLine[0];
  519.       (arg[CurWnd].BufferLen)++;
  520.     }
  521.  
  522.     fclose(InStream);
  523.     
  524.     if (arg[CurWnd].BufferLen==0) {buffer[0]=arg[CurWnd].delim;arg[CurWnd].BufferLen=1;}
  525.     GlobalUnlock(arg[CurWnd].hBuffer);
  526. }
  527.  
  528. /*****************************************************************************
  529.      InsertText:
  530.      This routine inserts the given text into the specified position in the
  531.      specified window.
  532. *****************************************************************************/
  533. BOOL InsertText(HWND hWnd)
  534. {
  535.     long NewLine;
  536.     int  NewCol;
  537.  
  538.  
  539.     // insert text and get new cursor position
  540.     SetTerCursorPos(hWnd,CurLine,CurCol,FALSE); // set cursor pos, don't refresh
  541.     GetTerCursorPos(hWnd,&CurLine,&CurCol);     // get cursor pos, don't refresh
  542.  
  543.     InsertTerText(hWnd,NewText,FALSE);           // insert text, don't refresh screen
  544.     NewCol=0;
  545.     GetTerCursorPos(hWnd,&NewLine,&NewCol);
  546.  
  547.     // highlight the new text and apply new font
  548.     SelectTerText(hWnd,CurLine,CurCol,NewLine,NewCol,FALSE);  // highlight the new text
  549.     SetTerFont(hWnd,CurTypeface,FALSE);
  550.     SetTerPointSize(hWnd,CurPointSize,FALSE);
  551.     SetTerCharStyle(hWnd,CurStyle,TRUE,FALSE);
  552.     SetTerColor(hWnd,CurColor,TRUE);
  553.  
  554.     return TRUE;
  555. }
  556.  
  557. /******************************************************************************
  558.     EditFont:
  559.     Show the common dialog to accept new font/color for the text
  560. ******************************************************************************/
  561. BOOL EditFont(HWND hWnd)
  562. {
  563.     int i,ResY,NewFont,SaveHeight,SaveWidth,GroupItem;
  564.     CHOOSEFONT cFont;
  565.     LOGFONT lFont;
  566.     int font;
  567.  
  568.     // Fill the lFont structure
  569.     memset(&lFont,0,sizeof(lFont));
  570.     ResY=GetDeviceCaps(GetDC(hWnd),LOGPIXELSY);
  571.     lFont.lfHeight=-(int)(((long)CurPointSize*ResY)/72);
  572.     lFont.lfWeight=CurStyle&BOLD ? 700 : 400;
  573.     lFont.lfItalic=(BYTE)(CurStyle&ITALIC ? TRUE : FALSE);
  574.     lFont.lfUnderline=(BYTE)(CurStyle&ULINE  ? TRUE : FALSE);
  575.     lFont.lfStrikeOut=(BYTE)(CurStyle&STRIKE ? TRUE : FALSE);
  576.     lFont.lfCharSet=ANSI_CHARSET;
  577.     lFont.lfOutPrecision=OUT_DEFAULT_PRECIS;
  578.     lFont.lfClipPrecision=CLIP_DEFAULT_PRECIS;
  579.     lFont.lfQuality=DRAFT_QUALITY;
  580.     lFont.lfPitchAndFamily=DEFAULT_PITCH|FF_DONTCARE;
  581.     lstrcpy(lFont.lfFaceName,CurTypeface);
  582.  
  583.     // fill the CHOOSEFONT structure
  584.     memset(&cFont,0,sizeof(CHOOSEFONT));
  585.     cFont.lStructSize=sizeof(CHOOSEFONT);
  586.     cFont.hwndOwner=hWnd;
  587.     cFont.hDC=0;                    // print device context
  588.     cFont.lpLogFont=&lFont;
  589.     cFont.Flags=CF_BOTH|CF_EFFECTS|CF_INITTOLOGFONTSTRUCT;
  590.     cFont.rgbColors=CurColor;
  591.     
  592.     if (!ChooseFont(&cFont)) return FALSE;
  593.  
  594.     // Extract the chosen properties
  595.     lstrcpy(CurTypeface,lFont.lfFaceName);
  596.     CurPointSize=(int)(((long)lFont.lfHeight*(long)72)/ResY);
  597.     if (CurPointSize<0) CurPointSize=-CurPointSize;
  598.     CurColor=cFont.rgbColors;
  599.  
  600.     CurStyle=0;
  601.  
  602.     if (lFont.lfWeight>400) CurStyle|=BOLD;
  603.     if (lFont.lfItalic)     CurStyle|=ITALIC;
  604.     if (lFont.lfUnderline)  CurStyle|=ULINE;
  605.     if (lFont.lfStrikeOut)  CurStyle|=STRIKE;
  606.     
  607.     return TRUE;
  608. }
  609.  
  610. /*****************************************************************************
  611.      PrintText:
  612.      This routine prints the specified file or buffer to the given printer.
  613. *****************************************************************************/
  614. BOOL PrintText(HWND hWnd)
  615. {
  616.     BOOL result;
  617.     DLGPROC lpProcParam;
  618.     char JobName[32];
  619.  
  620.     // open the current printer if not already open
  621.     if (!hPrtDC) hPrtDC=OpenCurPrinter(hWnd);                   
  622.  
  623.     lpProcParam = (DLGPROC) MakeProcInstance((FARPROC)DemoPrintDlg, hInst);
  624.     result=DialogBox(hInst,"DemoPrintDlg",hWnd,lpProcParam);
  625.     FreeProcInstance((FARPROC)lpProcParam);
  626.     if (!result) return TRUE;
  627.  
  628.     // specify the output device
  629.     if      (PrtOutput==IDC_DEF_PRINTER) prt.hDC=NULL;       // print to default printer
  630.     else if (PrtOutput==IDC_SPEC_PRINTER)prt.hDC=hPrtDC;     // print to specified printer DC
  631.     else if (PrtOutput==IDC_SPEC_WINDOW) prt.hDC=GetDC(hWnd);// print to specified window DC
  632.  
  633.     // Create a file buffer if the file is to passed as a buffer
  634.     if (prt.InputType=='B') {
  635.        CurWnd=MAX_WINDS-1;            // prepare to call MakeBuffer 
  636.        arg[CurWnd].hBuffer=prt.hBuffer;
  637.        arg[CurWnd].BufferLen=prt.BufferLen;
  638.        arg[CurWnd].delim=prt.delim;
  639.        lstrcpy(arg[CurWnd].file,prt.file);
  640.        if (arg[CurWnd].hBuffer==0) {    // make a buffer if it does not already exist 
  641.           MakeBuffer(hWnd);
  642.        }
  643.        else {
  644.           if (strcmp(arg[CurWnd].file,PrevFile)!=0) {
  645.              GlobalFree(arg[CurWnd].hBuffer);
  646.              arg[CurWnd].hBuffer=0;
  647.              MakeBuffer(hWnd);
  648.           }
  649.        }
  650.        prt.hBuffer=arg[CurWnd].hBuffer;
  651.        prt.BufferLen=arg[CurWnd].BufferLen;
  652.     }
  653.  
  654.  
  655.     // begin the print job when printing to our printer device context
  656.     if (PrtOutput==IDC_SPEC_PRINTER) {
  657.        strcpy(JobName,"Demo Ter Print");
  658.        Escape(hPrtDC,STARTDOC,strlen(JobName),JobName,0L);   // begin print job 
  659.     }
  660.  
  661.     // call the DLL to print
  662.     if (TerMergePrint(&prt)) {
  663.        prt.StartPos=prt.NextPos;           // Starting position for the next page
  664.  
  665.        if (PrtOutput==IDC_SPEC_PRINTER) {  // end the printing job when printing to our printer DC
  666.           Escape(hPrtDC,NEWFRAME,0,0L,0L);
  667.           Escape(hPrtDC,ENDDOC,0,0L,0L);   // end of print job 
  668.        }
  669.     }
  670.     else if (PrtOutput==IDC_SPEC_PRINTER) Escape(hPrtDC,ABORTDOC,0,0L,0L); // printing aborted
  671.  
  672.     if (PrtOutput==IDC_SPEC_WINDOW) ReleaseDC(hWnd,prt.hDC);   // release the window handle
  673.  
  674.     return TRUE;
  675. }
  676.  
  677. /*****************************************************************************
  678.      DemoPreview:
  679.      Preview the first page of the document.
  680. *****************************************************************************/
  681. BOOL DemoPreview()
  682. {
  683.     int PrtResX,PrtResY,WinWidth,WinHeight,RectWidth,ResX,ResY;
  684.     POINT pt;
  685.     float PageWidth,PageHeight;
  686.     RECT rect;
  687.     HDC hDC;
  688.     HPEN hOldPen;
  689.     HBRUSH hOldBrush;
  690.  
  691.     // open the current printer if not already open
  692.     if (!hPrtDC) hPrtDC=OpenCurPrinter(hDemoWnd);                   
  693.     hDC=GetDC(hDemoWnd);                      // screen device context
  694.  
  695.     // get the printer page width/height
  696.     PrtResX=GetDeviceCaps(hPrtDC,LOGPIXELSX);    // number of pixels per inch of X direction 
  697.     PrtResY=GetDeviceCaps(hPrtDC,LOGPIXELSY);    // number of pixels per inch of Y direction 
  698.  
  699.     Escape(hPrtDC,GETPHYSPAGESIZE,0,NULL,&pt);
  700.     PageWidth=(float)pt.x/PrtResX;            // actual page size
  701.     PageHeight=(float)pt.y/PrtResY;     
  702.     
  703.     // get the size of the rectangle
  704.     GetClientRect(hDemoWnd,&rect);
  705.     WinWidth=rect.right-rect.left;
  706.     WinHeight=rect.bottom-rect.top;
  707.     RectWidth=(int)((WinHeight*PageWidth)/PageHeight);
  708.  
  709.     // adjust width for different x y resolution
  710.     ResX=GetDeviceCaps(hDC,LOGPIXELSX);    // number of pixels per inch of X direction 
  711.     ResY=GetDeviceCaps(hDC,LOGPIXELSY);    // number of pixels per inch of Y direction 
  712.  
  713.     RectWidth=(int)(((long)RectWidth*ResX)/(long)ResY);
  714.  
  715.     // center the rectangle
  716.     rect.left=(WinWidth-RectWidth)/2;
  717.     rect.right=rect.left+RectWidth;
  718.  
  719.  
  720.     // display the page
  721.     hOldPen=SelectObject(hDC,GetStockObject(BLACK_PEN));
  722.     hOldBrush=SelectObject(hDC,GetStockObject(WHITE_BRUSH));
  723.     Rectangle(hDC,rect.left,rect.top,rect.right,rect.bottom);  // draw the frame
  724.     SelectObject(hDC,hOldPen);
  725.     SelectObject(hDC,hOldBrush);
  726.  
  727.     TerPrintPreview(arg[CurWnd].hTextWnd,hDC,&rect,-1,TRUE); // preview the current page
  728.  
  729.     // release the resources
  730.     ReleaseDC(hDemoWnd,hDC);
  731.  
  732.     return TRUE;
  733. }
  734.  
  735. /*****************************************************************************
  736.      DemoGetTerLine:
  737.      This routines demonstrate retrieving lines from the first window and
  738.      pasting it to the second window using the 'GetTerLine' and 'SetTerLine'
  739.      functions. 
  740. *****************************************************************************/
  741. BOOL DemoGetTerLine(HWND hWnd)
  742. {
  743.     long l;
  744.     char text[300],font[300];
  745.  
  746.     if (arg[0].open && arg[1].open) {
  747.        for (l=0;;l++) {
  748.           if (GetTerLine(arg[0].hTextWnd,l,text,font)==-1) break;
  749.           SetTerLine(arg[1].hTextWnd,l,text,font);
  750.        }
  751.     }
  752.  
  753.     return TRUE;
  754. }
  755.  
  756. /*****************************************************************************
  757.      DemoGetFontInfo:
  758.      This routines demonstrate retrieving the font information for the 
  759.      first font for the first TER window.
  760. *****************************************************************************/
  761. BOOL DemoGetFontInfo(HWND hWnd)
  762. {
  763.     char string[300],typeface[32];
  764.     int  PointSize;
  765.     UINT style;
  766.  
  767.     if (arg[0].open) {
  768.        if (GetFontInfo(arg[0].hTextWnd,0,typeface,&PointSize,&style)) {
  769.           wsprintf(string,"Typeface: %s, Point Size: %d, Styles: %X",(LPSTR)typeface,PointSize,style);
  770.           MessageBox(hWnd,string,"Font Id: 0 Data",MB_OK);
  771.        }
  772.     }
  773.     return TRUE;
  774. }
  775.  
  776. /******************************************************************************
  777.     OpenCurPrinter:
  778.     Open the current printer.  This function returns the device context of 
  779.     the printer.
  780. *******************************************************************************/
  781. HDC OpenCurPrinter(HWND hWnd)
  782. {
  783.     char    PrinterName[60],    // name of the printer 
  784.             PrinterDriver[60],  // printer driver 
  785.             PrinterPort[60];    // printer port 
  786.     HDC hPrtDC;
  787.  
  788.     if (!CurrentPrinter(PrinterName,PrinterDriver,PrinterPort)) return NULL; // get current printer info 
  789.  
  790.     // Open the printer device context
  791.     PrinterDriver[lstrlen(PrinterDriver)-4]=0;            // strip the .drv extension 
  792.     if (NULL==(hPrtDC=CreateDC(PrinterDriver,PrinterName,PrinterPort,NULL))) {
  793.         MessageBox(NULL,"Can not initialize printing","Device Context Error",MB_OK);
  794.         return NULL;
  795.     }
  796.  
  797.     return hPrtDC;
  798. }
  799.  
  800. /******************************************************************************
  801.     CurrentPrinter:
  802.     Get information (name,driver,port) for the currently selected printer.
  803.     The function returns FALSE if the current printer not set.
  804. ******************************************************************************/
  805. BOOL CurrentPrinter(LPSTR name,LPSTR driver,LPSTR port)
  806. {
  807.     char PrintData[80],ext[5];
  808.     LPSTR temp,name1,driver1=0,port1=0;
  809.     int len;
  810.  
  811.     name[0]=driver[0]=port[0]=0;       // initialized the output variables 
  812.  
  813.     if (!GetProfileString("windows","device",(LPSTR) "",PrintData,80)) return FALSE;
  814.  
  815.     temp=name1=PrintData;              // beginning pointer for the scan 
  816.  
  817.     while(*temp) {                     // scan until a NULL is found 
  818.        if (*temp==',') {               // a delimited found 
  819.           *temp=0;                     // NULL terminate the previous string, and advance the pointer 
  820.           temp++;
  821.           while (*temp==' ') temp=AnsiNext(temp);   // skip leading spaces 
  822.           if (!driver1) driver1=temp;  // Initiate the driver string if not found yet 
  823.           else {                       // else it is the last string, i.e. the port string 
  824.              port1=temp;
  825.              break;                    // all strings parsed 
  826.           }
  827.        }
  828.        else temp=AnsiNext(temp);       // advance the pointer 
  829.     }
  830.  
  831.     lstrcpy(name,name1);               // copy the strings to the user specified area 
  832.     lstrcpy(port,port1);
  833.     lstrcpy(driver,driver1);
  834.     
  835.     // add .drv extension to the driver name, if necessary 
  836.     len=lstrlen(driver);
  837.     if (len<=4) lstrcat(driver,".drv");
  838.     else {
  839.        lstrcpy(ext,&driver[len-4]);
  840.        if (lstrcmpi(ext,".DRV")!=0) lstrcat(driver,".DRV");
  841.     }
  842.     
  843.     return TRUE;
  844. }
  845.  
  846.  
  847. /******************************************************************************
  848.                              Helper Routines
  849. *******************************************************************************/
  850.  
  851. /******************************************************************************
  852.     HugeMemMove:
  853.     Use this function to move data from one buffer to another when the
  854.     buffer may be larger than 64K.  For buffer smaller than 64K, the
  855.     FarMove function will provide much better performance.
  856. *******************************************************************************/
  857. void HugeMemMove(char huge *src,char huge * dest, UINT count)
  858. {
  859.     UINT i;
  860.  
  861.     for (i=0;i<count;i++) dest[i]=src[i];
  862.     return;
  863. }
  864.  
  865. /******************************************************************************
  866.      AssignIntValue:
  867.      Extract an integer value from the dialog item.  Display error if a non-
  868.      numeric value is encountered and return a false result.
  869. *******************************************************************************/
  870. BOOL AssignIntValue(HWND hWin,int ControlId,LPINT pInt)
  871. {
  872.     BOOL ErrorFlag;
  873.  
  874.     *pInt=GetDlgItemInt(hWin,ControlId,&ErrorFlag,(BOOL) 0);
  875.     if (!ErrorFlag) {
  876.        MessageBox(hWin,"Must Enter a Valid Number",NULL,MB_OK);
  877.        SetFocus(GetDlgItem(hWin,ControlId));
  878.        return (FALSE);
  879.     }
  880.     return TRUE;
  881. }
  882.  
  883. /******************************************************************************
  884.      AssignLongValue:
  885.      Extract a long value from the dialog item.  Display error if a non-
  886.      numeric value is encountered and return a false result.
  887. *******************************************************************************/
  888. BOOL AssignLongValue(HWND hWin,int ControlId,LPLONG pLong)
  889. {
  890.     char string[20];
  891.     int i;
  892.  
  893.     GetDlgItemText(hWin,ControlId,string,sizeof(string)-1);  // get the number
  894.  
  895.     for (i=0;i<strlen(string);i++) {  // check for non numeric characters
  896.         if (string[i]=='-') continue;
  897.         if (string[i]<'0' || string[i]>'9') {
  898.            MessageBox(hWin,"Must Enter a Valid Number",NULL,MB_OK);
  899.            SetFocus(GetDlgItem(hWin,ControlId));
  900.            return (FALSE);
  901.         }
  902.     }
  903.  
  904.     (*pLong)=atol(string);       // convert to long
  905.     
  906.     return TRUE;
  907. }
  908.  
  909. /******************************************************************************
  910.      SetDemoLong:
  911.      Set a long value to a dialog field.
  912. *******************************************************************************/
  913. BOOL SetDemoLong(HWND hDlg,int ControlId,long value)
  914. {
  915.     char string[20];
  916.  
  917.     wsprintf(string,"%ld",value);
  918.     SetDlgItemText(hDlg,ControlId,string);
  919.  
  920.     return TRUE;
  921. }  
  922.  
  923. /******************************************************************************
  924.      GetDemoLong:
  925.      Gety a long value from a dialog field.
  926. *******************************************************************************/
  927. BOOL GetDemoLong(HWND hDlg,int ControlId,long *value)
  928. {
  929.     GetDlgItemText(hDlg,ControlId,DemoLine,19);
  930.     (*value)=atol(DemoLine);
  931.  
  932.     return TRUE;
  933. }  
  934.  
  935. /******************************************************************************
  936.     OurPrintf:
  937.     This routine formats and display a given set of arguments.  The format
  938.     is given by the first argument.  The argument 2 to n contain the
  939.     arguments for the specified format.  The function uses MessageBox to
  940.     display the formatted string.
  941. ******************************************************************************/
  942. int OurPrintf(LPSTR fmt,...)
  943. {
  944.     LPSTR ArgStart;
  945.     char string[MAX_WIDTH+2];
  946.  
  947.     ArgStart=(LPSTR) &fmt;  // pointer to first argument 
  948.     ArgStart=&ArgStart[4];  // go past the first argument 
  949.     wvsprintf(string,fmt,ArgStart);
  950.     if (FindWindow("DBWin",NULL)) { // debug window open
  951.         lstrcat(string,"\n");
  952.         OutputDebugString(string);  // send to the debug terminal
  953.     }
  954.     else MessageBox(NULL,string,NULL,MB_OK);
  955.     return TRUE;
  956. }
  957.  
  958.  
  959. /****************************************************************************
  960.                       DEMO DIALOG PROCEDURES
  961. ****************************************************************************/
  962.  
  963. /****************************************************************************
  964.     Process messages for "DemoOpenDlg" dialog box
  965.     This dialog box accepts the parameters to be passed to TER routine.
  966.     Finally this routines makes a call to TER routine to open a window.
  967. ****************************************************************************/
  968. int CALLBACK _export DemoOpenDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  969. {
  970.     BOOL flag;
  971.  
  972.     switch (message) {
  973.         case WM_INITDIALOG:
  974.             // Set initial values of the parameters
  975.             SetDlgItemInt(hDlg,IDC_X,arg[CurWnd].x,0);
  976.             SetDlgItemInt(hDlg,IDC_Y,arg[CurWnd].y,0);
  977.             SetDlgItemInt(hDlg,IDC_WIDTH,arg[CurWnd].width,0);
  978.             SetDlgItemInt(hDlg,IDC_HEIGHT,arg[CurWnd].height,0);
  979.             SetDemoLong(hDlg,IDC_MAX_LINES,arg[CurWnd].LineLimit);
  980.             SetDemoLong(hDlg,IDC_INIT_LINE,arg[CurWnd].InitLine);
  981.             SendMessage(GetDlgItem(hDlg,IDC_WORD_WRAP),BM_SETCHECK, arg[CurWnd].WordWrap, 0L);
  982.             SendMessage(GetDlgItem(hDlg,IDC_PRINT_VIEW),BM_SETCHECK, arg[CurWnd].PrintView, 0L);
  983.             SendMessage(GetDlgItem(hDlg,IDC_PAGE_MODE),BM_SETCHECK, arg[CurWnd].PageMode, 0L);
  984.             SendMessage(GetDlgItem(hDlg,IDC_RULER),BM_SETCHECK, arg[CurWnd].ruler, 0L);
  985.             SendMessage(GetDlgItem(hDlg,IDC_TOOL_BAR),BM_SETCHECK, arg[CurWnd].ToolBar, 0L);
  986.             if (arg[CurWnd].InputType=='F') flag=FALSE;else flag=TRUE; 
  987.             SendMessage(GetDlgItem(hDlg,IDC_FILE_OPT),BM_SETCHECK, flag, 0L);
  988.             SendMessage(GetDlgItem(hDlg,IDC_STATUS_LINE),BM_SETCHECK, arg[CurWnd].ShowStatus, 0L);
  989.             SendMessage(GetDlgItem(hDlg,IDC_MENU),BM_SETCHECK, arg[CurWnd].ShowMenu, 0L);
  990.             SendMessage(GetDlgItem(hDlg,IDC_VER_BAR),BM_SETCHECK, arg[CurWnd].ShowVerBar, 0L);
  991.             SendMessage(GetDlgItem(hDlg,IDC_HOR_BAR),BM_SETCHECK, arg[CurWnd].ShowHorBar, 0L);
  992.             SendMessage(GetDlgItem(hDlg,IDC_USER_CLOSE),BM_SETCHECK, arg[CurWnd].UserCanClose, 0L);
  993.             SendMessage(GetDlgItem(hDlg,IDC_BORDER),BM_SETCHECK, arg[CurWnd].BorderMargins, 0L);
  994.             SendMessage(GetDlgItem(hDlg,IDC_READ_ONLY),BM_SETCHECK, arg[CurWnd].ReadOnly, 0L);
  995.             SendMessage(GetDlgItem(hDlg,IDC_CHILD),BM_SETCHECK, arg[CurWnd].style&WS_CHILD?TRUE:FALSE, 0L);
  996.  
  997.             strcpy(PrevFile,arg[CurWnd].file);  // store the previous file name 
  998.             SetDlgItemText(hDlg,IDC_FILE_NAME,arg[CurWnd].file);
  999.             
  1000.             // set output file format
  1001.             SendMessage(GetDlgItem(hDlg,IDC_SAVE_DEFAULT),BM_SETCHECK, arg[CurWnd].SaveFormat==SAVE_DEFAULT, 0L);
  1002.             SendMessage(GetDlgItem(hDlg,IDC_SAVE_TER),BM_SETCHECK, arg[CurWnd].SaveFormat==SAVE_TER, 0L);
  1003.             SendMessage(GetDlgItem(hDlg,IDC_SAVE_RTF),BM_SETCHECK, arg[CurWnd].SaveFormat==SAVE_RTF, 0L);
  1004.             SendMessage(GetDlgItem(hDlg,IDC_SAVE_TEXT),BM_SETCHECK, arg[CurWnd].SaveFormat==SAVE_TEXT, 0L);
  1005.             SendMessage(GetDlgItem(hDlg,IDC_SAVE_TEXT_LINES),BM_SETCHECK, arg[CurWnd].SaveFormat==SAVE_TEXT_LINES, 0L);
  1006.             
  1007.             return (TRUE);
  1008.  
  1009.         case WM_COMMAND:
  1010.             switch (wParam) {
  1011.                 case IDOK:
  1012.                    if (!AssignIntValue(hDlg,IDC_X,&arg[CurWnd].x)) return (TRUE);
  1013.                    if (!AssignIntValue(hDlg,IDC_Y,&arg[CurWnd].y)) return (TRUE);
  1014.                    if (!AssignIntValue(hDlg,IDC_WIDTH,&arg[CurWnd].width)) return (TRUE);
  1015.                    if (!AssignIntValue(hDlg,IDC_HEIGHT,&arg[CurWnd].height)) return (TRUE);
  1016.                    if (!AssignLongValue(hDlg,IDC_MAX_LINES,&arg[CurWnd].LineLimit)) return (TRUE);
  1017.                    if (!AssignLongValue(hDlg,IDC_INIT_LINE,&arg[CurWnd].InitLine)) return (TRUE);
  1018.                    arg[CurWnd].WordWrap=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_WORD_WRAP),BM_GETCHECK, 0, 0L);
  1019.                    arg[CurWnd].PrintView=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_PRINT_VIEW),BM_GETCHECK, 0, 0L);
  1020.                    arg[CurWnd].PageMode=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_PAGE_MODE),BM_GETCHECK, 0, 0L);
  1021.                    arg[CurWnd].ruler=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_RULER),BM_GETCHECK, 0, 0L);
  1022.                    arg[CurWnd].ToolBar=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_TOOL_BAR),BM_GETCHECK, 0, 0L);
  1023.                    flag=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_FILE_OPT),BM_GETCHECK, 0, 0L);
  1024.                    if (flag) arg[CurWnd].InputType='B';else arg[CurWnd].InputType='F';
  1025.                    arg[CurWnd].ShowStatus=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_STATUS_LINE),BM_GETCHECK, 0, 0L);
  1026.                    arg[CurWnd].ShowMenu=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_MENU),BM_GETCHECK, 0, 0L);
  1027.                    arg[CurWnd].ShowVerBar=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_VER_BAR),BM_GETCHECK, 0, 0L);
  1028.                    arg[CurWnd].ShowHorBar=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_HOR_BAR),BM_GETCHECK, 0, 0L);
  1029.                    arg[CurWnd].UserCanClose=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_USER_CLOSE),BM_GETCHECK, 0, 0L);
  1030.                    arg[CurWnd].BorderMargins=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_BORDER),BM_GETCHECK, 0, 0L);
  1031.                    arg[CurWnd].ReadOnly=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_READ_ONLY),BM_GETCHECK, 0, 0L);
  1032.  
  1033.                    flag=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_CHILD),BM_GETCHECK, 0, 0L);
  1034.                    if (flag) arg[CurWnd].style=WS_CHILD|WS_THICKFRAME|WS_BORDER|WS_CAPTION|WS_MINIMIZEBOX|WS_MAXIMIZEBOX;
  1035.                    else      arg[CurWnd].style=WS_OVERLAPPEDWINDOW;
  1036.  
  1037.                    GetDlgItemText(hDlg,IDC_FILE_NAME,arg[CurWnd].file,100);
  1038.                    
  1039.                    // get output file format
  1040.                    if      (SendMessage(GetDlgItem(hDlg,IDC_SAVE_DEFAULT),BM_GETCHECK, 0, 0L)) arg[CurWnd].SaveFormat=SAVE_DEFAULT;
  1041.                    else if (SendMessage(GetDlgItem(hDlg,IDC_SAVE_TER),BM_GETCHECK, 0, 0L)) arg[CurWnd].SaveFormat=SAVE_TER;
  1042.                    else if (SendMessage(GetDlgItem(hDlg,IDC_SAVE_RTF),BM_GETCHECK, 0, 0L)) arg[CurWnd].SaveFormat=SAVE_RTF;
  1043.                    else if (SendMessage(GetDlgItem(hDlg,IDC_SAVE_TEXT),BM_GETCHECK, 0, 0L)) arg[CurWnd].SaveFormat=SAVE_TEXT;
  1044.                    else if (SendMessage(GetDlgItem(hDlg,IDC_SAVE_TEXT_LINES),BM_GETCHECK, 0, 0L)) arg[CurWnd].SaveFormat=SAVE_TEXT_LINES;
  1045.                    
  1046.                    EndDialog(hDlg, TRUE);
  1047.                    return (TRUE);
  1048.         
  1049.                 case IDCANCEL:
  1050.                    EndDialog(hDlg, FALSE);
  1051.                    return (TRUE);
  1052.                 default:
  1053.                    ;
  1054.             }
  1055.             break;
  1056.     }
  1057.     return (FALSE);
  1058. }
  1059.  
  1060. /****************************************************************************
  1061.     Process messages for "DemoPrintDlg" dialog box
  1062. ****************************************************************************/
  1063. int FAR PASCAL _export DemoPrintDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1064. {
  1065.     BOOL flag,FullPage,OnePage;
  1066.  
  1067.     switch (message) {
  1068.         case WM_INITDIALOG:
  1069.             // Set the buffer/file option
  1070.             if (prt.InputType=='F') flag=FALSE;else flag=TRUE; 
  1071.             SendMessage(GetDlgItem(hDlg,IDC_FILE_OPT),BM_SETCHECK, flag, 0L);
  1072.             strcpy(PrevFile,prt.file);   // store the previous file name 
  1073.             SetDlgItemText(hDlg,IDC_FILE_NAME,prt.file);
  1074.             
  1075.             // set output device
  1076.             SendMessage(GetDlgItem(hDlg,IDC_DEF_PRINTER), BM_SETCHECK, PrtOutput==IDC_DEF_PRINTER, 0L);
  1077.             SendMessage(GetDlgItem(hDlg,IDC_SPEC_PRINTER),BM_SETCHECK, PrtOutput==IDC_SPEC_PRINTER, 0L);
  1078.             SendMessage(GetDlgItem(hDlg,IDC_SPEC_WINDOW), BM_SETCHECK, PrtOutput==IDC_SPEC_WINDOW, 0L);
  1079.  
  1080.             // set printing area parameters
  1081.             SetDlgItemInt(hDlg,IDC_X,PrtRect.left,0);
  1082.             SetDlgItemInt(hDlg,IDC_Y,PrtRect.top,0);
  1083.             SetDlgItemInt(hDlg,IDC_WIDTH,PrtRect.right-PrtRect.left,0);
  1084.             SetDlgItemInt(hDlg,IDC_HEIGHT,PrtRect.bottom-PrtRect.top,0);
  1085.             if (PrtOutput==IDC_SPEC_WINDOW) prt.rect=NULL;  // full window by default
  1086.             if (prt.rect==NULL) {
  1087.                SendMessage(GetDlgItem(hDlg,IDC_FULL_PAGE),BM_SETCHECK, TRUE, 0L);
  1088.                EnableWindow(GetDlgItem(hDlg,IDC_X),FALSE);       // disable
  1089.                EnableWindow(GetDlgItem(hDlg,IDC_Y),FALSE);       // disable
  1090.                EnableWindow(GetDlgItem(hDlg,IDC_WIDTH),FALSE);   // disable
  1091.                EnableWindow(GetDlgItem(hDlg,IDC_HEIGHT),FALSE);  // disable
  1092.             }
  1093.             
  1094.             // set other variables
  1095.             SetDemoLong(hDlg,IDC_START_POS,prt.StartPos);
  1096.             SendMessage(GetDlgItem(hDlg,IDC_ONE_PAGE),BM_SETCHECK, prt.OnePage, 0L);
  1097.  
  1098.             return (TRUE);
  1099.  
  1100.         case WM_COMMAND:
  1101.             switch (wParam) {
  1102.                 case IDC_SPEC_WINDOW:      // print to a specified window
  1103.                    SendMessage(GetDlgItem(hDlg,IDC_FULL_PAGE),BM_SETCHECK, TRUE, 0L);   // full page by default
  1104.  
  1105.                 case IDC_FULL_PAGE:
  1106.                    FullPage=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_FULL_PAGE),BM_GETCHECK, 0, 0L);
  1107.                    EnableWindow(GetDlgItem(hDlg,IDC_X),!FullPage);
  1108.                    EnableWindow(GetDlgItem(hDlg,IDC_Y),!FullPage);
  1109.                    EnableWindow(GetDlgItem(hDlg,IDC_WIDTH),!FullPage);
  1110.                    EnableWindow(GetDlgItem(hDlg,IDC_HEIGHT),!FullPage);
  1111.                    break;
  1112.  
  1113.                 case IDOK:
  1114.                    if (!AssignLongValue(hDlg,IDC_START_POS,&(prt.StartPos))) return (TRUE);
  1115.  
  1116.                    FullPage=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_FULL_PAGE),BM_GETCHECK, 0, 0L);
  1117.                    if (FullPage) prt.rect=NULL;
  1118.                    else {
  1119.                       prt.rect=&PrtRect;       // pointer to the printing area rectangle
  1120.                       if (!AssignIntValue(hDlg,IDC_X,(LPINT)&PrtRect.left)) return (TRUE);
  1121.                       if (!AssignIntValue(hDlg,IDC_Y,(LPINT)&PrtRect.top)) return (TRUE);
  1122.                       if (!AssignIntValue(hDlg,IDC_WIDTH,(LPINT)&PrtRect.right)) return (TRUE);
  1123.                       if (!AssignIntValue(hDlg,IDC_HEIGHT,(LPINT)&PrtRect.bottom)) return (TRUE);
  1124.                       PrtRect.right+=PrtRect.left;  // convert width to right coordinate
  1125.                       PrtRect.bottom+=PrtRect.top;  // convert height to bottom coordinate
  1126.                    }
  1127.  
  1128.                    flag=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_FILE_OPT),BM_GETCHECK, 0, 0L);
  1129.                    if (flag) prt.InputType='B';else prt.InputType='F';
  1130.                    GetDlgItemText(hDlg,IDC_FILE_NAME,prt.file,100);
  1131.  
  1132.                    // get output device;
  1133.                    if ((BOOL) SendMessage(GetDlgItem(hDlg,IDC_DEF_PRINTER),BM_GETCHECK,0,0L)) PrtOutput=IDC_DEF_PRINTER;
  1134.                    if ((BOOL) SendMessage(GetDlgItem(hDlg,IDC_SPEC_PRINTER),BM_GETCHECK,0,0L)) PrtOutput=IDC_SPEC_PRINTER;
  1135.                    if ((BOOL) SendMessage(GetDlgItem(hDlg,IDC_SPEC_WINDOW),BM_GETCHECK,0,0L)) PrtOutput=IDC_SPEC_WINDOW;
  1136.  
  1137.                    prt.OnePage=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_ONE_PAGE),BM_GETCHECK, 0, 0L);
  1138.                    
  1139.                    // set the rectangle when printing to the window
  1140.                    if (PrtOutput==IDC_SPEC_WINDOW && prt.rect==NULL) {// print to the demo window
  1141.                       prt.rect=&PrtRect;  // always specify the rectanble
  1142.                       GetClientRect(hDemoWnd,&PrtRect);  // print to entire client area
  1143.                       // convert from pixel units to mm units
  1144.                       PrtRect.left=PixelToMmX(PrtRect.left);
  1145.                       PrtRect.right=PixelToMmX(PrtRect.right);
  1146.                       PrtRect.top=PixelToMmY(PrtRect.top);
  1147.                       PrtRect.bottom=PixelToMmY(PrtRect.bottom);
  1148.                    }
  1149.  
  1150.                    EndDialog(hDlg, TRUE);
  1151.                    return (TRUE);
  1152.         
  1153.                 case IDCANCEL:
  1154.                    EndDialog(hDlg, FALSE);
  1155.                    return (TRUE);
  1156.                 default:
  1157.                    ;
  1158.             }
  1159.             break;
  1160.     }
  1161.     return (FALSE);
  1162. }
  1163.  
  1164. /****************************************************************************
  1165.     DemoCloseDlg:
  1166.     This dialog box allows you to select a TER window to close. The index
  1167.     of the selected window is returned.
  1168. ****************************************************************************/
  1169. int FAR PASCAL _export DemoCloseDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1170. {
  1171.     int i,j;
  1172.     char string[64];
  1173.  
  1174.     switch (message) {
  1175.         case WM_INITDIALOG:
  1176.             // insert the open file names in the dialog box 
  1177.             for (i=0;i<MAX_WINDS;i++) {
  1178.                if (arg[i].open) {
  1179.                   if (arg[i].file[0]==0) SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_ADDSTRING, 0, (DWORD)(LPSTR)"UNNAMED");
  1180.                   else                   SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_ADDSTRING, 0, (DWORD)(LPSTR)arg[i].file);
  1181.                }
  1182.             }
  1183.             SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_SETCURSEL, 0,0L);
  1184.             SetFocus(GetDlgItem(hDlg,IDC_BOX));
  1185.             return (FALSE);
  1186.  
  1187.         case WM_COMMAND:
  1188.             switch (wParam) {
  1189.                 case IDC_BOX:
  1190.                     if (HIWORD(lParam)!=LBN_DBLCLK) break;
  1191.  
  1192.                 case IDOK:
  1193.                    j=(int)SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_GETCURSEL, 0,0L);
  1194.                    SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_GETTEXT, j,(DWORD)(LPSTR)string);
  1195.                    if (lstrcmp(string,"UNNAMED")==0) string[0]=0;
  1196.                    for (i=0;i<MAX_WINDS;i++) {
  1197.                       if (arg[i].open && lstrcmp(arg[i].file,string)==0) {
  1198.                         EndDialog(hDlg, i);
  1199.                         return (TRUE);
  1200.                       }
  1201.                    }
  1202.                    EndDialog(hDlg, -1);
  1203.                    return (TRUE);
  1204.         
  1205.                 case IDCANCEL:
  1206.                    EndDialog(hDlg, -1);
  1207.                    return (TRUE);
  1208.                 default:
  1209.                    ;
  1210.             }
  1211.             break;
  1212.     }
  1213.     return (FALSE);
  1214. }
  1215.  
  1216. /****************************************************************************
  1217.     DemoResetDlg:
  1218.     This dialog box allows you to select a TER window to be reset.  The
  1219.     reset example is meant to demonstrate the use of the 'SetTerBuffer'
  1220.     function.
  1221. ****************************************************************************/
  1222.  
  1223. int FAR PASCAL _export DemoResetDlg(HWND hDlg, UINT message,WPARAM wParam,LPARAM lParam)
  1224. {
  1225.     int i,j;
  1226.     char string[64];
  1227.  
  1228.     switch (message) {
  1229.         case WM_INITDIALOG:
  1230.             // insert the open file names in the dialog box 
  1231.             for (i=0;i<MAX_WINDS;i++) {
  1232.                if (arg[i].open) {
  1233.                   if (arg[i].file[0]==0) SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_ADDSTRING, 0, (DWORD)(LPSTR)"UNNAMED");     // file name not provided 
  1234.                   else                   SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_ADDSTRING, 0, (DWORD)(LPSTR)arg[i].file);
  1235.                }
  1236.             }
  1237.             SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_SETCURSEL, 0,0L);
  1238.             SetFocus(GetDlgItem(hDlg,IDC_BOX));
  1239.             return (FALSE);
  1240.  
  1241.         case WM_COMMAND:
  1242.             switch (wParam) {
  1243.                 case IDC_BOX:
  1244.                     if (HIWORD(lParam)!=LBN_DBLCLK) break;
  1245.  
  1246.                 case IDOK:
  1247.                    j=(int)SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_GETCURSEL, 0,0L);
  1248.                    SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_GETTEXT, j,(DWORD)(LPSTR)string);
  1249.                    if (lstrcmp(string,"UNNAMED")==0) string[0]=0;
  1250.                    for (i=0;i<MAX_WINDS;i++) {
  1251.                       if (arg[i].open && lstrcmp(arg[i].file,string)==0) {
  1252.                         if (arg[i].InputType!='B') {
  1253.                             MessageBox(hDlg,"File Type Window Can Not be Refreshed!",NULL,MB_OK);
  1254.                             return (TRUE);
  1255.                         }
  1256.                         EndDialog(hDlg, i);
  1257.                         return (TRUE);
  1258.                       }
  1259.                    }
  1260.                    EndDialog(hDlg, -1);
  1261.                    return (TRUE);
  1262.         
  1263.                 case IDCANCEL:
  1264.                    EndDialog(hDlg, -1);
  1265.                    return (TRUE);
  1266.                 default:
  1267.                    ;
  1268.             }
  1269.             break;
  1270.     }
  1271.     return (FALSE);
  1272. }
  1273.  
  1274. /****************************************************************************
  1275.     DemoSelectWin:
  1276.     This dialog box allows you to select a TER window.
  1277. ****************************************************************************/
  1278. int FAR PASCAL _export DemoSelectWin(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1279. {
  1280.     int i,j;
  1281.     char string[64];
  1282.  
  1283.     switch (message) {
  1284.         case WM_INITDIALOG:
  1285.             // insert the open file names in the dialog box 
  1286.             for (i=0;i<MAX_WINDS;i++) {
  1287.                if (arg[i].open) {
  1288.                   if (arg[i].file[0]==0) SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_ADDSTRING, 0, (DWORD)(LPSTR)"UNNAMED");
  1289.                   else                   SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_ADDSTRING, 0, (DWORD)(LPSTR)arg[i].file);
  1290.                }
  1291.             }
  1292.             SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_SETCURSEL, 0,0L);
  1293.             SetFocus(GetDlgItem(hDlg,IDC_BOX));
  1294.             return (FALSE);
  1295.  
  1296.         case WM_COMMAND:
  1297.             switch (wParam) {
  1298.                 case IDC_BOX:
  1299.                     if (HIWORD(lParam)!=LBN_DBLCLK) break;
  1300.  
  1301.                 case IDOK:
  1302.                    j=(int)SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_GETCURSEL, 0,0L);
  1303.                    SendMessage(GetDlgItem(hDlg,IDC_BOX),LB_GETTEXT, j,(DWORD)(LPSTR)string);
  1304.                    if (lstrcmp(string,"UNNAMED")==0) string[0]=0;
  1305.                    for (i=0;i<MAX_WINDS;i++) {
  1306.                       if (arg[i].open && lstrcmp(arg[i].file,string)==0) {
  1307.                         EndDialog(hDlg, i);
  1308.                         return (TRUE);
  1309.                       }
  1310.                    }
  1311.                    EndDialog(hDlg, -1);
  1312.                    return (TRUE);
  1313.         
  1314.                 case IDCANCEL:
  1315.                    EndDialog(hDlg, -1);
  1316.                    return (TRUE);
  1317.                 default:
  1318.                    ;
  1319.             }
  1320.             break;
  1321.     }
  1322.     return (FALSE);
  1323. }
  1324.  
  1325. /****************************************************************************
  1326.     DemoFields:
  1327.     This dialog box shows the internal variables for the current window, and
  1328.     let to modify them.
  1329. ****************************************************************************/
  1330. int FAR PASCAL _export DemoFields(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1331. {
  1332.     int i,j;
  1333.  
  1334.     switch (message) {
  1335.         case WM_INITDIALOG:
  1336.             // Set read/write dialog fields 
  1337.                              // Position variables 
  1338.             SetDemoLong(hDlg,IDC_CUR_ROW,field.CurRowW);
  1339.             SetDlgItemInt(hDlg,IDC_CUR_COL,field.CurColW,0);
  1340.             SetDemoLong(hDlg,IDC_CUR_LINE,field.CurLineW);
  1341.             SetDemoLong(hDlg,IDC_BEGIN_LINE,field.BeginLineW);
  1342.  
  1343.                              // Color variables 
  1344.             SetDemoLong(hDlg,IDC_TEXT_BK_COLOR,(long)field.TextBkColorW);
  1345.             SetDemoLong(hDlg,IDC_STATUS_COLOR,(long)field.StatusColorW);
  1346.             SetDemoLong(hDlg,IDC_STATUS_BK_COLOR,(long)field.StatusBkColorW);
  1347.             SetDemoLong(hDlg,IDC_LINK_COLOR,(long)field.LinkColorW);
  1348.             SendDlgItemMessage(hDlg,IDC_MODIFY_PROTECT_COLOR, BM_SETCHECK, field.ModifyProtectColorW, 0L);
  1349.             
  1350.                              // Highlight variables 
  1351.             if (field.HilightTypeW==HILIGHT_OFF)  SendMessage(GetDlgItem(hDlg,IDC_HILIGHT_TYPE_OFF), BM_SETCHECK, TRUE, 0L);
  1352.             if (field.HilightTypeW==HILIGHT_LINE) SendMessage(GetDlgItem(hDlg,IDC_HILIGHT_TYPE_LINE),BM_SETCHECK, TRUE, 0L);
  1353.             if (field.HilightTypeW==HILIGHT_CHAR) SendMessage(GetDlgItem(hDlg,IDC_HILIGHT_TYPE_CHAR),BM_SETCHECK, TRUE, 0L);
  1354.             SetDemoLong(hDlg,IDC_HILIGHT_BEG_ROW,field.HilightBegRowW);
  1355.             SetDemoLong(hDlg,IDC_HILIGHT_END_ROW,field.HilightEndRowW);
  1356.             SetDlgItemInt(hDlg,IDC_HILIGHT_BEG_COL,field.HilightBegColW,0);
  1357.             SetDlgItemInt(hDlg,IDC_HILIGHT_END_COL,field.HilightEndColW,0);
  1358.             SendMessage(GetDlgItem(hDlg,IDC_STRETCH_HILIGHT),BM_SETCHECK, field.StretchHilightW, 0L);
  1359.  
  1360.                              // Text data variables 
  1361.             SetDlgItemText(hDlg,IDC_TEXT,field.text);
  1362.             SetDlgItemInt(hDlg,IDC_LINE_LEN,field.LineLenW,0);
  1363.             SetDlgItemInt(hDlg,IDC_PFMT,(int)field.pfmtW,0);
  1364.             if (field.TextApply==APPLY_IGNORE)        SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_IGNORE),BM_SETCHECK, TRUE, 0L);
  1365.             if (field.TextApply==APPLY_MOD_CUR_LINE)  SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_CUR),BM_SETCHECK, TRUE, 0L);
  1366.             if (field.TextApply==APPLY_BEF_CUR_LINE)  SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_BEF),BM_SETCHECK, TRUE, 0L);
  1367.             if (field.TextApply==APPLY_AFT_CUR_LINE)  SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_AFT),BM_SETCHECK, TRUE, 0L);
  1368.  
  1369.                               //* Paint/wrapping and other flag 
  1370.             SendMessage(GetDlgItem(hDlg,IDC_PAINT_ENABLED),BM_SETCHECK, field.PaintEnabledW, 0L);
  1371.             SendMessage(GetDlgItem(hDlg,IDC_WRAP),BM_SETCHECK, field.WrapFlagW!=WRAP_OFF, 0L);
  1372.             SendMessage(GetDlgItem(hDlg,IDC_LINK_DBL_CLICK),BM_SETCHECK, field.LinkDblClickW, 0L);
  1373.             SendMessage(GetDlgItem(hDlg,IDC_SHOW_PROTECT_CARET),BM_SETCHECK, field.ShowProtectCaretW, 0L);
  1374.             SetDlgItemInt(hDlg,IDC_LINK_STYLE,field.LinkStyleW,0);
  1375.  
  1376.             // Set read Only dialog fields 
  1377.             SetDemoLong(hDlg,IDC_TOTAL_LINES,field.TotalLinesW);
  1378.             SetDlgItemInt(hDlg,IDC_TOTAL_PFMTS,field.TotalPfmtsW,0);
  1379.             SetDlgItemInt(hDlg,IDC_TOTAL_FONTS,field.TotalFontsW,0);
  1380.             SendMessage(GetDlgItem(hDlg,IDC_MODIFIED),BM_SETCHECK, field.modified, 0L);
  1381.  
  1382.             SetFocus(GetDlgItem(hDlg,IDCANCEL));
  1383.             return (FALSE);
  1384.  
  1385.         case WM_COMMAND:
  1386.             switch (wParam) {
  1387.                 case IDOK:
  1388.                    // retrieve dialog fields 
  1389.                                     // Position variables 
  1390.                    if (!AssignLongValue(hDlg,IDC_CUR_ROW,&field.CurRowW)) return TRUE;
  1391.                    if (!AssignIntValue(hDlg,IDC_CUR_COL,&field.CurColW)) return TRUE;
  1392.                    if (!AssignLongValue(hDlg,IDC_CUR_LINE,&field.CurLineW)) return TRUE;
  1393.                    if (!AssignLongValue(hDlg,IDC_BEGIN_LINE,&field.BeginLineW)) return TRUE;
  1394.  
  1395.                                     // Color variables 
  1396.                    GetDemoLong(hDlg,IDC_TEXT_BK_COLOR,(long *)&field.TextBkColorW);
  1397.                    GetDemoLong(hDlg,IDC_STATUS_COLOR,(long *)&field.StatusColorW);
  1398.                    GetDemoLong(hDlg,IDC_STATUS_BK_COLOR,(long *)&field.StatusBkColorW);
  1399.                    GetDemoLong(hDlg,IDC_LINK_COLOR,(long *)&(field.LinkColorW));
  1400.                    field.ModifyProtectColorW=(BOOL)SendDlgItemMessage(hDlg,IDC_MODIFY_PROTECT_COLOR,BM_GETCHECK, 0, 0L);
  1401.                    
  1402.                                     // Highlight variables 
  1403.                    field.HilightTypeW=HILIGHT_OFF;
  1404.                    if (SendMessage(GetDlgItem(hDlg,IDC_HILIGHT_TYPE_LINE),BM_GETCHECK, 0, 0L)) field.HilightTypeW=HILIGHT_LINE;
  1405.                    if (SendMessage(GetDlgItem(hDlg,IDC_HILIGHT_TYPE_CHAR),BM_GETCHECK, 0, 0L)) field.HilightTypeW=HILIGHT_CHAR;
  1406.                    if (!AssignLongValue(hDlg,IDC_HILIGHT_BEG_ROW,&field.HilightBegRowW)) return TRUE;
  1407.                    if (!AssignLongValue(hDlg,IDC_HILIGHT_END_ROW,&field.HilightEndRowW)) return TRUE;
  1408.                    if (!AssignIntValue(hDlg,IDC_HILIGHT_BEG_COL,&field.HilightBegColW)) return TRUE;
  1409.                    if (!AssignIntValue(hDlg,IDC_HILIGHT_END_COL,&field.HilightEndColW)) return TRUE;
  1410.                    field.StretchHilightW=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_STRETCH_HILIGHT),BM_GETCHECK, 0, 0L);
  1411.  
  1412.                                     // Text data variables 
  1413.                    GetDlgItemText(hDlg,IDC_TEXT,field.text,MAX_WIDTH);
  1414.                    field.LineLenW=strlen(field.text);
  1415.                    
  1416.                    if (!AssignIntValue(hDlg,IDC_PFMT,&i)) return TRUE;
  1417.                    field.pfmtW=(BYTE)i;
  1418.  
  1419.                    field.TextApply=APPLY_IGNORE;
  1420.                    if (SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_CUR),BM_GETCHECK, 0, 0L)) field.TextApply=APPLY_MOD_CUR_LINE;
  1421.                    if (SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_BEF),BM_GETCHECK, 0, 0L)) field.TextApply=APPLY_BEF_CUR_LINE;
  1422.                    if (SendMessage(GetDlgItem(hDlg,IDC_TEXT_APPLY_AFT),BM_GETCHECK, 0, 0L)) field.TextApply=APPLY_AFT_CUR_LINE;
  1423.  
  1424.                                      // Paint enable and other flag 
  1425.                    field.PaintEnabledW=(BOOL)SendMessage(GetDlgItem(hDlg,IDC_PAINT_ENABLED),BM_GETCHECK, 0, 0L);
  1426.                    if (SendMessage(GetDlgItem(hDlg,IDC_WRAP),BM_GETCHECK, 0, 0L)) 
  1427.                         field.WrapFlagW=WRAP_WIN;
  1428.                    else field.WrapFlagW=WRAP_OFF;
  1429.                    field.LinkDblClickW=(BOOL)SendDlgItemMessage(hDlg,IDC_LINK_DBL_CLICK,BM_GETCHECK, 0, 0L);
  1430.                    field.ShowProtectCaretW=(BOOL)SendDlgItemMessage(hDlg,IDC_SHOW_PROTECT_CARET,BM_GETCHECK, 0, 0L);
  1431.  
  1432.                    if (!AssignIntValue(hDlg,IDC_LINK_STYLE,&(field.LinkStyleW))) return TRUE;
  1433.  
  1434.                    EndDialog(hDlg, TRUE);
  1435.                    return (TRUE);
  1436.         
  1437.                 case IDCANCEL:
  1438.                    EndDialog(hDlg, FALSE);
  1439.                    return (TRUE);
  1440.                 default:
  1441.                    ;
  1442.             }
  1443.             break;
  1444.     }
  1445.     return (FALSE);
  1446. }
  1447.  
  1448. /****************************************************************************
  1449.     DemoInsertText:
  1450.     This dialog box accepts text (with attributes) to insert into the
  1451.     chosen TER window.
  1452. ****************************************************************************/
  1453. int FAR PASCAL _export DemoInsertText(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1454. {
  1455.     int i,j;
  1456.  
  1457.     switch (message) {
  1458.         case WM_INITDIALOG:
  1459.             // set current row/col 
  1460.             GetTerCursorPos(arg[CurWnd].hTextWnd,&CurLine,&CurCol);
  1461.             SetDemoLong(hDlg,IDC_INSERT_LINE,CurLine);
  1462.             SetDlgItemInt(hDlg,IDC_INSERT_COL,CurCol,0);
  1463.  
  1464.             SetFocus(GetDlgItem(hDlg,IDC_INSERT_TEXT));
  1465.             return (FALSE);
  1466.  
  1467.         case WM_COMMAND:
  1468.             switch (wParam) {
  1469.                 case IDC_INSERT_FONT:
  1470.                    EditFont(hDlg);
  1471.                    break;
  1472.  
  1473.                 case IDOK:
  1474.                    if (!AssignLongValue(hDlg,IDC_INSERT_LINE,&CurLine)) return TRUE;
  1475.                     if (!AssignIntValue(hDlg,IDC_INSERT_COL,&CurCol)) return TRUE;
  1476.                    GetDlgItemText(hDlg,IDC_INSERT_TEXT,NewText,2*MAX_WIDTH);
  1477.                    NewText[2*MAX_WIDTH]=0;
  1478.  
  1479.                    EndDialog(hDlg, TRUE);
  1480.                    return (TRUE);
  1481.         
  1482.                 case IDCANCEL:
  1483.                    EndDialog(hDlg, FALSE);
  1484.                    return (TRUE);
  1485.                 default:
  1486.                    ;
  1487.             }
  1488.             break;
  1489.     }
  1490.     return (FALSE);
  1491. }
  1492.  
  1493. /****************************************************************************
  1494.     DemoSearchDlg:
  1495.     This dialog box accepts the parameters for the search/replace api
  1496. ****************************************************************************/
  1497. int FAR PASCAL _export DemoSearchDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1498. {
  1499.     int i,j;
  1500.     BOOL result;
  1501.  
  1502.     switch (message) {
  1503.         case WM_INITDIALOG:
  1504.             // set current values
  1505.             SetDlgItemText(hDlg,IDC_SEARCH,search);
  1506.             SetDlgItemText(hDlg,IDC_REPLACE,replace);
  1507.  
  1508.             SendDlgItemMessage(hDlg,IDC_FLAG_SCROLL,BM_SETCHECK, SearchFlags&SRCH_SCROLL, 0L);
  1509.             SendDlgItemMessage(hDlg,IDC_FLAG_SEARCH,BM_SETCHECK, SearchFlags&SRCH_SEARCH, 0L);
  1510.             SendDlgItemMessage(hDlg,IDC_FLAG_REPLACE,BM_SETCHECK, SearchFlags&SRCH_REPLACE, 0L);
  1511.             SendDlgItemMessage(hDlg,IDC_FLAG_RETRIEVE,BM_SETCHECK, SearchFlags&SRCH_RETRIEVE, 0L);
  1512.             SendDlgItemMessage(hDlg,IDC_FLAG_CASE,BM_SETCHECK, SearchFlags&SRCH_CASE, 0L);
  1513.             SendDlgItemMessage(hDlg,IDC_FLAG_WORD,BM_SETCHECK, SearchFlags&SRCH_WORD, 0L);
  1514.  
  1515.             SetDemoLong(hDlg,IDC_POS_CUR,SearchCurPos);
  1516.             SetDemoLong(hDlg,IDC_POS_END,SearchEndPos);
  1517.             SetDemoLong(hDlg,IDC_SEARCH_SIZE,SearchSize);
  1518.  
  1519.             SetFocus(GetDlgItem(hDlg,IDCANCEL));
  1520.  
  1521.             return (FALSE);
  1522.  
  1523.         case WM_COMMAND:
  1524.             switch (wParam) {
  1525.  
  1526.                 case IDOK:
  1527.                    // retrieve the updated values
  1528.                    GetDlgItemText(hDlg,IDC_SEARCH,search,sizeof(search)-1);
  1529.                    GetDlgItemText(hDlg,IDC_REPLACE,replace,sizeof(replace)-1);
  1530.  
  1531.                    SearchFlags=0;
  1532.                    if ((BOOL)SendDlgItemMessage(hDlg,IDC_FLAG_SCROLL,BM_GETCHECK, 0, 0L)) SearchFlags|=SRCH_SCROLL;
  1533.                    if ((BOOL)SendDlgItemMessage(hDlg,IDC_FLAG_SEARCH,BM_GETCHECK, 0, 0L)) SearchFlags|=SRCH_SEARCH;
  1534.                    if ((BOOL)SendDlgItemMessage(hDlg,IDC_FLAG_REPLACE,BM_GETCHECK, 0, 0L)) SearchFlags|=SRCH_REPLACE;
  1535.                    if ((BOOL)SendDlgItemMessage(hDlg,IDC_FLAG_RETRIEVE,BM_GETCHECK, 0, 0L)) SearchFlags|=SRCH_RETRIEVE;
  1536.                    if ((BOOL)SendDlgItemMessage(hDlg,IDC_FLAG_CASE,BM_GETCHECK, 0, 0L)) SearchFlags|=SRCH_CASE;
  1537.                    if ((BOOL)SendDlgItemMessage(hDlg,IDC_FLAG_WORD,BM_GETCHECK, 0, 0L)) SearchFlags|=SRCH_WORD;
  1538.  
  1539.                    if (!AssignLongValue(hDlg,IDC_POS_CUR,&SearchCurPos)) return TRUE;
  1540.                    if (!AssignLongValue(hDlg,IDC_POS_END,&SearchEndPos)) return TRUE;
  1541.                    if (!AssignLongValue(hDlg,IDC_SEARCH_SIZE,&SearchSize)) return TRUE;
  1542.  
  1543.                    // make the API call
  1544.                    result=TerSearchReplace(arg[CurWnd].hTextWnd,search,replace,SearchFlags,SearchCurPos,&SearchEndPos,&SearchSize);
  1545.  
  1546.                    if (result) SetDlgItemText(hDlg,IDC_RESULT,"True");
  1547.                    else        SetDlgItemText(hDlg,IDC_RESULT,"False");
  1548.  
  1549.                    // redisplay the updated values
  1550.                    DemoSearchDlg(hDlg,WM_INITDIALOG,0,0L);
  1551.  
  1552.                    break;
  1553.         
  1554.                 case IDCANCEL:
  1555.                    EndDialog(hDlg, FALSE);
  1556.                    return (TRUE);
  1557.                 default:
  1558.                    ;
  1559.             }
  1560.             break;
  1561.     }
  1562.     return (FALSE);
  1563. }
  1564.  
  1565.