📄 ide_main.c
字号:
case WM_SETFOCUS: SetFocus (hEditWnd); break; case WM_SIZE: MoveWindow(hEditWnd, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE); break; case WM_QUERYENDSESSION: return (QuerySaveFile(hWnd,&cancel)); case WM_CLOSE: { extern HFONT hFont; if (!QuerySaveFile(hWnd,&cancel)) return (FALSE); DestroyWindow(hWnd); DeleteObject ( hFont ); return(TRUE); } case WM_DESTROY: { FreeDDE ( ); PostQuitMessage(0); break; } case WM_INITMENU: if ( wParam == (WPARAM) GetMenu(hWnd)) { if (OpenClipboard(hWnd)) { if (IsClipboardFormatAvailable(CF_TEXT) || IsClipboardFormatAvailable(CF_OEMTEXT)) EnableMenuItem((HMENU) wParam,IDM_EDIT_PASTE,MF_ENABLED); else EnableMenuItem((HMENU) wParam,IDM_EDIT_PASTE,MF_GRAYED); CloseClipboard (); return (TRUE); } else return (FALSE); } return (TRUE); default: return (DefWindowProc(hWnd, message, wParam, lParam)); } return (NULL);}/******************************************************************* DoFileMenu : Processes all Messages for File Menu Item******************************************************************/BOOL DoFileMenu (HWND hWnd, WPARAM wParam ) { long text_length; short cancel; if (! bChanges) { bChanges = SendMessage(hEditWnd,EM_GETMODIFY,(WPARAM) 0, (LPARAM) 0); } /* bChanges = TRUE; */ switch (wParam) { case IDM_FILE_NEW: { extern BOOL bChanges; extern char szFileName[]; /*-----------------------------------+ | If current file has been modified, | | query user about saving it. | +-----------------------------------*/ if (!QuerySaveFile(hWnd,&cancel)) { return (NULL); } /*-----------------------------------------------+ | bChanges is set to FALSE to indicate there | | have been no changes since the last file save. | +-----------------------------------------------*/ bChanges = FALSE; szFileName[0] = 0; /*-----------------------+ | Update the edit buffer | +-----------------------*/ SetNewBuffer(hWnd, // NULL, "Edit File - (untitled)"); EnableMenuItem ( GetMenu(hWnd), IDM_FILE_REVERT, MF_BYCOMMAND | MF_GRAYED); break; } case IDM_FILE_OPEN: { extern OPENFILENAME ofn; if (!QuerySaveFile(hWnd,&cancel)) { return (NULL); } /*-------------------------+ | Use standard open dialog | +-------------------------*/ if (!GetOpenFileName ((LPOPENFILENAME)&ofn)) { return NULL; } EnableMenuItem ( GetMenu(hWnd), IDM_FILE_REVERT, MF_BYCOMMAND | MF_ENABLED); /*-------------------------------------------+ | Fall Through to Revert to Open & Read File | +-------------------------------------------*/ } case IDM_FILE_REVERT: { extern int hFile; extern char szFileTitle[]; extern char szFileName[]; // struct stat FileStatus; // GDR extern HANDLE hEditBuffer; char *pEditBuffer; extern HANDLE hHourGlass; HANDLE hSaveCursor; UINT IOStatus; /*------------------+ | Revert Safety Net | +------------------*/ if ( wParam == IDM_FILE_REVERT ) { if (MessageBox (hWnd,"Revert to Last Saved Document ?","Warning", MB_YESNO | MB_ICONHAND) == IDNO ) { return 0; } } /*---------------------------------+ | Open the file and get its handle | +---------------------------------*/ hFile = OpenFile ((LPSTR)szFileName, (LPOFSTRUCT)&OfStruct, OF_READ); if (! hFile) { return (NULL); } /*-------------------------------------------------+ | Allocate edit buffer to the size of the file + 1 | +-------------------------------------------------*/ text_length = _llseek(hFile,0,2); // GDR _llseek(hFile,0,0); // GDR /* if (fstat(hFile, &FileStatus)) { MessageBox(hWnd, "File not found !", "FILE READ ERROR", MB_OK | MB_ICONEXCLAMATION); close(hFile); return (NULL); } */ // if (FileStatus.st_size > 65534) if (text_length > 65534L) // GDR { MessageBox(hWnd, "Can't load files larger than 65,534 bytes long !", "FILE READ ERROR", MB_OK | MB_ICONEXCLAMATION); _lclose(hFile); return (NULL); } // hEditBuffer = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, // (WORD)FileStatus.st_size+1); pEditBuffer = malloc(text_length+1); // if (!hEditBuffer) if (pEditBuffer == NULL) { MessageBox(hWnd, "Not enough memory.", NULL, MB_OK | MB_ICONEXCLAMATION); _lclose(hFile); return (NULL); } hSaveCursor = SetCursor(hHourGlass); // pEditBuffer = LocalLock(hEditBuffer); // IOStatus = read(hFile, pEditBuffer, (WORD)FileStatus.st_size); IOStatus = _lread(hFile, pEditBuffer, text_length); pEditBuffer[text_length] = '\0'; // close(hFile); _lclose(hFile); // GDR /*----------------------------------+ | # bytes read must equal file size | +----------------------------------*/ if (IOStatus != text_length) { sprintf(szTemp, "Error reading %s tl %ld IO %d.", szFileName, text_length, IOStatus); SetCursor(hSaveCursor); /* Remove the hourglass */ MessageBox(hWnd, szTemp, NULL, MB_OK | MB_ICONEXCLAMATION); } else { SendMessage(hEditWnd,WM_SETTEXT,0,(LPARAM) pEditBuffer); } //LocalUnlock(hEditBuffer); free(pEditBuffer); /*-------------------------------------+ | Set up a new buffer and window title | +-------------------------------------*/ sprintf(szTemp, "Edit File - (%s)", szFileTitle); SetNewBuffer(hWnd, // hEditBuffer, (LPSTR)&szTemp); SetCursor(hSaveCursor); break; } case IDM_FILE_SAVE: { /*------------------------------------------------+ | If there is no filename, use the saveas command | | to get one. Otherwise, save the file using the | | current filename. | +------------------------------------------------*/ extern char szFileName[]; if (szFileName[0]) { extern BOOL bChanges; if (bChanges) { SaveFile(hWnd); } break; } /*-------------------------------------+ | else fall thru for Saveas processing | +-------------------------------------*/ } case IDM_FILE_SAVEAS: { extern OPENFILENAME ofn; extern char szFileTitle[]; char szWindowTitle[80]; /*-------------------------+ | Use standard save dialog | +-------------------------*/ if (!GetSaveFileName ((LPOPENFILENAME)&ofn)) { return FALSE; } /*------------------------------------------+ | Change window title to include file title | +------------------------------------------*/ lstrcpy(szWindowTitle, "CLIPS 6.0 Editor"); lstrcat(szWindowTitle, " - "); lstrcat(szWindowTitle, szFileTitle); SetWindowText(hWnd, szWindowTitle); SaveFile(hWnd); break; } case IDM_FILE_PRINT: return ( PrintFile (hWnd)); case IDM_FILE_SETUP: { extern PRINTDLG pd; DWORD FlagSave; FlagSave = pd.Flags; pd.Flags |= PD_PRINTSETUP; /* Set option */ PrintDlg((LPPRINTDLG)&pd); pd.Flags = FlagSave; /* Remove option */ break; } case IDM_FILE_CLOSE: { if (QuerySaveFile(hWnd,&cancel)) { if (cancel) { return(TRUE); } WinHelp ( hWnd, "CLIPS6.HLP", HELP_QUIT, NULL ); } if (cancel) return(TRUE); DestroyWindow(hWnd); break; } } return TRUE; }/******************************************************************* DoEditMenu : Processes all Messages for Edit Menu Item******************************************************************/DoEditMenu (HWND hWnd, WPARAM wParam, LPARAM lParam ){ extern HWND hEditWnd; switch (wParam) { case IDM_EDIT_UNDO: if(SendMessage(hEditWnd, EM_CANUNDO, 0, 0L)) SendMessage(hEditWnd, EM_UNDO,0,0l); break; case IDM_EDIT_CLEAR: SendMessage(hEditWnd, WM_CLEAR, 0, 0L); break; case IDM_EDIT_CUT: SendMessage(hEditWnd, WM_CUT, 0, 0L); break; case IDM_EDIT_COPY: SendMessage(hEditWnd, WM_COPY, 0, 0L); break; case IDM_EDIT_PASTE: SendMessage(hEditWnd, WM_PASTE, 0, 0L); break; case IDM_EDIT_BALANCE: Balance(hEditWnd); break; case IDM_EDIT_FONT: { extern HWND hwnd; LOGFONT lf; CHOOSEFONT cf; memset ( &cf, 0, sizeof ( CHOOSEFONT) ); cf.lStructSize = sizeof ( CHOOSEFONT ); cf.hwndOwner = hwnd; cf.lpLogFont = &lf; cf.Flags = CF_BOTH; cf.rgbColors = RGB(0,255,255); cf.nFontType = SCREEN_FONTTYPE; if (ChooseFont (&cf )) { extern HFONT hFont; DeleteObject ( hFont ); hFont = CreateFontIndirect (cf.lpLogFont); SendMessage (hEditWnd, WM_SETFONT, (WORD)hFont,(LONG)TRUE); } break; } case IDC_EDIT: { if (HIWORD (lParam) == EN_CHANGE) { extern BOOL bChanges; EnableMenuItem(GetMenu(hWnd), IDM_EDIT_UNDO, MF_ENABLED); bChanges = TRUE; } if (HIWORD (lParam) == EN_ERRSPACE) { MessageBox ( GetFocus (), "Out of memory.", "PrntFile Sample Application", MB_ICONHAND | MB_OK); } break; } } return ( TRUE );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -