📄 poppad.c
字号:
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- *//* * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is the Netscape Portable Runtime (NSPR). * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998-2000 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL"), in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your * version of this file only under the terms of the GPL and not to * allow others to use your version of this file under the MPL, * indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient * may use your version of this file under either the MPL or the * GPL. *//*--------------------------------------- POPPAD.C -- Popup Editor (c) Charles Petzold, 1992 ---------------------------------------*/#include "nspr.h"#include "plevent.h"#include <windows.h>#include <commdlg.h>#include <stdlib.h>#include "poppad.h"#include <time.h>#define EDITID 1#define UNTITLED "(untitled)"long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG) ;BOOL FAR PASCAL _export AboutDlgProc (HWND, UINT, UINT, LONG) ;/* Declarations for NSPR customization** */typedef struct PadEvent{ PLEvent plEvent; int unused; } PadEvent;static void PR_CALLBACK TimerThread( void *arg);static void PR_CALLBACK HandlePadEvent( PadEvent *padEvent );static void PR_CALLBACK DestroyPadEvent( PadEvent *padevent );static PRThread *tThread;static PLEventQueue *padQueue; static int quitSwitch = 0;static long ThreadSleepTime = 1000;static long timerCount = 0;static char *startMessage = "Poppad: NSPR GUI and event test program.\n" "You should see lines of 50 characters\n" "with a new character appearing at 1 second intervals.\n" "Every 10 seconds gets a '+'; every 5 seconds gets a '_';\n" "every 1 second gets a '.'.\n\n" "You should be able to type in the window.\n\n\n"; // Functions in POPFILE.Cvoid PopFileInitialize (HWND) ;BOOL PopFileOpenDlg (HWND, LPSTR, LPSTR) ;BOOL PopFileSaveDlg (HWND, LPSTR, LPSTR) ;BOOL PopFileRead (HWND, LPSTR) ;BOOL PopFileWrite (HWND, LPSTR) ; // Functions in POPFIND.CHWND PopFindFindDlg (HWND) ;HWND PopFindReplaceDlg (HWND) ;BOOL PopFindFindText (HWND, int *, LPFINDREPLACE) ;BOOL PopFindReplaceText (HWND, int *, LPFINDREPLACE) ;BOOL PopFindNextText (HWND, int *) ;BOOL PopFindValidFind (void) ; // Functions in POPFONT.Cvoid PopFontInitialize (HWND) ;BOOL PopFontChooseFont (HWND) ;void PopFontSetFont (HWND) ;void PopFontDeinitialize (void) ; // Functions in POPPRNT.CBOOL PopPrntPrintFile (HANDLE, HWND, HWND, LPSTR) ; // Global variablesstatic char szAppName [] = "PopPad" ;static HWND hDlgModeless ;static HWND hwndEdit ;int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { MSG msg; HWND hwnd ; HANDLE hAccel ; WNDCLASS wndclass ; PR_STDIO_INIT(); PR_Init(0, 0, 0); if (!hPrevInstance) { wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (hInstance, szAppName) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = szAppName ; wndclass.lpszClassName = szAppName ; RegisterClass (&wndclass) ; } hwnd = CreateWindow (szAppName, NULL, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, lpszCmdLine) ; ShowWindow (hwnd, nCmdShow) ; UpdateWindow (hwnd); hAccel = LoadAccelerators (hInstance, szAppName) ; for(;;) { if ( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE )) { if (GetMessage(&msg, NULL, 0, 0)) { if (hDlgModeless == NULL || !IsDialogMessage (hDlgModeless, &msg)) { if (!TranslateAccelerator (hwnd, hAccel, &msg)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } /* end if !TranslateAccelerator */ } } else { break; } /* end if GetMessage() */ } else /* !PeekMessage */ { PR_Sleep(50); }/* end if PeekMessage() */ } /* end for() */ PR_JoinThread( tThread ); PL_DestroyEventQueue( padQueue ); PR_Cleanup(); return msg.wParam ; }void DoCaption (HWND hwnd, char *szTitleName) { char szCaption [64 + _MAX_FNAME + _MAX_EXT] ; wsprintf (szCaption, "%s - %s", (LPSTR) szAppName, (LPSTR) (szTitleName [0] ? szTitleName : UNTITLED)) ; SetWindowText (hwnd, szCaption) ; }void OkMessage (HWND hwnd, char *szMessage, char *szTitleName) { char szBuffer [64 + _MAX_FNAME + _MAX_EXT] ; wsprintf (szBuffer, szMessage, (LPSTR) (szTitleName [0] ? szTitleName : UNTITLED)) ; MessageBox (hwnd, szBuffer, szAppName, MB_OK | MB_ICONEXCLAMATION) ; }short AskAboutSave (HWND hwnd, char *szTitleName) { char szBuffer [64 + _MAX_FNAME + _MAX_EXT] ; short nReturn ; wsprintf (szBuffer, "Save current changes in %s?", (LPSTR) (szTitleName [0] ? szTitleName : UNTITLED)) ; nReturn = MessageBox (hwnd, szBuffer, szAppName, MB_YESNOCANCEL | MB_ICONQUESTION) ; if (nReturn == IDYES) if (!SendMessage (hwnd, WM_COMMAND, IDM_SAVE, 0L)) nReturn = IDCANCEL ; return nReturn ; }long FAR PASCAL _export WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam) { static BOOL bNeedSave = FALSE ; static char szFileName [_MAX_PATH] ; static char szTitleName [_MAX_FNAME + _MAX_EXT] ; static FARPROC lpfnAboutDlgProc ; static HANDLE hInst ; static int iOffset ; static UINT messageFindReplace ; LONG lSelect ; LPFINDREPLACE lpfr ; WORD wEnable ; switch (message) { case WM_CREATE: // Get About dialog instance address hInst = ((LPCREATESTRUCT) lParam)->hInstance ; lpfnAboutDlgProc = MakeProcInstance ((FARPROC) AboutDlgProc, hInst) ; // Create the edit control child window hwndEdit = CreateWindow ("edit", NULL, WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | WS_BORDER | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0, 0, 0, 0, hwnd, EDITID, hInst, NULL) ; SendMessage (hwndEdit, EM_LIMITTEXT, 32000, 0L) ; // Initialize common dialog box stuff PopFileInitialize (hwnd) ; PopFontInitialize (hwndEdit) ; messageFindReplace = RegisterWindowMessage (FINDMSGSTRING) ; // Process command line lstrcpy (szFileName, (LPSTR) (((LPCREATESTRUCT) lParam)->lpCreateParams)) ; if (lstrlen (szFileName) > 0) { GetFileTitle (szFileName, szTitleName, sizeof (szTitleName)) ; if (!PopFileRead (hwndEdit, szFileName)) OkMessage (hwnd, "File %s cannot be read!", szTitleName) ; } DoCaption (hwnd, szTitleName) ; /* Initialize Event Processing for NSPR ** Retrieve the event queue just created ** Create the TimerThread */ PL_InitializeEventsLib("someName"); padQueue = PL_GetMainEventQueue(); tThread = PR_CreateThread(PR_USER_THREAD, TimerThread, NULL, PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0 ); return 0 ; case WM_SETFOCUS: SetFocus (hwndEdit) ; return 0 ; case WM_SIZE: MoveWindow (hwndEdit, 0, 0, LOWORD (lParam), HIWORD (lParam), TRUE) ; return 0 ; case WM_INITMENUPOPUP: switch (lParam) { case 1: // Edit menu // Enable Undo if edit control can do it EnableMenuItem (wParam, IDM_UNDO, SendMessage (hwndEdit, EM_CANUNDO, 0, 0L) ? MF_ENABLED : MF_GRAYED) ; // Enable Paste if text is in the clipboard EnableMenuItem (wParam, IDM_PASTE, IsClipboardFormatAvailable (CF_TEXT) ? MF_ENABLED : MF_GRAYED) ; // Enable Cut, Copy, and Del if text is selected lSelect = SendMessage (hwndEdit, EM_GETSEL, 0, 0L) ; wEnable = HIWORD (lSelect) != LOWORD (lSelect) ? MF_ENABLED : MF_GRAYED ; EnableMenuItem (wParam, IDM_CUT, wEnable) ; EnableMenuItem (wParam, IDM_COPY, wEnable) ; EnableMenuItem (wParam, IDM_DEL, wEnable) ; break ; case 2: // Search menu // Enable Find, Next, and Replace if modeless // dialogs are not already active
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -