📄 ide_main.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* A Product Of The */ /* Software Technology Branch */ /* NASA - Johnson Space Center */ /* */ /* CLIPS Version 6.00 01/01/93 */ /* IDE Text Editor 1.00 01/01/93 */ /* */ /* MAIN MODULE */ /*******************************************************//**************************************************************//* Purpose: For Starting, Maintaining and Stopping a Dymanic *//* Data Exchange (DDE) conversation with a CLIPS Server. *//* *//* Principal Programmer(s): *//* Christopher J. Ortiz *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//**************************************************************//*-------------------------------+| Windows & System Include Files |+-------------------------------*/#include <windows.h>#include <commdlg.h>#include <io.h>#include <stdio.h>#include <string.h>#include <stdlib.h> // GDR#include <sys\stat.h>/*---------------------+| Editor Include Files |+---------------------*/#include "ide_ids.h"#include "ide_main.h" // GDR#include "ide_misc.h"#include "ide_dde.h"#include "ide_bal.h"#include "ide_srch.h"/*-----------------+| Global Variables |+-----------------*/HFONT hFont; /* Handle to the font */HANDLE hAccTable; /* handle to accelerator table */HWND hwnd; /* handle to main window */HWND hEditWnd; /* handle to edit window */HANDLE hInst;HANDLE hHourGlass; /* handle to hourglass cursor */OPENFILENAME ofn; int Log = 0;char szFileName[MAXFILENAME];char szFileTitle[MAXFILENAME];HANDLE hEditBuffer; /* handle to editing buffer */HFILE hFile; /* file handle */OFSTRUCT OfStruct; /* information from OpenFile() */BOOL bChanges = FALSE; /* TRUE if the file is changed */char szTemp[128]; /* Temp Buffer *//*----------------+| Local Functions |+----------------*/DoFileMenu (HWND hWnd, WPARAM wParam );DoEditMenu (HWND hWnd, WPARAM wParam, LPARAM lParam );/******************************************************************* WinMain : Calls initialization function & processes the* message loop******************************************************************/#if IBM_BCC#pragma argsused#endifint PASCAL _export WinMain ( HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ){ extern HWND hwnd; extern HANDLE hAccTable; MSG msg; if (!hPrevInstance) if (!InitApplication(hInstance)) return (FALSE); if (!InitInstance(hInstance, nCmdShow)) return (FALSE); StartUpDDE( hwnd ); while (GetMessage(&msg, NULL, NULL, NULL)) { if (!TranslateAccelerator(hwnd, hAccTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } ShutDownDDE ( ); return (msg.wParam);}/******************************************************************* InitApplication : Initializes window data and registers* the window class ******************************************************************/BOOL InitApplication( HANDLE hInstance ){ WNDCLASS wc; wc.style = NULL; wc.lpfnWndProc = MainWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(hInstance, "Clips_Text"); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1); wc.lpszMenuName = "ClipsEditMenu"; wc.lpszClassName = "ClipsEditWClass"; return (RegisterClass(&wc));}/******************************************************************* InitInstance : Saves instance handle and creates the main window******************************************************************/BOOL InitInstance ( HANDLE hInstance, int nCmdShow ){ extern HWND hEditWnd, hwnd; extern HANDLE hInst; extern HANDLE hAccTable; RECT Rect; hInst = hInstance; hAccTable = LoadAccelerators(hInst, "ClipsAcc"); hwnd = CreateWindow ( "ClipsEditWClass", "Edit File - (untitled)", WS_OVERLAPPEDWINDOW, 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); if (!hwnd) return (FALSE); GetClientRect(hwnd, (LPRECT) &Rect); /*----------------------------+ |Create a child editor window | +----------------------------*/ hEditWnd = CreateWindow ( "Edit", "", ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP, 0, 0, (Rect.right-Rect.left), (Rect.bottom-Rect.top), hwnd, (HMENU) IDC_EDIT, hInst, NULL ); if (!hEditWnd) { DestroyWindow(hwnd); return (NULL); } /*-----------------------------------------------------+ | Get an hourglass cursor to use during file transfers | +-----------------------------------------------------*/ { extern HANDLE hHourGlass; hHourGlass = LoadCursor(NULL, IDC_WAIT); } /*---------------------------------------------------+ | fill in non-variant fields of OPENFILENAME struct. | +---------------------------------------------------*/ { extern char szFileName[]; extern char szFileTitle[]; extern OPENFILENAME ofn; ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "CLIPS Files (*.CLP)\0*.CLP\0Batch Files (*.BAT)\0*.BAT\0All Files (*.*)\0*.*\0"; ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = 0; ofn.nFilterIndex = 1; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAXFILENAME; ofn.lpstrInitialDir = NULL; ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = MAXFILENAME; ofn.lpstrTitle = NULL; ofn.lpstrDefExt = "CLP"; ofn.Flags = 0; } /*-----------------------------------------------+ | fill in non-variant fields of PRINTDLG struct. | +-----------------------------------------------*/ { extern PRINTDLG pd; pd.lStructSize = sizeof(PRINTDLG); pd.hwndOwner = hwnd; pd.hDevMode = NULL; pd.hDevNames = NULL; pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS; pd.nCopies = 1; } /*-------------------------+ | Set Font to a Fixed Font | +-------------------------*/ { extern HFONT hFont; hFont = GetStockObject(SYSTEM_FIXED_FONT); SendMessage(hEditWnd, WM_SETFONT, (WPARAM) GetStockObject(SYSTEM_FIXED_FONT), 0L); } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); /*-----------------------+ | Setup for Find Replace | +-----------------------*/ { extern FINDREPLACE fr; extern char SearchFor[]; extern char ReplaceWith[]; extern UINT uFindReplaceMsg; uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING); memset ( &SearchFor, '\0', 255 ); memset ( &ReplaceWith, '\0', 255 ); memset ( &fr, 0, sizeof ( FINDREPLACE ) ); fr.lStructSize = sizeof ( FINDREPLACE ); fr.hwndOwner = hwnd; fr.lpstrFindWhat = (LPSTR) &SearchFor; fr.lpstrReplaceWith = (LPSTR) &ReplaceWith; fr.wFindWhatLen = 255; fr.wReplaceWithLen = 255; fr.Flags = FR_HIDEUPDOWN | FR_HIDEWHOLEWORD ; } return (TRUE);}/******************************************************************* MainWndProc : Processes all Messages for Editor Application.******************************************************************/long FAR PASCAL _export MainWndProc ( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ){ extern UINT uFindReplaceMsg; extern HWND hEditWnd; /* handle to edit window */ short cancel; /*-------------------------------------+ | Process the Find and Replace Message | +-------------------------------------*/ if ( message == uFindReplaceMsg ) return StartSearch (hWnd, wParam, lParam ); switch (message) { case WM_COMMAND: { wParam = LOWORD(wParam); // GDR switch (wParam) { case 0x00DA: SendMessage (hEditWnd,WM_CHAR,VK_BACK,0L); break; case 0x00E0: SendMessage (hEditWnd,WM_CHAR,VK_RETURN,0L); break; /*-------------------+ | FILE menu commands | +-------------------*/ case IDM_FILE_NEW: case IDM_FILE_OPEN: case IDM_FILE_REVERT: case IDM_FILE_SAVE: case IDM_FILE_SAVEAS: case IDM_FILE_PRINT: case IDM_FILE_SETUP: case IDM_FILE_CLOSE: return DoFileMenu ( hWnd, wParam ); /*-------------------+ | EDIT menu commands | +-------------------*/ case IDM_EDIT_UNDO: case IDM_EDIT_CLEAR: case IDM_EDIT_CUT: case IDM_EDIT_COPY: case IDM_EDIT_PASTE: case IDM_EDIT_BALANCE: case IDM_EDIT_FONT: case IDC_EDIT: return DoEditMenu (hWnd, wParam, lParam ); /*---------------------+ | BUFFER menu commands | +---------------------*/ case IDM_BUFFER_FIND: { SetUpSearch ( hWnd, 0 ); break; } case IDM_BUFFER_REPLACE: { SetUpSearch ( hWnd, 1 ); break; } case IDM_BUFFER_BATCH: case IDM_HELP_COMPLETE: case IDM_EDIT_COMPLETE: case IDM_BUFFER_LOAD: case IDM_BUFFER_LBUF: return MessageDDE( wParam ); case IDM_HELP_CLIPS: { WinHelp ( hWnd, "CLIPS6.HLP", HELP_INDEX, NULL ); break; } /*-------------------+ | ABOUT menu command | +-------------------*/ case IDM_ABOUT: { extern HANDLE hInst; FARPROC lpProcAbout;#if WIN_32 lpProcAbout = About;#else lpProcAbout = MakeProcInstance(About, hInst);#endif DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);#if ! WIN_32 FreeProcInstance(lpProcAbout);#endif break; } } break; } case WM_INITMENUPOPUP: { extern HCONV hConv; DWORD sel = SendMessage(hEditWnd,EM_GETSEL,0,0L); int len = HIWORD(sel) - LOWORD(sel); UINT Flags = MF_BYCOMMAND|MF_GRAYED; HMENU hMenu = GetMenu(hWnd); if ( (len > 0) && (hConv != NULL) ) Flags = MF_BYCOMMAND|MF_ENABLED; EnableMenuItem(hMenu, IDM_BUFFER_LOAD, Flags); EnableMenuItem(hMenu, IDM_BUFFER_BATCH,Flags); break; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -