home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / WIN_NT / WINNER.ZIP / WINNER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-27  |  31.9 KB  |  895 lines

  1.  
  2. /*        Winner        version 1.07.07        for Windows NT     3/28/93        */
  3.  
  4. #include "windows.h"
  5. #include "drivinit.h"
  6. #include "winner.h"
  7. #include "commdlg.h"
  8. #include "io.h"
  9. #include "shellapi.h"
  10. #include "stdio.h"
  11. #include "string.h"
  12. #include <sys\types.h>
  13. #include <sys\stat.h>
  14.  
  15. FARPROC lpAbortDlg, lpAbortProc;
  16.  
  17. CHOOSEFONT cf;
  18. LOGFONT lf;
  19. OFSTRUCT OfStruct;
  20. OPENFILENAME ofn;
  21. PAINTSTRUCT ps;
  22. PLOGFONT plf;
  23. PRINTDLG pd;
  24. RECT Rect;
  25. TEXTMETRIC TextMetric;
  26. HANDLE hAccTable;
  27. HANDLE hEditBuffer;
  28. HANDLE hNewFile;
  29. HANDLE hHourGlass;
  30. HANDLE hInst;
  31. HANDLE hNewBuffer;
  32. HANDLE hOldBuffer;
  33. HANDLE hPrevRunning;
  34. HANDLE hSaveCursor;
  35. HANDLE hShell;
  36. HBRUSH hBkBrush;
  37. HDC hDC;
  38. HDC GetPrinterDC ( void );
  39. HDC hPr;
  40. HFONT hFont;
  41. HFONT hgFont;
  42. HFONT hgWndFont;
  43. HMENU hMenu;
  44. HPEN hPen;
  45. HWND hAbortDlgWnd;
  46. HWND hBtOpenWnd;
  47. HWND hBtOpen2Wnd;
  48. HWND hBtSaveWnd;
  49. HWND hBtSaveasWnd;
  50. HWND hBtDeleteWnd;
  51. HWND hBtPrintWnd;
  52. HWND hBtTypeWnd;
  53. HWND hBtExitWnd;
  54. HWND hBtUndoWnd;
  55. HWND hBtCutWnd;
  56. HWND hBtCopyWnd;
  57. HWND hBtPasteWnd;
  58. HWND hBtClearWnd;
  59. HWND hBtSelaWnd;
  60. HWND hBtFindWnd;
  61. HWND hBtNextWnd;
  62. HWND hBtPrevWnd;
  63. HWND hBtReplWnd;
  64. HWND hBtReplaWnd;
  65. HWND hBtCmplWnd;
  66. HWND hBtBuildWnd;
  67. HWND hBtBuildallWnd;
  68. HWND hBtCleanWnd;
  69. HWND hBtRunWnd;
  70. HWND hBtChelpWnd;
  71. HWND hBtWhelpWnd;
  72. HWND hEditWnd;
  73. HWND hwnd;
  74. BOOL bAbort;
  75. BOOL bButCut = FALSE;
  76. BOOL fCase       = FALSE;
  77. BOOL bChanges = FALSE;
  78. BOOL bSaveEnabled = FALSE;
  79. BOOL bSearchin=FALSE;
  80. DWORD dwEnd;
  81. DWORD dwResults;
  82. DWORD dwLineCount;
  83. DWORD dwStart;
  84. DWORD dwStyle;
  85. DWORD dwStyleEx;
  86. DWORD dwTextColor;
  87. LPSTR lpstrPointer;
  88. PSTR pBuffer;
  89. PSTR pEditBuffer;
  90. WORD wIndex;
  91. WORD wLines;
  92. WORD TabSpacing = 8;
  93. UINT idMenu;
  94. char szBaseWindowTitle[ ] = "Winner";
  95. char szEmptyString[ ] = "";
  96. char szFFileName[MAXFILENAME];
  97. char szFileName[MAXFILENAME] = "";
  98. char szFileTitle[MAXFILENAME];
  99. char szFilterSpec[128] = "All Files (*.*)\0*.*\0Executable (*.EXE)\0*.EXE\0Text Files (*.TXT)\0*.TXT\0";
  100. char szLine[128];
  101. char szRepl[160] = "";
  102. char szSearch[160] = "";
  103. char szTemp[128];
  104. char Untitled[ ] = "Winner - ( untitled )";
  105. char szWindowTitle[80];
  106. char szRepl[ ];
  107. int Count;
  108. int CurrentLine;
  109. int EX = 0;
  110. int EY = 0;
  111. int EW= 640;
  112. int EH= 400;
  113. int hFile;
  114. int Heigth;
  115. int LineLength;
  116. int LinesPerPage;
  117. int LineSpace;
  118. int Response;
  119. int nTabs[1] = {34};
  120. int Width = 0;
  121. struct stat FileStatus;
  122.  
  123. int PASCAL WinMain ( hInstance, hPrevInstance, lpCmdLine, nCmdShow )
  124. HANDLE hInstance;
  125. HANDLE hPrevInstance;
  126. LPSTR lpCmdLine;
  127. int nCmdShow;
  128. {    MSG msg;
  129.     RECT Rect;
  130.     hPrevRunning = FindWindow("WinnerWClass", NULL);
  131.     if ( !hPrevInstance ) {
  132.         WNDCLASS    wc;
  133.         wc.style = 0;
  134.         wc.lpfnWndProc = MainWndProc;
  135.         wc.cbClsExtra = 0;
  136.         wc.cbWndExtra = 0;
  137.         wc.hInstance = hInstance;
  138.         wc.hIcon = LoadIcon ( hInstance,"Icon" );
  139.         wc.hCursor = LoadCursor ( NULL, IDC_ARROW );
  140.         wc.hbrBackground = GetStockObject ( LTGRAY_BRUSH );
  141.         wc.lpszMenuName = "WinnerMenu";
  142.         wc.lpszClassName = "WinnerWClass";
  143.         if (!RegisterClass ( &wc ) )
  144.             return ( FALSE ) ; }
  145.     if(hPrevRunning) {
  146.         dwTextColor = RGB(0, 0, 128);
  147.         EX = 50 ;
  148.         EY = 25 ; }
  149.     lstrcpy ( (LPSTR)&szFileName,  lpCmdLine ) ;
  150.     if(!lstrcmpi( (LPSTR)&szFileName, "buildres.ult\0")){
  151.         dwTextColor = RGB(128, 0, 0);
  152.         EX=0;
  153.         EY=200;
  154.         EH=280;}
  155.     hInst = hInstance ;
  156.     hAccTable = LoadAccelerators ( hInst, "WinnerAcc" ) ;
  157.     dwStyle = WS_OVERLAPPEDWINDOW ;
  158.     hwnd = CreateWindow ( "WinnerWClass", szBaseWindowTitle, dwStyle, EX, EY, EW-EX, EH, NULL, NULL, hInstance, NULL ) ;
  159.     if ( !hwnd )
  160.         return ( FALSE) ;
  161.     dwStyle = WS_CHILD|WS_VISIBLE|ES_MULTILINE|WS_VSCROLL|ES_AUTOVSCROLL|ES_NOHIDESEL|WS_HSCROLL|ES_AUTOHSCROLL;
  162.     if(GetAsyncKeyState(VK_CONTROL)<0)
  163.         dwStyle = WS_CHILD|WS_VISIBLE|ES_MULTILINE|WS_VSCROLL|ES_AUTOVSCROLL|ES_NOHIDESEL;
  164.     dwStyleEx = WS_EX_TOPMOST ;
  165.     GetClientRect ( hwnd, ( LPRECT) &Rect ) ;
  166.     Width = ( Rect.right - Rect.left ) ;
  167.     Heigth = ( Rect.bottom - Rect.top ) ;
  168.     hEditWnd = CreateWindowEx ( dwStyleEx, "Edit", NULL, dwStyle, 0, 25, Width, Heigth - 25, hwnd, (HMENU)IDC_EDIT, hInst, NULL ) ;
  169.     if ( !hEditWnd ) {
  170.         DestroyWindow ( hwnd ) ;
  171.         return ( 0 ) ; }
  172.     dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON;
  173.     hBtOpenWnd = CreateWindowEx ( dwStyleEx, "Button", "O", dwStyle, 8, 2, 16, 20, hwnd, (HMENU)IDM_OPEN, hInst, NULL );
  174.     hBtOpen2Wnd = CreateWindowEx ( dwStyleEx, "Button", "2", dwStyle, 24, 2, 16, 20, hwnd, (HMENU)IDM_OPEN2, hInst, NULL );
  175.     hBtSaveWnd = CreateWindowEx ( dwStyleEx, "Button", "S", dwStyle, 40, 2, 16, 20, hwnd, (HMENU)IDM_SAVE, hInst, NULL );
  176.     hBtSaveasWnd = CreateWindowEx ( dwStyleEx, "Button", "A", dwStyle, 56, 2, 16, 20, hwnd, (HMENU)IDM_SAVEAS, hInst, NULL );
  177.     hBtDeleteWnd = CreateWindowEx ( dwStyleEx, "Button", "D", dwStyle, 72, 2, 16, 20, hwnd, (HMENU)IDM_DELETE, hInst, NULL );
  178.     hBtPrintWnd = CreateWindowEx ( dwStyleEx, "Button", "P", dwStyle, 88, 2, 16, 20, hwnd, (HMENU)IDM_PRINT, hInst, NULL );
  179.     hBtTypeWnd = CreateWindowEx ( dwStyleEx, "Button", "T", dwStyle, 104, 2, 16, 20, hwnd, (HMENU)IDM_FONTS, hInst, NULL );
  180.     hBtExitWnd = CreateWindowEx ( dwStyleEx, "Button", "X", dwStyle, 120, 2, 16, 20, hwnd, (HMENU)IDM_EXIT, hInst, NULL );
  181.     hBtUndoWnd = CreateWindowEx ( dwStyleEx, "Button", "U", dwStyle, 144, 2, 16, 20, hwnd, (HMENU)IDM_UNDO, hInst, NULL );
  182.     hBtCutWnd = CreateWindowEx ( dwStyleEx, "Button", "C", dwStyle, 160, 2, 16, 20, hwnd, (HMENU)IDM_CUT, hInst, NULL );
  183.     hBtCopyWnd = CreateWindowEx ( dwStyleEx, "Button", ">", dwStyle, 176, 2, 16, 20, hwnd, (HMENU)IDM_COPY, hInst, NULL );
  184.     hBtPasteWnd = CreateWindowEx ( dwStyleEx, "Button", "P", dwStyle, 192, 2, 16, 20, hwnd, (HMENU)IDM_PASTE, hInst, NULL );
  185.     hBtClearWnd = CreateWindowEx ( dwStyleEx, "Button", "D", dwStyle, 208, 2, 16, 20, hwnd, (HMENU)IDM_CLEAR, hInst, NULL );
  186.     hBtSelaWnd = CreateWindowEx ( dwStyleEx, "Button", "A", dwStyle, 224, 2, 16, 20, hwnd, (HMENU)IDM_SELECTALL, hInst, NULL );
  187.     hBtFindWnd = CreateWindowEx ( dwStyleEx, "Button", "F", dwStyle, 248, 2, 16, 20, hwnd, (HMENU)IDM_FIND, hInst, NULL );
  188.     hBtNextWnd = CreateWindowEx ( dwStyleEx, "Button", "N", dwStyle, 264, 2, 16, 20, hwnd, (HMENU)IDM_NEXT, hInst, NULL );
  189.     hBtPrevWnd = CreateWindowEx ( dwStyleEx, "Button", "P", dwStyle, 280, 2, 16, 20, hwnd, (HMENU)IDM_PREV, hInst, NULL );
  190.     hBtReplWnd = CreateWindowEx ( dwStyleEx, "Button", "R", dwStyle, 296, 2, 16, 20, hwnd, (HMENU)IDM_REPL, hInst, NULL );
  191.     hBtReplaWnd = CreateWindowEx ( dwStyleEx, "Button", "A", dwStyle, 312, 2, 16, 20, hwnd, (HMENU)IDM_REPLA, hInst, NULL );
  192.     hBtCmplWnd = CreateWindowEx ( dwStyleEx, "Button", "C", dwStyle, 336, 2, 16, 20, hwnd, (HMENU)IDM_CMPL, hInst, NULL );
  193.     hBtBuildWnd = CreateWindowEx ( dwStyleEx, "Button", "B", dwStyle, 352, 2, 16, 20, hwnd, (HMENU)IDM_BUILD, hInst, NULL );
  194.     hBtBuildallWnd = CreateWindowEx ( dwStyleEx, "Button", "A", dwStyle, 368, 2, 16, 20, hwnd, (HMENU)IDM_BUILDALL, hInst, NULL );
  195.     hBtCleanWnd = CreateWindowEx ( dwStyleEx, "Button", "C", dwStyle, 384, 2, 16, 20, hwnd, (HMENU)IDM_CLEAN, hInst, NULL );
  196.     hBtRunWnd = CreateWindowEx ( dwStyleEx, "Button", "E", dwStyle, 400, 2, 16, 20, hwnd, (HMENU)IDM_RUN, hInst, NULL );
  197.     hBtChelpWnd = CreateWindowEx ( dwStyleEx, "Button", "C", dwStyle, 424, 2, 16, 20, hwnd, (HMENU)IDM_CHELP, hInst, NULL );
  198.     hBtWhelpWnd = CreateWindowEx ( dwStyleEx, "Button", "W", dwStyle, 440, 2, 16, 20, hwnd, (HMENU)IDM_WHELP, hInst, NULL );
  199.     EnableWindow(hBtNextWnd, FALSE);
  200.     EnableWindow(hBtPrevWnd, FALSE);
  201.     EnableWindow(hBtReplWnd, FALSE);
  202.     EnableWindow(hBtCmplWnd, FALSE);
  203.     EnableWindow(hBtBuildWnd, FALSE);
  204.     EnableWindow(hBtBuildallWnd, FALSE);
  205.     SendMessage(hEditWnd, EM_LIMITTEXT, 1048576, 0L);
  206.     hHourGlass = LoadCursor ( NULL, IDC_WAIT ) ;
  207.     hSaveCursor = LoadCursor( NULL, IDC_ARROW ) ;
  208.     ofn.lStructSize = sizeof ( OPENFILENAME ) ;
  209.     ofn.hwndOwner = hwnd ;
  210.     ofn.lpstrFilter     = szFilterSpec ;
  211.     ofn.lpstrCustomFilter = NULL ;
  212.     ofn.nMaxCustFilter = 0 ;
  213.     ofn.nFilterIndex = 1 ;
  214.     ofn.lpstrFile = szFileName ;
  215.     ofn.nMaxFile = MAXFILENAME ;
  216.     ofn.lpstrInitialDir = NULL ;
  217.     ofn.lpstrFileTitle = szFileTitle ;
  218.     ofn.nMaxFileTitle = MAXFILENAME ;
  219.     ofn.lpstrTitle = NULL ;
  220.     ofn.lpstrDefExt = "" ;
  221.     ofn.Flags = 0 ;
  222.     pd.lStructSize = sizeof ( PRINTDLG ) ;
  223.     pd.hwndOwner = hwnd ;
  224.     pd.hDevMode = NULL ;
  225.     pd.hDevNames = NULL ;
  226.     pd.Flags = PD_RETURNDEFAULT;
  227.     pd.nCopies = 1 ;
  228.     strcpy ( lf.lfFaceName, "MS Sans Serif") ;
  229.     lf.lfHeight = 8 ;
  230.     plf = (PLOGFONT) LocalAlloc ( LPTR, sizeof (LOGFONT) ) ;
  231.     plf->lfHeight = lf.lfHeight ;
  232.     strcpy (plf->lfFaceName, lf.lfFaceName ) ;
  233.     hgWndFont = CreateFontIndirect (plf) ;
  234.     SendMessage ( hEditWnd, WM_SETFONT, (WPARAM)hgWndFont, 0L ) ;
  235.     LocalFree ( (HLOCAL) plf );
  236.     ShowWindow ( hwnd, nCmdShow ) ;
  237.     UpdateWindow ( hwnd ) ;
  238.     SendMessage ( hEditWnd, EM_SETTABSTOPS, 1, ( LPARAM )( int far* ) &TabSpacing ) ;
  239.     memset ( &cf, 0, sizeof (CHOOSEFONT ) ) ;
  240.     cf.lStructSize = sizeof ( CHOOSEFONT ) ;
  241.     cf.hwndOwner = hwnd ;
  242.     cf.lpLogFont = &lf ;
  243.     cf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT ;
  244.     cf.rgbColors = RGB ( 0, 0, 0 ) ;
  245.     cf.nFontType = SCREEN_FONTTYPE ;
  246.     hMenu = GetMenu (hwnd) ;
  247.     hBkBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
  248.     if(hPrevRunning) {
  249.         EnableMenuItem ( hMenu, IDM_OPEN2, MF_DISABLED | MF_GRAYED | MF_BYCOMMAND ) ;
  250.         EnableWindow(hBtOpen2Wnd, FALSE);
  251.         cf.rgbColors = RGB ( 0, 0, 255 ); }
  252.     if ( lstrlen (lpCmdLine ) ) 
  253.         PostMessage ( hwnd, WM_COMMAND, IDM_VIEW, 0L) ;
  254.     while ( GetMessage ( &msg, NULL, 0, 0 ) ) {
  255.         if ( !TranslateAccelerator ( hwnd, hAccTable, &msg ) ) {
  256.             TranslateMessage ( &msg ) ;
  257.             DispatchMessage ( &msg ) ; } }
  258.     return ( msg.wParam ) ;
  259. }
  260.  
  261. long APIENTRY MainWndProc ( HWND hWnd, UINT uMsg, UINT wParam, LONG lParam )
  262. {    FARPROC lpProcAbout ;
  263.     DWORD FlagSave ;
  264.     DWORD IOStatus ;
  265.     int Status ;
  266.     int nPageSize ;
  267.     switch ( uMsg ) {
  268.         case WM_COMMAND :
  269.             switch ( LOWORD(wParam) ) {
  270.                 case IDM_ABOUT :
  271.                     lpProcAbout = MakeProcInstance ( About, hInst ) ;
  272.                     DialogBox ( hInst, "AboutBox", hWnd, lpProcAbout ) ;
  273.                     FreeProcInstance ( lpProcAbout ) ;
  274.                     break ;
  275.                 case IDM_NEW :
  276.                     if ( !QuerySaveFile ( hWnd ) )
  277.                         return ( 0 ) ;
  278.                     bChanges = FALSE ;
  279.                     szFileName[0] = 0 ;
  280.                     hOldBuffer = ( HANDLE ) SendMessage ( hEditWnd, EM_GETHANDLE, 0, 0L ) ;
  281.                     if ( hOldBuffer ){
  282.                         hNewBuffer = LocalAlloc ( LMEM_MOVEABLE | LMEM_ZEROINIT, 1 );
  283.                         SendMessage ( hEditWnd, EM_SETHANDLE, (WPARAM)hNewBuffer, 0L ) ;
  284.                         SetWindowText ( hWnd, "Winner- Untitled" ) ;
  285.                         SetFocus ( hEditWnd ) ;
  286.                         LocalFree ( hOldBuffer );}
  287.                     break ;
  288.                 case IDM_RUN:
  289.                     sprintf(szFFileName, "%s", szFileName );
  290.                     ofn.nFilterIndex = 2 ;
  291.                     ofn.lpstrTitle="Execute File";
  292.                     if ( !GetOpenFileName ( ( LPOPENFILENAME ) &ofn ) )
  293.                         return ( 0 ) ;
  294.                     ShellExecute ( hWnd, NULL, (LPSTR)&szFileName, "", "", SW_SHOW ) ;
  295.                     sprintf(szFileName, "%s", szFFileName );
  296.                     ofn.nFilterIndex = 1 ;
  297.                     break;
  298.                 case IDM_OPEN2:
  299.                     if(GetAsyncKeyState(VK_CONTROL)<0)
  300.                         ShowWindow(hwnd,SW_MINIMIZE);
  301.                     ofn.nFilterIndex = 1 ;
  302.                     ofn.lpstrTitle="Open 2nd File";
  303.                     sprintf(szFFileName, "%s", szFileName );
  304.                     if ( !GetOpenFileName ( ( LPOPENFILENAME ) &ofn ) )
  305.                         return ( 0 ) ;
  306.                     ShellExecute ( hWnd, NULL, "Winner.exe", (LPSTR)&szFileName, "", SW_SHOW) ;
  307.                     sprintf(szFileName, "%s", szFFileName );
  308.                     break;
  309.                 case IDM_DELETE :
  310.                     ofn.nFilterIndex = 1 ;
  311.                     ofn.lpstrTitle="Delete File";
  312.                     sprintf(szFFileName, "%s", szFileName );
  313.                     if ( !GetOpenFileName ( ( LPOPENFILENAME ) &ofn ) )
  314.                         return ( 0 ) ;
  315.                     sprintf ( szTemp, "DELETE: %s ?", szFileName ) ;
  316.                     Response = MessageBox ( hWnd, szTemp, "Winner",  MB_YESNOCANCEL | MB_ICONEXCLAMATION ) ;
  317.                     if ( Response == IDYES )
  318.                         DeleteFile ( ( LPSTR )&szFileName ) ;
  319.                     sprintf(szFileName, "%s", szFFileName );
  320.                     break;
  321.                 case IDM_OPEN :
  322.                     if ( !QuerySaveFile ( hWnd ) )
  323.                         return ( 0 ) ;
  324.                     ofn.nFilterIndex = 1 ;
  325.                     ofn.lpstrTitle="Open File";
  326.                     if ( !GetOpenFileName ( ( LPOPENFILENAME ) &ofn ) )
  327.                         return ( 0 ) ;
  328.                 case IDM_VIEW :
  329.                     hFile = OpenFile ( ( LPSTR ) szFileName, ( LPOFSTRUCT )&OfStruct, OF_READ ) ;
  330.                     if ( !hFile )
  331.                         return ( 0 ) ;
  332.                     hOldBuffer = ( HANDLE ) SendMessage ( hEditWnd, EM_GETHANDLE, 0, 0L ) ;
  333.                     LocalFree ( hOldBuffer ) ;
  334.                     dwResults  = GetFileSize((HANDLE)hFile, NULL);
  335.                     hEditBuffer = LocalAlloc ( LMEM_MOVEABLE | LMEM_ZEROINIT, dwResults+1 ) ;
  336.                     if ( !hEditBuffer ) {
  337.                         MessageBox ( hWnd, "Not enough memory.", NULL, MB_OK | MB_ICONEXCLAMATION ) ;
  338.                         _lclose ( hFile ) ;
  339.                         return ( 0 ) ; }
  340.                     hSaveCursor = SetCursor ( hHourGlass ) ;
  341.                     pEditBuffer = LocalLock ( hEditBuffer ) ;
  342.                     ReadFile((HANDLE)hFile, pEditBuffer, dwResults, (LPDWORD)&IOStatus, NULL ) ;
  343.                     _lclose ( hFile ) ;
  344.                     LocalUnlock ( hEditBuffer ) ;
  345.                     if ( IOStatus != dwResults ) {
  346.                         sprintf ( szTemp, "Error reading %s.", szFileName ) ;
  347.                         SetCursor ( hSaveCursor ) ;
  348.                         MessageBox ( hWnd, szTemp, NULL, MB_OK | MB_ICONEXCLAMATION ) ; }
  349.                     sprintf ( szTemp, "%s - %s", szBaseWindowTitle, szFileName ) ;
  350.                     SendMessage ( hEditWnd, EM_SETHANDLE, (WPARAM)hEditBuffer, 0L ) ;
  351.                     SetWindowText ( hWnd, szTemp ) ;
  352.                     SetFocus ( hEditWnd ) ;
  353.                     bChanges = FALSE ;
  354.                     SetCursor ( hSaveCursor ) ;
  355.                     EnableMenuItem ( hMenu, IDM_CMPL, MF_ENABLED | MF_BYCOMMAND ) ;
  356.                     EnableMenuItem ( hMenu, IDM_BUILD, MF_ENABLED | MF_BYCOMMAND ) ;
  357.                     EnableMenuItem ( hMenu, IDM_BUILDALL, MF_ENABLED | MF_BYCOMMAND ) ;
  358.                     EnableWindow(hBtCmplWnd, TRUE);
  359.                     EnableWindow(hBtBuildWnd, TRUE);
  360.                     EnableWindow(hBtBuildallWnd,TRUE);
  361.                     break ;
  362.                 case IDM_SAVE :
  363.                     if ( szFileName[ 0 ] ) {
  364.                         if ( bChanges )
  365.                             SaveFile ( hWnd ) ;
  366.                         SetFocus(hEditWnd);
  367.                         break ; }
  368.                     SetFocus(hEditWnd);
  369.                 case IDM_SAVEAS :
  370.                     ofn.nFilterIndex = 1 ;
  371.                     ofn.lpstrTitle="Save File As";
  372.                     if ( !GetSaveFileName ( ( LPOPENFILENAME ) &ofn ) )
  373.                         return FALSE ;
  374.                     lstrcpy ( szWindowTitle, szBaseWindowTitle ) ;
  375.                     lstrcat ( szWindowTitle, " - " ) ;
  376.                     lstrcat ( szWindowTitle, szFileTitle ) ;
  377.                     SetWindowText ( hWnd, szWindowTitle ) ;
  378.                     SaveFile ( hWnd ) ;
  379.                     break ;
  380.                 case IDM_PRINT :
  381.                     hSaveCursor = SetCursor ( hHourGlass ) ;
  382.                     hPr = GetPrinterDC( ) ;
  383.                     if ( !hPr ) {
  384.                         sprintf ( szTemp, "Cannot print %s", szFileName ) ;
  385.                         MessageBox ( hWnd, szTemp, NULL, MB_OK | MB_ICONHAND ) ;
  386.                         return ( 0 ) ; }
  387.                     lpAbortDlg =  MakeProcInstance ( AbortDlg, hInst ) ;
  388.                     lpAbortProc = MakeProcInstance( AbortProc, hInst ) ;
  389.                     SetAbortProc ( hPr, lpAbortProc ) ;
  390.                     plf = ( PLOGFONT ) LocalAlloc ( LPTR, sizeof ( LOGFONT ) ) ;
  391.                     plf->lfHeight = -MulDiv ( lf.lfHeight, GetDeviceCaps ( hPr, LOGPIXELSY ), 72 ) ;
  392.                     plf->lfWeight = lf.lfWeight ;
  393.                     plf->lfItalic = lf.lfItalic ;
  394.                     plf->lfUnderline = lf.lfUnderline ;
  395.                     plf->lfStrikeOut = lf.lfStrikeOut ;
  396.                     plf->lfCharSet = lf.lfCharSet ;
  397.                     plf->lfQuality = lf.lfQuality ;
  398.                     plf->lfPitchAndFamily = lf.lfPitchAndFamily ;
  399.                     strcpy ( plf->lfFaceName, lf.lfFaceName ) ;
  400.                     hFont = CreateFontIndirect ( plf ) ;
  401.                     SelectObject ( hPr, hFont ) ;
  402.                     if ( Escape ( hPr, STARTDOC, 14, "PrntFile text", ( LPSTR ) NULL ) < 0 ) {
  403.                         MessageBox ( hWnd, "Unable to start print job", NULL, MB_OK | MB_ICONHAND ) ;
  404.                         FreeProcInstance ( lpAbortDlg ) ;
  405.                         FreeProcInstance ( lpAbortProc ) ;
  406.                         DeleteDC ( hPr ) ; }
  407.                     bAbort = FALSE ;
  408.                     hAbortDlgWnd = CreateDialog ( hInst, "AbortDlg", hWnd, lpAbortDlg ) ;
  409.                     if ( !hAbortDlgWnd ) {
  410.                         SetCursor ( hSaveCursor ) ;
  411.                         MessageBox ( hWnd, "NULL Abort window handle", NULL, MB_OK | MB_ICONHAND ) ;
  412.                         return ( FALSE ) ; }
  413.                     ShowWindow ( hAbortDlgWnd, SW_NORMAL ) ;
  414.                     EnableWindow ( hWnd, FALSE ) ;
  415.                     SetCursor ( hSaveCursor ) ;
  416.                     GetTextMetrics ( hPr, &TextMetric ) ;
  417.                     LineSpace = TextMetric.tmHeight + TextMetric.tmExternalLeading ;
  418.                     nPageSize = GetDeviceCaps ( hPr, VERTRES ) ;
  419.                     LinesPerPage = nPageSize / LineSpace - 2 ;
  420.                     wLines = ( WORD ) SendMessage ( hEditWnd, EM_GETLINECOUNT, 0, 0L ) ;
  421.                     CurrentLine = 1 ;
  422.                     dwStyle = 1 ;
  423.                     StartPage ( hPr ) ;
  424.                     Count = sprintf ( szTemp, "File Name  %s     Page  %lu ", szFileName, dwStyle ) ;
  425.                     TextOut ( hPr, 99, CurrentLine*LineSpace, ( LPSTR ) szTemp, Count ) ;
  426.                     CurrentLine ++ ;
  427.                     TextOut ( hPr, 0, CurrentLine*LineSpace, "", 0 ) ;
  428.                     CurrentLine ++ ;
  429.                     for ( wIndex = Status = 0; wIndex < wLines; wIndex++ ) {
  430.                         szLine[0] = 127 ;
  431.                         szLine[1] = 0 ;
  432.                         LineLength = ( int ) SendMessage ( hEditWnd, EM_GETLINE, wIndex, ( DWORD ) ( LPSTR ) szLine ) ;
  433.                         TabbedTextOut ( hPr, 99, CurrentLine*LineSpace, ( LPSTR ) szLine, LineLength, 1,  nTabs, 99 ) ;
  434.                         if ( ++CurrentLine > LinesPerPage ) {
  435.                             CurrentLine = 1 ;
  436.                             dwStyle ++ ;
  437.                             Status = EndPage ( hPr ) ;
  438.                             if ( Status < 0 || bAbort )
  439.                                 break ;
  440.                             SelectObject ( hPr, hFont ) ;
  441.                             StartPage ( hPr ) ;
  442.                             Count = sprintf ( szTemp, "File Name  %s      Page  %lu ", szFileName, dwStyle ) ;
  443.                             TextOut ( hPr, 99, CurrentLine*LineSpace, ( LPSTR ) szTemp, Count ) ;
  444.                             CurrentLine ++ ;
  445.                             TextOut ( hPr, 0, CurrentLine*LineSpace, "", 0 ) ;
  446.                             CurrentLine ++ ; } }
  447.                     if ( Status >= 0 && !bAbort ) {
  448.                         Escape( hPr, NEWFRAME, 0, 0L, 0L ) ;
  449.                         Escape( hPr, ENDDOC, 0, 0L, 0L ) ; }
  450.                     EnableWindow ( hWnd, TRUE ) ;
  451.                     DestroyWindow ( hAbortDlgWnd ) ;
  452.                     FreeProcInstance ( lpAbortDlg ) ;
  453.                     FreeProcInstance ( lpAbortProc ) ;
  454.                     LocalFree ( ( HLOCAL ) plf ) ;
  455.                     DeleteObject ( hFont ) ;
  456.                     DeleteDC ( hPr ) ;
  457.                     break ;
  458.                 case IDM_PRINTSETUP :
  459.                     FlagSave = pd.Flags ;
  460.                     pd.Flags = PD_RETURNDC | PD_PRINTSETUP ;
  461. /*                    PrintDlg ( ( LPPRINTDLG ) &pd ) ;    */
  462. /*                    pd.Flags = FlagSave ;    */
  463.                     break ;
  464.                 case IDM_UNDO :
  465.                     SendMessage ( hEditWnd,EM_UNDO,0,0L ) ;
  466.                     SetFocus(hEditWnd);
  467.                     break ;
  468.                 case IDM_CUT :
  469.                     SendMessage ( hEditWnd, WM_CUT, 0, 0L ) ;
  470.                     SetFocus(hEditWnd);
  471.                     break ;
  472.                 case IDM_COPY :
  473.                     SendMessage ( hEditWnd, WM_COPY, 0, 0L ) ;
  474.                     SendMessage ( hEditWnd, EM_GETSEL, (WPARAM)(LPDWORD)&dwStart, 0L ) ;
  475.                     SendMessage ( hEditWnd, EM_SETSEL, (WPARAM)dwStart, (LPARAM)dwStart ) ;
  476.                     SetFocus(hEditWnd);
  477.                     break ;
  478.                 case IDM_PASTE :
  479.                     SendMessage ( hEditWnd, WM_PASTE, 0, 0L ) ;
  480.                     SetFocus(hEditWnd);
  481.                     break ;
  482.                 case IDM_CLEAR :
  483.                     SendMessage ( hEditWnd, WM_CLEAR, 0, 0L ) ;
  484.                     break ;
  485.                 case IDM_SELECTALL :
  486.                     SendMessage ( hEditWnd, EM_SETSEL, 0, -1 ) ;
  487.                     break ;
  488.                 case IDM_CMPL:
  489.                     if ( !QuerySaveFile ( hWnd ) )
  490.                         return ( 0 ) ;
  491.                     ShellExecute ( hWnd, NULL, "winner.bat", szFileName,"", SW_MINIMIZE ) ;
  492.                     break ;                    
  493.                 case IDM_BUILD :
  494.                     if ( !QuerySaveFile ( hWnd ) )
  495.                         return ( 0 ) ;
  496.                     ShellExecute ( hWnd, NULL, "winner.bat", " b", "", SW_MINIMIZE ) ;
  497.                     break ;
  498.                 case IDM_BUILDALL :
  499.                     if ( !QuerySaveFile ( hWnd ) )
  500.                         return ( 0 ) ;
  501.                     ShellExecute ( hWnd, NULL, "winner.bat", " a", "", SW_MINIMIZE ) ;
  502.                     break ;
  503.                 case IDM_CLEAN :
  504.                     ShellExecute ( hWnd, NULL, "winner.bat", " c", "" ,SW_MINIMIZE ) ;
  505.                     break ;
  506.                 case IDM_FIND :
  507.                     EnableMenuItem ( hMenu, IDM_NEXT, MF_ENABLED | MF_BYCOMMAND ) ;
  508.                     EnableWindow(hBtNextWnd, TRUE);
  509.                     EnableMenuItem ( hMenu, IDM_PREV, MF_ENABLED | MF_BYCOMMAND ) ;
  510.                     EnableWindow(hBtPrevWnd, TRUE);
  511.                     EnableMenuItem ( hMenu, IDM_REPL, MF_ENABLED | MF_BYCOMMAND ) ;
  512.                     EnableWindow(hBtReplWnd, TRUE);
  513.                     Find( ) ;
  514.                     break ;
  515.                 case IDM_NEXT :
  516.                     FindNext( ) ;
  517.                     SetFocus(hEditWnd);
  518.                     break ;
  519.                 case IDM_PREV :
  520.                     FindPrev( ) ;
  521.                     SetFocus(hEditWnd);
  522.                     break ;
  523.                 case IDM_REPL :
  524.                     SendMessage ( hEditWnd, EM_REPLACESEL, 0, ( LPARAM ) ( LPSTR ) &szRepl ) ;
  525.                     SetFocus(hEditWnd);
  526.                     break ;
  527.                 case IDM_REPLA :
  528.                     bSearchin = TRUE ;
  529.                     SendMessage ( hEditWnd, EM_SETSEL, 0, 0L ) ;
  530.                     Find( ) ;
  531.                     while ( bSearchin ) {
  532.                         bSearchin = FALSE ;
  533.                         dwResults = SendMessage ( hEditWnd, EM_GETSEL, 0, 0L ) ;
  534.                         if ( dwResults != 0 ) {
  535.                             SendMessage ( hEditWnd, EM_REPLACESEL, 0, ( LPARAM ) ( LPSTR ) &szRepl ) ;
  536.                             bSearchin = TRUE ;
  537.                             FindNext( ) ; } }
  538.                     break ;
  539.                 case IDM_FONTS :
  540.                     if (ChooseFont (&cf)) {
  541.                         plf = (PLOGFONT) LocalAlloc ( LPTR, sizeof (LOGFONT) ) ;
  542.                         plf->lfHeight = lf.lfHeight ;
  543.                         plf->lfWeight = lf.lfWeight ;
  544.                         plf->lfItalic = lf.lfItalic ;
  545.                         plf->lfUnderline = lf.lfUnderline ;
  546.                         plf->lfStrikeOut = lf.lfStrikeOut ;
  547.                         plf->lfCharSet = lf.lfCharSet ;
  548.                         plf->lfQuality = lf.lfQuality ;
  549.                         plf->lfPitchAndFamily = lf.lfPitchAndFamily ;
  550.                         strcpy (plf->lfFaceName, lf.lfFaceName ) ;
  551.                         dwTextColor = cf.rgbColors ;
  552.                         hgFont = CreateFontIndirect (plf) ;
  553.                         SendMessage ( hEditWnd, WM_SETFONT, (WPARAM)hgFont, 0L ) ;
  554.                         LocalFree ( (HLOCAL) plf ); }
  555.                     break ;
  556.                 case IDM_EXIT :
  557.                     QuerySaveFile ( hWnd ) ;
  558.                     DestroyWindow ( hWnd ) ;
  559.                     break ;
  560.                 case IDM_CHELP:
  561.                     ShellExecute ( hWnd, NULL, "winhlp32.exe", " msc.hlp", "", SW_SHOW ) ;
  562.                     break;
  563.                 case IDM_WHELP:
  564.                     ShellExecute ( hWnd, NULL, "winhlp32.exe", " api32wh.hlp", "", SW_SHOW ) ;
  565.                     break;
  566.                 case IDC_EDIT :
  567.                     if ( HIWORD ( wParam ) == EN_CHANGE ) {
  568.                         bChanges = TRUE ;
  569.                         SendMessage ( hEditWnd, EM_GETSEL, (WPARAM)(LPDWORD)&dwStart, 0L ) ;
  570.                         dwResults = SendMessage ( hEditWnd, EM_LINEFROMCHAR,dwStart,0L ) ;
  571.                         if ( dwResults == dwLineCount )
  572.                             break ;
  573.                         dwLineCount = sprintf ( szTemp, "Line Number  %u    ", dwResults+1 ) ;
  574.                         hDC = GetDC(hwnd);
  575.                         SetBkColor(hDC, (COLORREF)RGB(192, 192, 192));
  576.                         SelectObject(hDC, hgWndFont);
  577.                         TextOut(hDC, 472, 5, (LPSTR)&szTemp, dwLineCount) ;
  578.                         ReleaseDC(hwnd, hDC);
  579.                         dwLineCount = dwResults ;
  580.                         if(bButCut) {
  581.                             bButCut = FALSE;
  582.                             break;}
  583.                         TabSpacing =  (WORD)dwResults ;
  584.                         dwResults = SendMessage ( hEditWnd, EM_GETLINE, (WPARAM)TabSpacing, ( DWORD ) ( LPSTR ) szTemp ) ;
  585.                         if ( dwResults == 0 ) {
  586.                             dwResults = SendMessage ( hEditWnd, EM_GETLINE, (WPARAM)TabSpacing - 1, ( DWORD ) ( LPSTR ) szTemp ) ;
  587.                             lpstrPointer = ( LPSTR ) szTemp ;
  588.                             TabSpacing = 0 ;
  589.                             while ( *lpstrPointer == ( BYTE ) 9 ) {
  590.                                 TabSpacing ++ ;
  591.                                 lpstrPointer ++ ; }
  592.                             lpstrPointer = ( LPSTR ) szTemp + dwResults -1 ;
  593.                             if ( *lpstrPointer == ( BYTE ) 40 )
  594.                                 TabSpacing++ ;
  595.                             if ( *lpstrPointer == ( BYTE ) 41 )
  596.                                 TabSpacing++ ;
  597.                             if ( *lpstrPointer == ( BYTE ) 58 )
  598.                                 TabSpacing++ ;
  599.                             if ( *lpstrPointer == ( BYTE ) 123 )
  600.                                 TabSpacing++ ;
  601.                             if ( TabSpacing > 0 )
  602.                                 if ( *lpstrPointer == ( BYTE ) 125 )
  603.                                     TabSpacing-- ;
  604.                             wsprintf ( szTemp, "" ) ;
  605.                             while ( TabSpacing >0 ) {
  606.                                 lstrcat ( szTemp, "\t" ) ;
  607.                                 TabSpacing-- ; }
  608.                             SendMessage ( hEditWnd, EM_REPLACESEL, 0, ( LPARAM ) ( LPSTR ) szTemp ) ; }
  609.                         break ; }
  610.                     if ( HIWORD ( wParam ) == EN_ERRSPACE ) {
  611.                         MessageBox ( GetFocus ( ), "Out of memory.", "PrntFile Sample Application", MB_ICONHAND | MB_OK ) ; }
  612.                     break ; }
  613.                 break ;
  614.         case WM_PAINT:
  615.             hDC = BeginPaint(hwnd, (LPPAINTSTRUCT)&ps);
  616.             MoveToEx(hDC, 0, 24, NULL);
  617.             hPen = SelectObject(hDC, (HGDIOBJ)GetStockObject(BLACK_PEN));
  618.             LineTo(hDC, 632, 24);
  619.             MoveToEx(hDC, 466, 20, NULL);
  620.             DeleteObject(hPen);
  621.             hPen = SelectObject(hDC, (HGDIOBJ)CreatePen(PS_SOLID, 2, RGB(128,128,128)));
  622.             LineTo(hDC, 466, 3);
  623.             LineTo(hDC, 620, 3);
  624.             LineTo(hDC, 620, 4);
  625.             DeleteObject(hPen);
  626.             hPen = SelectObject(hDC, (HGDIOBJ)CreatePen(PS_SOLID, 2, RGB(255, 255, 255)));
  627.             LineTo(hDC, 620,21);
  628.             LineTo(hDC, 466, 21);
  629.             DeleteObject(hPen);
  630.             dwResults = sprintf ( szTemp, "Line Number  %u    ", dwLineCount+1 ) ;
  631.             SetBkColor(hDC, (COLORREF)RGB(192, 192, 192));
  632.             SelectObject(hDC, hgWndFont);
  633.             TextOut(hDC, 472, 5, (LPSTR)&szTemp, dwResults) ;
  634.             EndPaint(hwnd, (LPPAINTSTRUCT)&ps);
  635.         case WM_CTLCOLOREDIT:
  636.             if (lParam == (LPARAM)hEditWnd) {
  637.                 SetTextColor ( (HDC) wParam, (COLORREF) dwTextColor);
  638.                 return (WPARAM)hBkBrush;}
  639.             return 0;
  640.         case WM_SETCURSOR :
  641.             if (wParam == (WPARAM)hEditWnd ) {
  642.                 SendMessage(hEditWnd, EM_GETSEL, (WPARAM)(LPDWORD)&dwStart, (LPARAM)(LPDWORD)&dwEnd);
  643.                 if(HIWORD(lParam) == WM_RBUTTONUP) {
  644.                     if(dwEnd == dwStart)
  645.                         SendMessage ( hEditWnd, WM_PASTE, 0, 0L ) ;
  646.                     else {
  647.                         SendMessage ( hEditWnd, WM_CUT, 0, 0L ) ;
  648.                         SendMessage ( hEditWnd, EM_SETSEL, (WPARAM)dwStart, (LPARAM)dwStart ) ;
  649.                         bButCut = TRUE;}}
  650.                 dwResults = SendMessage ( hEditWnd, EM_LINEFROMCHAR, dwStart, 0L ) ;
  651.                 if ( dwResults == dwLineCount )
  652.                     break ;
  653.                 dwLineCount = sprintf ( szTemp, "Line Number  %u    ", dwResults+1 ) ;
  654.                 hDC = GetDC(hwnd);
  655.                 SetBkColor(hDC, (COLORREF)RGB(192, 192, 192));
  656.                 SelectObject(hDC, hgWndFont);
  657.                 TextOut(hDC, 472, 5, (LPSTR)&szTemp, dwLineCount) ;
  658.                 ReleaseDC(hwnd, hDC);
  659.                 dwLineCount=dwResults ;
  660.                 break ; }
  661.             return ( DefWindowProc ( hWnd, uMsg, wParam, lParam ) ) ;
  662.         case WM_SETFOCUS :
  663.             SetFocus ( hEditWnd ) ;
  664.             break ;
  665.         case WM_SIZE :
  666.             MoveWindow ( hEditWnd, 0, 25, LOWORD ( lParam ), HIWORD ( lParam ) - 25, TRUE ) ;
  667.             break ;
  668.         case WM_QUERYENDSESSION :
  669.             return ( QuerySaveFile ( hWnd ) ) ;
  670.         case WM_CLOSE :
  671.             if ( QuerySaveFile ( hWnd ) )
  672.                 DestroyWindow ( hWnd ) ;
  673.             break ;
  674.         case WM_DESTROY :
  675.             PostQuitMessage ( 0 ) ;
  676.             break ;
  677.         default :
  678.             return ( DefWindowProc ( hWnd, uMsg, wParam, lParam ) ) ; }
  679.     return ( 0 ) ;
  680. }
  681.  
  682. BOOL SaveFile ( hWnd )
  683. HWND hWnd ;
  684. {   BOOL bSuccess ;
  685.     DWORD IOStatus ;
  686.     if ( ( hNewFile = CreateFile (szFileName,     GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
  687.                                             NULL, CREATE_ALWAYS, 0, NULL ) ) < 0) {
  688.         sprintf ( szTemp, "Cannot write to %s.", szFileName ) ;
  689.         MessageBox ( hWnd, szTemp, NULL, MB_OK | MB_ICONHAND ) ;
  690.         return ( FALSE ) ; }
  691.     hEditBuffer = ( HANDLE) SendMessage ( hEditWnd, EM_GETHANDLE, 0, 0L ) ;
  692.     pEditBuffer = LocalLock ( hEditBuffer ) ;
  693.     hSaveCursor = SetCursor ( hHourGlass ) ;
  694.      WriteFile (hNewFile, pEditBuffer, strlen ( pEditBuffer ), (LPDWORD)&IOStatus, NULL ) ;
  695.     CloseHandle ( hNewFile ) ;
  696.     SetCursor ( hSaveCursor ) ;
  697.     if ( IOStatus != strlen ( pEditBuffer ) ) {
  698.         sprintf ( szTemp, "Error writing to %s.", szFileName ) ;
  699.         MessageBox ( hWnd, szTemp, NULL, MB_OK | MB_ICONHAND ) ;
  700.         bSuccess = FALSE ; }
  701.     else {
  702.         bSuccess = TRUE ;
  703.         bChanges = FALSE ; }
  704.     LocalUnlock ( hEditBuffer ) ;
  705.     return ( bSuccess ) ;
  706. }
  707.  
  708. BOOL QuerySaveFile ( hWnd )
  709. HWND hWnd ;
  710. {    if ( bChanges ) {
  711.         sprintf ( szTemp, "Save current changes: %s", szFileName ) ;
  712.         Response = MessageBox ( hWnd, szTemp, "Winner",  MB_YESNOCANCEL | MB_ICONEXCLAMATION ) ;
  713.         if ( Response == IDYES ) {
  714.             while ( !szFileName[ 0 ] ) {
  715.                 if ( !GetSaveFileName ( ( LPOPENFILENAME ) &ofn ) )
  716.                     return FALSE ; }
  717.             SaveFile ( hWnd ) ; }
  718.         else if ( Response == IDCANCEL )
  719.             return ( FALSE ) ; }
  720.     else  return ( TRUE ) ;
  721. }
  722.  
  723. HDC GetPrinterDC ( void )
  724. {    HDC         hDC ;
  725.     LPDEVMODE   lpDevMode = NULL ;
  726.     LPDEVNAMES  lpDevNames ;
  727.     LPSTR       lpszDriverName ;
  728.     LPSTR       lpszDeviceName ;
  729.     LPSTR       lpszPortName ;
  730.     if ( !PrintDlg ( ( LPPRINTDLG ) &pd ) )
  731.         return ( NULL ) ;
  732.     if ( pd.hDC )
  733.         hDC = pd.hDC ;
  734.     else {
  735.         if ( !pd.hDevNames )
  736.             return ( NULL ) ;
  737.         lpDevNames = ( LPDEVNAMES ) GlobalLock ( pd.hDevNames ) ;
  738.         lpszDriverName = ( LPSTR ) lpDevNames + lpDevNames->wDriverOffset ;
  739.         lpszDeviceName = ( LPSTR ) lpDevNames + lpDevNames->wDeviceOffset ;
  740.         lpszPortName   = ( LPSTR ) lpDevNames + lpDevNames->wOutputOffset ;
  741.         GlobalUnlock ( pd.hDevNames ) ;
  742.         if ( pd.hDevMode )
  743.             lpDevMode = ( LPDEVMODE ) GlobalLock ( pd.hDevMode ) ;
  744.         hDC = CreateDC ( lpszDriverName, lpszDeviceName, lpszPortName, NULL ) ;
  745.         if ( pd.hDevMode && lpDevMode )
  746.             GlobalUnlock ( pd.hDevMode ) ; }
  747.     if ( pd.hDevNames ) {
  748.         GlobalFree( pd.hDevNames ) ;
  749.         pd.hDevNames = NULL ; }
  750.     if ( pd.hDevMode ) {
  751.         GlobalFree ( pd.hDevMode ) ;
  752.         pd.hDevMode = NULL ; }
  753.     return ( hDC ) ;
  754. }
  755.  
  756. int APIENTRY AbortProc ( hPr, Code )
  757. HDC hPr ;
  758. int Code ;
  759. {    MSG msg ;
  760.     if ( !hAbortDlgWnd )
  761.         return ( TRUE ) ;
  762.     while ( !bAbort && PeekMessage ( &msg, NULL, 0, 0, TRUE ) )
  763.            if ( !IsDialogMessage ( hAbortDlgWnd, &msg ) ) {
  764.             TranslateMessage ( &msg ) ;
  765.             DispatchMessage ( &msg ) ; }
  766.     return ( !bAbort ) ;
  767. }
  768.  
  769. int APIENTRY AbortDlg ( HWND hDlg, UINT uMsg, UINT wParam, LONG lParam )
  770. {    switch ( uMsg ) {
  771.         case WM_COMMAND :
  772.             return ( bAbort = TRUE ) ;
  773.         case WM_INITDIALOG :
  774.             SetFocus ( GetDlgItem ( hDlg, IDCANCEL ) ) ;
  775.             SetDlgItemText ( hDlg, IDC_FILENAME, szFileName ) ;
  776.             return ( TRUE ) ; }
  777.     return ( FALSE ) ;
  778. }
  779.  
  780. BOOL APIENTRY About ( HWND hDlg, UINT uMsg, UINT wParam, LONG lParam )
  781. {    switch ( uMsg ) {
  782.         case WM_INITDIALOG :
  783.             return ( TRUE ) ;
  784.         case WM_COMMAND :
  785.             if ( LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL ) {
  786.                 EndDialog( hDlg, TRUE ) ;
  787.                 return ( TRUE ) ; }
  788.             return ( TRUE ) ; }
  789.     return ( FALSE ) ;
  790. }
  791.  
  792. BOOL NEAR PASCAL RealSlowCompare (pSubject, pTarget )
  793. LPSTR pSubject;
  794. LPSTR pTarget;
  795. {    if (fCase){
  796.         while (*pTarget)
  797.             if (*pTarget++ != *pSubject++)
  798.                 return FALSE;}
  799.     else{
  800.         AnsiLower ((LPSTR)pTarget);
  801.         while (*pTarget)
  802.             if (*pTarget++ != (char)(DWORD)AnsiLower ((LPSTR)(DWORD)(BYTE)*pSubject++))
  803.                 return FALSE;}
  804.     return TRUE;
  805. }
  806.  
  807. VOID NEAR PASCAL MyFindText( dch )
  808. LONG dch;
  809. {    DWORD  cch;
  810.     DWORD i;
  811.     if (!*szSearch)
  812.         return;
  813.     SendMessage(hEditWnd, EM_GETSEL,(WPARAM)(LPDWORD)&dwStart, 0L);
  814.     hEditBuffer = (HANDLE)SendMessage (hEditWnd, EM_GETHANDLE, 0, 0L);
  815.     pEditBuffer = LocalLock(hEditBuffer);
  816.     cch = SendMessage (hEditWnd, WM_GETTEXTLENGTH, 0, 0L);
  817.     pEditBuffer += dwStart + dch;
  818.     if (dch < 0)
  819.         i = dwStart;
  820.     else
  821.         i = cch - dwStart + 1 - lstrlen (szSearch);
  822.     while ( i > 0){
  823.         dwStart+=dch;
  824.         if (RealSlowCompare(pEditBuffer, (LPSTR)&szSearch)){
  825.             LocalUnlock(hEditBuffer);
  826.             dwEnd = dwStart + lstrlen (szSearch);
  827.             SendMessage (hEditWnd, EM_SETSEL, dwStart, dwEnd);
  828.             SendMessage (hEditWnd, EM_SCROLLCARET, 0, 0);
  829.             return;}
  830.         i--;
  831.         pEditBuffer += dch;}
  832.     LocalUnlock (hEditBuffer);
  833.     MessageBox (hwnd,"Done","Find String", MB_OK);
  834.     SendMessage(hEditWnd, EM_SETSEL, 0, 0L);
  835.     SetFocus(hEditWnd);
  836.     return;
  837. }
  838.  
  839. VOID FAR PASCAL FindPrev(void)
  840. {    MyFindText(-1);
  841. }
  842.  
  843. VOID FAR PASCAL FindNext(void)
  844. {    MyFindText(1);
  845. }
  846.  
  847. BOOL APIENTRY FindDlgProc(HWND hwnd, UINT uMsg, UINT wParam, LONG lParam)
  848. {    switch (uMsg){
  849.         case WM_INITDIALOG:{
  850.             CheckDlgButton (hwnd, IDD_CASE, fCase);
  851.             SetDlgItemText (hwnd, IDD_SEARCH, szSearch);
  852.             SetDlgItemText (hwnd, IDD_REPL, szRepl);
  853.             if (!lstrlen (szSearch)){
  854.                 EnableWindow (GetDlgItem (hwnd, IDOK), FALSE);
  855.                 EnableWindow (GetDlgItem (hwnd, IDD_PREV), FALSE);}
  856.             break;}
  857.         case WM_COMMAND:{
  858.             int i = 1;
  859.             switch (LOWORD(wParam)){
  860.                 case IDD_SEARCH:
  861.                     if (HIWORD (wParam) == EN_CHANGE){
  862.                         if (! SendDlgItemMessage (hwnd, IDD_SEARCH, WM_GETTEXTLENGTH, 0, 0L))
  863.                             i = FALSE;
  864.                     else
  865.                         i = TRUE;
  866.                     EnableWindow (GetDlgItem (hwnd, IDOK), i);
  867.                     EnableWindow (GetDlgItem (hwnd, IDD_PREV), i);}
  868.                     break;
  869.                 case IDD_CASE:
  870.                     CheckDlgButton (hwnd, IDD_CASE, !IsDlgButtonChecked (hwnd, IDD_CASE));
  871.                     break;
  872.                 case IDD_PREV:
  873.                     i=-1;
  874.                 case IDOK:
  875.                     fCase = IsDlgButtonChecked( hwnd, IDD_CASE);
  876.                     GetDlgItemText (hwnd, IDD_SEARCH, szSearch, sizeof (szSearch));
  877.                     GetDlgItemText (hwnd, IDD_REPL, szRepl, sizeof (szRepl));
  878.                     MyFindText (i);
  879.                 case IDCANCEL:
  880.                     EndDialog (hwnd, 0);
  881.                     break;
  882.                 default:
  883.                     return FALSE;}
  884.             break;}
  885.         default:
  886.             return FALSE;}
  887.     return TRUE;
  888. }
  889.  
  890. VOID FAR PASCAL Find()
  891. {    FARPROC lpfn;
  892.     lpfn = MakeProcInstance (FindDlgProc, hInst);
  893.     DialogBox (hInst,"FindBox", hEditWnd, lpfn);
  894.     FreeProcInstance (lpfn);
  895. }