📄 main.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* A */ /* Of The */ /* Software Technology Branch */ /* NASA - Johnson Space Center */ /* */ /* CLIPS Version 6.00 10/01/92 */ /* */ /* MAIN MODULE */ /*******************************************************//************************************************************ Purpose: Initalizing and Maintaining the Interface windows * and main menu items during execution.* * Principal Programmer(s): * Christopher J. Ortiz * * Contributing Programmer(s): * Gary Riley* * Revision History: *************************************************************//*-------------------------------+| Windows & System Include Files |+-------------------------------*/#include <windows.h>#undef CopyMemory#include <stdlib.h> #include <ctype.h> // Remove later#include <stdio.h>#include <string.h>#include <time.h> // Remove later/*------------------------+| CLIPS 6.0 Include Files |+------------------------*/#include "setup.h"#include "commline.h"#include "extnfunc.h"#include "sysdep.h"#include "utility.h"#include "engine.h"#include "clipsmem.h"#include "argacces.h"#include "router.h"#include "memory.h"/*------------------------+| Interface Include Files |+------------------------*/#include "ids.h"#include "dialog.h"#include "commdlg.h"#include "status.h"#include "memory.h"#include "main.h"#include "diag_win.h"#include "menucmds.h"HCURSOR NowCursor; /* Current Cursor */HANDLE hAccTable;HANDLE hInst= NULL;HCURSOR ARROW, QUERY;HCURSOR WAIT[10];int ShiftKeyDown;int ApplicationFocus = 0;/*-----------------+| Local Procedures |+-----------------*/BOOL InitApplication (HANDLE);BOOL InitInstance( HANDLE, int);VOID SetUpRouters ( VOID );int QueryFunction (char*);int GetCFunction(char*);int SetJoeWarningsCommand ( VOID );int WinWaitEvent ( VOID );static VOID InitializeKeywords( VOID );VOID DefineWinFunctions ( VOID );int ExitFunction ( int );int SetCompletionDialogCommand( VOID );int WinOutOfMemoryFunction( unsigned long int );int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);VOID WinHelp2 ( VOID );/**************************************************************** WinMAIN: Start execution of CLIPS. This function must be* redefined in order to embed CLIPS within another program. * Example of redefined main:* main()* { * init_clips(); * . * . * . * process_data(); * RunCLIPS(-1);* evaluate_data(); * . * . * . * final_results(); * } ***************************************************************/#if IBM_TBC#pragma argsused#endifint PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow) HANDLE hInstance; HANDLE hPrevInstance; LPSTR lpCmdLine; int nCmdShow;{ extern HWND hDialogWnd; extern HANDLE hAccTable; /* FILE *theFile; time_t tp; struct tm *lt; char *theTime; theFile = fopen("x.txt","w"); if (theFile == NULL) return; time(&tp); lt = localtime(&tp); theTime = asctime(lt); fprintf(theFile,"%s\n",theTime); if (isalpha('(')) { fprintf(theFile,"2 is alpha\n"); } else { fprintf(theFile,"2 is not alpha\n"); } fclose(theFile); exit(1); */ /*----------------------------------+ | Check Windows Version Information | +---------------------------------*/ { int Version = LOBYTE(LOWORD( GetVersion()))*100 + HIBYTE(LOWORD( GetVersion())); if ( Version < 310 ) { MessageBeep (0); MessageBox ( NULL, "CLIPS Needs Windows 3.1 or Higher "," Version Error", MB_ICONHAND | MB_OK ); return ( TRUE ); } } InitializeCLIPS(); /*-------------------------------------------------+ | Load Accelerator table and Initalize Application | +-------------------------------------------------*/ hAccTable = LoadAccelerators (hInstance, "Main_Accelerator"); if (!hPrevInstance) if (!InitApplication(hInstance)) return (FALSE); /*-------------------+ | Initalize Instance | +-------------------*/ if (!InitInstance(hInstance, nCmdShow)) return (FALSE); /*--------------------------------+ | setup routers for the interface | +--------------------------------*/ SetUpRouters (); /*-------------------------------+ | Create Terminal Data Structure | +-------------------------------*/ CreateTerminal (); /*----------------------------------+ | Set up hook between CLIPS command | | loop and interface event loop. | +----------------------------------*/ SetEventFunction((int(*)())WinWaitEvent); /*------------------------------------+ | Add execution functions to update | | the interface between rule firings. | +------------------------------------*/ AddPeriodicFunction("status_wnd", WinRunEvent ,0);#if DEFRULE_CONSTRUCT AddRunFunction ("run_function", WinRunEvent, 0);#endif /*------------------------------------------------------------+ | Change the functions to be called when CLIPS is out of | | memory, CLIPS preforms a reset, and CLIPS preforms a clear. | +------------------------------------------------------------*/ SetOutOfMemoryFunction ( WinOutOfMemoryFunction ); /*---------------------------------+ / Add Interface specific functions | +---------------------------------*/ InitializeKeywords(); DefineWinFunctions(); EnableStatusWindows(); /*------------------------------------------------------+ | Get message and dispatch it to the appropriate window | +------------------------------------------------------*/ CommandLoop(); return (TRUE);}/******************************************************************** InitApplication: function creates & registers window classes for* subsequent use in calls to the CreateWindow function.* Performs any initialization necessary only for the first* executing instance of the application.*******************************************************************/BOOL InitApplication(hInstance) HANDLE hInstance;{ WNDCLASS dialog; WNDCLASS status; dialog.style = CS_CLASSDC | CS_VREDRAW | CS_HREDRAW; dialog.lpfnWndProc = (WNDPROC) DialogWndProc; dialog.cbClsExtra = 0; dialog.cbWndExtra = 0; dialog.hInstance = hInstance; dialog.hIcon = LoadIcon(hInstance, "Clips_Icon"); dialog.hCursor = LoadCursor ( NULL, IDC_ARROW); dialog.hbrBackground = GetStockObject(WHITE_BRUSH); dialog.lpszMenuName ="MainMenu"; dialog.lpszClassName = "DialogWClass"; if (!(RegisterClass(&dialog))) return (FALSE); status.style = CS_CLASSDC | CS_HREDRAW | CS_VREDRAW; status.lpfnWndProc = (WNDPROC) StatusWndProc; status.cbClsExtra = 0; status.cbWndExtra = 0; status.hInstance = hInstance; status.hIcon = LoadIcon(hInstance, "Clips_Icon"); status.hCursor = NULL; status.hbrBackground = GetStockObject(WHITE_BRUSH); status.lpszMenuName = NULL; status.lpszClassName = "StatusWClass"; return (RegisterClass(&status));}/**************************************************************** InitInstance: Creates & Displays all the necessary windows* as well as loading all cursor resources. * Performs any initialization necessary for every executing* instance of the application.****************************************************************/BOOL InitInstance(hInstance, nCmdShow) HANDLE hInstance; int nCmdShow;{ extern HANDLE hInst; /* Handle to instance data*/ extern HWND hInstWnd; /* Handle to Instance window */ TEXTMETRIC tm; extern SCREEN WinDialog, WinFact; extern SCREEN WinAgenda; extern SCREEN WinGlobal, WinInst, WinFocus; HDC hDC; int width = GetSystemMetrics ( SM_CXSCREEN ); int height = GetSystemMetrics ( SM_CYSCREEN ); RECT ClientRect; hInst = hInstance;#if CLP_HELP /*-----------------------+ | Find the path for Help | +-----------------------*/ { extern char *help_file; char HelpPath [255]; int size,x ; if ( help_file != NULL ) genfree ( help_file, strlen (help_file) ); GetModuleFileName(hInst,(LPSTR) &HelpPath, 254); HelpPath [strlen ( HelpPath ) - 12] = '\0'; strcat ( HelpPath, "CLIPS.HLP\0"); for ( x=0; x< strlen(HelpPath); x++) if ( HelpPath[x] == '\\' ) HelpPath[x] = '/'; size = strlen( HelpPath ) + 1; help_file = (char *) genalloc ( size ); strncpy ( help_file, HelpPath, size ); }#endif /*--------------+ | Dialog Window | +--------------*/ WinDialog.hWnd = CreateWindow( "DialogWClass", "CLIPS 6.0", WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_VSCROLL | WS_HSCROLL, 0,0, (width * .66)-5,(height * .66)-5, NULL, NULL, hInstance, (LPSTR) NULL ); if (!WinDialog.hWnd) return (FALSE); hDC = GetDC ( WinDialog.hWnd ); SelectObject (hDC, GetStockObject(SYSTEM_FIXED_FONT)); GetTextMetrics ( hDC, &tm ); ReleaseDC ( WinDialog.hWnd, hDC ); GetClientRect ( WinDialog.hWnd, (LPRECT) &ClientRect ); WinDialog.LastLine = 0; WinDialog.LineSize = tm.tmHeight+ tm.tmExternalLeading; WinDialog.NoLines = (ClientRect.bottom / WinDialog.LineSize)-1; ShowWindow(WinDialog.hWnd, nCmdShow );#if DEFTEMPLATE_CONSTRUCT /*------------+ | Fact Window | +------------*/ WinFact.hWnd = CreateWindow( "StatusWClass", NULL, WS_THICKFRAME | WS_MAXIMIZEBOX | WS_CAPTION | WS_VSCROLL | WS_HSCROLL, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); if (!WinFact.hWnd) return (FALSE); hDC = GetDC ( WinFact.hWnd); SelectObject (hDC, GetStockObject(SYSTEM_FIXED_FONT)); GetTextMetrics(hDC, &tm); ReleaseDC ( WinFact.hWnd, hDC ); WinFact.LineSize = tm.tmHeight+ tm.tmExternalLeading; WinFact.NoLines = 0; ShowWindow(WinFact.hWnd, SW_HIDE );#endif#if OBJECT_SYSTEM /*----------------+ | Instance Window | +----------------*/ WinInst.hWnd = CreateWindow( "StatusWClass", NULL, WS_THICKFRAME | WS_MAXIMIZEBOX | WS_CAPTION | WS_VSCROLL | WS_HSCROLL, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); if (!WinInst.hWnd) return (FALSE); hDC = GetDC ( WinInst.hWnd); SelectObject (hDC, GetStockObject(SYSTEM_FIXED_FONT)); GetTextMetrics(hDC, &tm); ReleaseDC ( WinInst.hWnd, hDC ); WinInst.LineSize = ( tm.tmHeight + tm.tmExternalLeading ); WinInst.NoLines = 0; ShowWindow(WinInst.hWnd, SW_HIDE );#endif#if DEFGLOBAL_CONSTRUCT /*---------------+ | Globals Window | +---------------*/ WinGlobal.hWnd = CreateWindow( "StatusWClass", NULL, WS_THICKFRAME | WS_MAXIMIZEBOX | WS_CAPTION | WS_VSCROLL | WS_HSCROLL, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); if (!WinGlobal.hWnd) return (FALSE); hDC = GetDC ( WinGlobal.hWnd); SelectObject (hDC, GetStockObject(SYSTEM_FIXED_FONT)); GetTextMetrics(hDC, &tm); ReleaseDC ( WinGlobal.hWnd, hDC ); WinGlobal.LineSize = ( tm.tmHeight + tm.tmExternalLeading ); WinGlobal.NoLines = 0; ShowWindow(WinGlobal.hWnd, SW_HIDE );#endif#if DEFRULE_CONSTRUCT /*--------------+ | Agenda Window | +--------------*/ WinAgenda.hWnd = CreateWindow( "StatusWClass", NULL, WS_THICKFRAME | WS_MAXIMIZEBOX | WS_CAPTION | WS_VSCROLL | WS_HSCROLL, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); if (!WinAgenda.hWnd) return (FALSE); hDC = GetDC ( WinAgenda.hWnd); SelectObject (hDC, GetStockObject(SYSTEM_FIXED_FONT)); GetTextMetrics(hDC, &tm); ReleaseDC ( WinAgenda.hWnd, hDC ); WinAgenda.LineSize = ( tm.tmHeight + tm.tmExternalLeading ); WinAgenda.NoLines = 0; ShowWindow(WinAgenda.hWnd, SW_HIDE );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -