edit.c
上传用户:jlteech
上传日期:2007-01-06
资源大小:349k
文件大小:6k
源码类别:

压缩解压

开发平台:

Visual C++

  1. /* edit.c -- the editor module of WiZ
  2.  * Author Mike White
  3.  */
  4. #include "wiz.h"
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <time.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include <io.h>
  11. #include <stdio.h>
  12. #include <stdarg.h>
  13. HMENU hStaticMenu;
  14. LRESULT WINAPI StaticWndProc(HWND hWnd, WORD wMessage, WPARAM wParam, LPARAM lParam)
  15. {
  16. RECT rectT;
  17. switch (wMessage)
  18.     {
  19.     case WM_SIZE:
  20.         GetClientRect(hWndStatic, &rectT);
  21.         MoveWindow(hWndEdit,
  22.                 rectT.left, rectT.top,
  23.                 rectT.right, rectT.bottom,
  24.                 FALSE);
  25.         ShowWindow(hWndEdit, SW_SHOW);
  26.         break;
  27.     case WM_INITMENU:
  28.       {
  29.         UINT fEnable;
  30.         UINT ichStart, ichEnd;
  31.       hStaticMenu = GetMenu(hWndStatic);
  32.         if (!hStaticMenu)
  33.             return 0;
  34.         fEnable = (UINT)SendMessage(hWndEdit, EM_CANUNDO, 0, 0);
  35.         EnableMenuItem(hStaticMenu, IDM_EDIT_UNDO,
  36.                     (fEnable ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  37.         /* Can we paste from the clipboard? */
  38.         if (OpenClipboard(hWnd))
  39.            {
  40.            /* Only allow text */
  41.            if (IsClipboardFormatAvailable(CF_TEXT) ||
  42.               IsClipboardFormatAvailable(CF_OEMTEXT))
  43.               fEnable = TRUE;
  44.            else
  45.               fEnable = FALSE;
  46.            }
  47.         CloseClipboard();
  48.         EnableMenuItem(hStaticMenu, IDM_EDIT_PASTE,
  49.                     (fEnable ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  50.         SendMessage(hWndEdit, EM_GETSEL, (WPARAM)&ichStart, (LPARAM)&ichEnd);
  51.         fEnable = (ichStart != ichEnd);
  52.         EnableMenuItem(hStaticMenu, IDM_EDIT_CUT,
  53.                 (fEnable ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  54.         EnableMenuItem(hStaticMenu, IDM_EDIT_COPY,
  55.                 (fEnable ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  56.         EnableMenuItem(hStaticMenu, IDM_EDIT_DELETE,
  57.                 (fEnable ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  58.         fEnable = (UINT)SendMessage(hWndEdit, WM_GETTEXTLENGTH, 0, 0);
  59.         EnableMenuItem(hStaticMenu, IDM_EDIT_SELECT_ALL,
  60.                 (fEnable ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  61.         EnableMenuItem(hStaticMenu, IDM_CLEAR_STATUS,
  62.                 (fEnable ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  63.         EnableMenuItem(hStaticMenu, IDM_EDIT_SAVE_AS,
  64.                 (fEnable ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  65.       }
  66.       break;
  67.      case WM_COMMAND:
  68.         switch (LOWORD(wParam))
  69.             {
  70.             case IDM_EDIT_OPEN_FILE:
  71.                 SendMessage(hWndMain, WM_COMMAND, (WPARAM)IDM_EDIT_OPEN_FILE, 0);
  72.                 break;
  73.             case IDM_EDIT_SAVE_AS:
  74.                 SendMessage(hWndMain, WM_COMMAND, (WPARAM)IDM_EDIT_SAVE_AS, 0);
  75.                 break;
  76.             case IDM_EDIT_UNDO:
  77.                 SendMessage(hWndEdit, EM_UNDO, 0, 0);
  78.                 break;
  79.             case IDM_EDIT_CUT:
  80.                 SendMessage(hWndEdit, WM_CUT, 0, 0);
  81.                 break;
  82.             case IDM_EDIT_COPY:
  83.                 SendMessage(hWndEdit, WM_COPY, 0, 0);
  84.                 break;
  85.             case IDM_EDIT_PASTE:
  86.                 SendMessage(hWndEdit, WM_PASTE, 0, 0);
  87.                 break;
  88.             case IDM_EDIT_DELETE:
  89.                 SendMessage(hWndEdit, WM_CLEAR, 0, 0);
  90.                 break;
  91.             case IDM_EDIT_SELECT_ALL:
  92.                 SendMessage(hWndEdit, EM_SETSEL, (WPARAM)0,
  93.                         (LPARAM)MAKELPARAM(0,-1));
  94.             break;
  95.          case IDM_CLEAR_STATUS:  
  96.                 SendMessage(hWndEdit, WM_COMMAND, IDM_CLEAR_STATUS, 0L);
  97.                 break;
  98.             default:
  99.                 return DefWindowProc(hWnd, wMessage, wParam, lParam);
  100.          }
  101.     default:
  102.         return DefWindowProc(hWnd, wMessage, wParam, lParam);
  103.     }
  104. return DefWindowProc(hWnd, wMessage, wParam, lParam);
  105. }
  106. extern FARPROC lpOldEditProc;
  107. LRESULT CALLBACK SubClassEditProc(HWND hWnd, WORD message, WPARAM wParam, LPARAM lParam)
  108. {
  109. switch (message)
  110.     {
  111.    case WM_COMMAND:
  112.         switch (LOWORD(wParam))
  113.             {
  114.             case IDM_EDIT_UNDO:
  115.                 SendMessage(hWndEdit, EM_UNDO, 0, 0);
  116.                 break;
  117.             case IDM_EDIT_CUT:
  118.                 SendMessage(hWndEdit, WM_CUT, 0, 0);
  119.                 break;
  120.             case IDM_EDIT_COPY:
  121.                 SendMessage(hWndEdit, WM_COPY, 0, 0);
  122.                 break;
  123.             case IDM_EDIT_PASTE:
  124.                 SendMessage(hWndEdit, WM_PASTE, 0, 0);
  125.                 break;
  126.             case IDM_EDIT_DELETE:
  127.                 SendMessage(hWndEdit, WM_CLEAR, 0, 0);
  128.                 break;
  129.             case IDM_EDIT_SELECT_ALL:
  130.                 SendMessage(hWndEdit, EM_SETSEL, (WPARAM)0,
  131.                         (LPARAM)MAKELPARAM(0,-1));
  132.                 break;
  133.             case IDM_CLEAR_STATUS:
  134.                 {
  135. #ifdef WIN32
  136.                 HGLOBAL hTemp;
  137.                 PARAFORMAT pf;
  138. #endif
  139.                 SetWindowText(hWndStatic, "WiZ Edit/Status Window");
  140. #ifdef WIN32
  141.                 /* Reallocate the editor buffer to original size */
  142.                 GlobalUnlock(hEditor);
  143.                 hTemp = GlobalReAlloc(hEditor, EDIT_BUF_SIZE, GMEM_MOVEABLE);
  144.                 if (hTemp)
  145.                    {
  146.                    hEditor = hTemp;
  147.                    dwEditBufSize = EDIT_BUF_SIZE;
  148.                    }
  149.                 pszBuffer = GlobalLock(hEditor);
  150.                 SendMessage(hWndEdit, EM_EXLIMITTEXT, (WPARAM)0,
  151.                    (LPARAM)dwEditBufSize);
  152.                 memset(pszBuffer, '', dwEditBufSize);
  153. #else
  154.                 _fmemset(pszBuffer, '', (unsigned int)dwEditBufSize);
  155. #endif
  156.                 SendMessage(hWndEdit, WM_SETTEXT, 0, (LPARAM) pszBuffer);
  157. #ifdef WIN32
  158.                 /* Insure alignment is set to left. Clearing sometimes seems
  159.                    to cause centering with rich edit controls.
  160.                  */
  161.                 pf.cbSize = sizeof(PARAFORMAT);
  162.                 SendMessage(hWndEdit, EM_GETPARAFORMAT, 0, (LPARAM) &pf);
  163.                 pf.dwMask = PFM_ALIGNMENT;     // only change the alignment
  164.                 pf.wAlignment = PFA_LEFT;
  165.                 SendMessage(hWndEdit, EM_SETPARAFORMAT, 0, (LPARAM) &pf);
  166. #endif
  167.                 break;
  168.                 }
  169.             default:
  170.                 return DefWindowProc(hWnd, message, wParam, lParam);
  171.          }
  172.       }
  173. return (CallWindowProc((FARPROC)(lpOldEditProc), hWnd, message, wParam, lParam));
  174. }