ReactOS 0.4.16-dev-329-g9223134
main.c File Reference
#include "notepad.h"
#include <shlobj.h>
#include <strsafe.h>
Include dependency graph for main.c:

Go to the source code of this file.

Functions

VOID NOTEPAD_EnableSearchMenu ()
 
VOID SetFileName (LPCTSTR szFileName)
 
static int NOTEPAD_MenuCommand (WPARAM wParam)
 
static BOOL NOTEPAD_FindTextAt (FINDREPLACE *pFindReplace, LPCTSTR pszText, INT iTextLength, DWORD dwPosition)
 
BOOL NOTEPAD_FindNext (FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bShowAlert)
 
static VOID NOTEPAD_ReplaceAll (FINDREPLACE *pFindReplace)
 
static VOID NOTEPAD_FindTerm (VOID)
 
static VOID NOTEPAD_InitData (HINSTANCE hInstance)
 
static VOID NOTEPAD_InitMenuPopup (HMENU menu, LPARAM index)
 
LRESULT CALLBACK EDIT_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
static LRESULT WINAPI NOTEPAD_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
static int AlertFileDoesNotExist (LPCTSTR szFileName)
 
static BOOL HandleCommandLine (LPTSTR cmdline)
 
int WINAPI _tWinMain (HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int show)
 

Variables

NOTEPAD_GLOBALS Globals
 
static ATOM aFINDMSGSTRING
 

Function Documentation

◆ _tWinMain()

int WINAPI _tWinMain ( HINSTANCE  hInstance,
HINSTANCE  prev,
LPTSTR  cmdline,
int  show 
)

Definition at line 555 of file main.c.

556{
557 MSG msg;
558 HACCEL hAccel;
559 WNDCLASSEX wndclass;
561 static const TCHAR className[] = _T("Notepad");
562 static const TCHAR winName[] = _T("Notepad");
563
564 switch (GetUserDefaultUILanguage())
565 {
568 break;
569
570 default:
571 break;
572 }
573
575
577
580
581 ZeroMemory(&wndclass, sizeof(wndclass));
582 wndclass.cbSize = sizeof(wndclass);
583 wndclass.lpfnWndProc = NOTEPAD_WndProc;
584 wndclass.hInstance = Globals.hInstance;
586 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
587 wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
589 wndclass.lpszClassName = className;
590 wndclass.hIconSm = (HICON)LoadImage(hInstance,
595 0);
596 if (!RegisterClassEx(&wndclass))
597 {
599 return 1;
600 }
601
602 /* Globals.hMainWnd will be set in WM_CREATE handling */
603 CreateWindow(className,
604 winName,
610 NULL,
611 NULL,
613 NULL);
614 if (!Globals.hMainWnd)
615 {
617 return 1;
618 }
619
620 /* Use the result of CW_USEDEFAULT if the data in the registry is not valid */
622 {
624 }
625 /* Does the parent process want to force a show action? */
626 if (show != SW_SHOWDEFAULT)
627 {
628 wp.showCmd = show;
629 }
632
634 return 0;
635
637
638 while (GetMessage(&msg, NULL, 0, 0))
639 {
640 if ((!Globals.hFindReplaceDlg || !IsDialogMessage(Globals.hFindReplaceDlg, &msg)) &&
642 {
645 }
646 }
647
649
650 return (int) msg.wParam;
651}
#define msg(x)
Definition: auth_time.c:54
#define MAIN_MENU
Definition: resources.h:12
#define ID_ACCEL
Definition: resources.h:13
VOID ShowLastError(VOID)
Definition: dialog.c:45
static BOOL HandleCommandLine(LPTSTR cmdline)
Definition: main.c:463
static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: main.c:330
static VOID NOTEPAD_InitData(HINSTANCE hInstance)
Definition: main.c:243
static ATOM aFINDMSGSTRING
Definition: main.c:18
OSK_GLOBALS Globals
Definition: main.c:16
HINSTANCE hInstance
Definition: charmap.c:19
#define FINDMSGSTRING
Definition: commdlg.h:653
WORD ATOM
Definition: dimm.idl:113
#define NULL
Definition: types.h:112
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: locale.c:1375
HACCEL hAccel
Definition: main.c:47
static HICON
Definition: imagelist.c:80
void NOTEPAD_LoadSettingsFromRegistry(PWINDOWPLACEMENT pWP)
Definition: settings.c:105
#define IDI_NPICON
Definition: notepad_res.h:19
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define MAKELANGID(p, s)
Definition: nls.h:15
#define LANG_HEBREW
Definition: nls.h:67
#define SUBLANG_DEFAULT
Definition: nls.h:168
TCHAR * cmdline
Definition: stretchblt.cpp:32
HINSTANCE hInstance
Definition: precomp.h:52
HWND hMainWnd
Definition: precomp.h:53
RECT rcNormalPosition
Definition: winuser.h:3298
HINSTANCE hInstance
Definition: winuser.h:3209
HCURSOR hCursor
Definition: winuser.h:3211
LPCSTR lpszMenuName
Definition: winuser.h:3213
HICON hIconSm
Definition: winuser.h:3215
UINT cbSize
Definition: winuser.h:3204
WNDPROC lpfnWndProc
Definition: winuser.h:3206
LPCSTR lpszClassName
Definition: winuser.h:3214
HICON hIcon
Definition: winuser.h:3210
HBRUSH hbrBackground
Definition: winuser.h:3212
LONG right
Definition: windef.h:308
LONG left
Definition: windef.h:306
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define _T(x)
Definition: vfdio.h:22
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1691
#define ZeroMemory
Definition: winbase.h:1737
#define LAYOUT_RTL
Definition: wingdi.h:1371
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define COLOR_WINDOW
Definition: winuser.h:921
#define IsDialogMessage
Definition: winuser.h:5821
#define IMAGE_ICON
Definition: winuser.h:212
BOOL WINAPI GetWindowPlacement(_In_ HWND, _Inout_ WINDOWPLACEMENT *)
#define IDC_ARROW
Definition: winuser.h:687
#define SM_CYSMICON
Definition: winuser.h:1016
#define CreateWindow
Definition: winuser.h:5766
#define SW_SHOWDEFAULT
Definition: winuser.h:783
#define GetMessage
Definition: winuser.h:5802
#define SM_CXSMICON
Definition: winuser.h:1015
#define RegisterClassEx
Definition: winuser.h:5849
#define RegisterWindowMessage
Definition: winuser.h:5852
#define LoadIcon
Definition: winuser.h:5825
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5824
#define CW_USEDEFAULT
Definition: winuser.h:225
#define LoadImage
Definition: winuser.h:5827
#define DispatchMessage
Definition: winuser.h:5777
BOOL WINAPI DestroyAcceleratorTable(_In_ HACCEL)
#define TranslateAccelerator
Definition: winuser.h:5872
BOOL WINAPI SetWindowPlacement(_In_ HWND hWnd, _In_ const WINDOWPLACEMENT *)
#define MAKEINTRESOURCE
Definition: winuser.h:591
int WINAPI GetSystemMetrics(_In_ int)
#define LoadAccelerators
Definition: winuser.h:5822
char TCHAR
Definition: xmlstorage.h:189

◆ AlertFileDoesNotExist()

static int AlertFileDoesNotExist ( LPCTSTR  szFileName)
static

Definition at line 456 of file main.c.

457{
459 szFileName,
461}
int DIALOG_StringMsgBox(HWND hParent, int formatId, LPCTSTR szString, DWORD dwFlags)
Definition: dialog.c:193
#define STRING_DOESNOTEXIST
Definition: notepad_res.h:72
#define MB_YESNO
Definition: winuser.h:820
#define MB_ICONEXCLAMATION
Definition: winuser.h:788

Referenced by HandleCommandLine().

◆ EDIT_WndProc()

LRESULT CALLBACK EDIT_WndProc ( HWND  hWnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 294 of file main.c.

295{
296 switch (msg)
297 {
298 case WM_KEYDOWN:
299 case WM_KEYUP:
300 {
301 switch (wParam)
302 {
303 case VK_UP:
304 case VK_DOWN:
305 case VK_LEFT:
306 case VK_RIGHT:
308 break;
309 default:
310 {
312 break;
313 }
314 }
315 }
316 case WM_LBUTTONUP:
317 {
319 break;
320 }
321 }
322 return CallWindowProc( Globals.EditProc, hWnd, msg, wParam, lParam);
323}
HWND hWnd
Definition: settings.c:17
VOID DIALOG_StatusBarUpdateCaretPos(VOID)
Definition: dialog.c:931
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define FALSE
Definition: types.h:117
void UpdateWindowCaption(HWND hwnd)
Definition: mplay32.c:102
#define WM_KEYUP
Definition: winuser.h:1719
#define CallWindowProc
Definition: winuser.h:5747
#define VK_UP
Definition: winuser.h:2228
#define WM_LBUTTONUP
Definition: winuser.h:1780
#define VK_LEFT
Definition: winuser.h:2227
#define VK_RIGHT
Definition: winuser.h:2229
#define VK_DOWN
Definition: winuser.h:2230
#define WM_KEYDOWN
Definition: winuser.h:1718

Referenced by DoCreateEditWindow().

◆ HandleCommandLine()

static BOOL HandleCommandLine ( LPTSTR  cmdline)
static

Definition at line 463 of file main.c.

464{
465 BOOL opt_print = FALSE;
467
468 while (*cmdline == _T(' ') || *cmdline == _T('-') || *cmdline == _T('/'))
469 {
471
472 if (*cmdline++ == _T(' ')) continue;
473
474 option = *cmdline;
475 if (option) cmdline++;
476 while (*cmdline == _T(' ')) cmdline++;
477
478 switch(option)
479 {
480 case 'p':
481 case 'P':
482 opt_print = TRUE;
483 break;
484 }
485 }
486
487 if (*cmdline)
488 {
489 /* file name is passed in the command line */
493
494 if (cmdline[0] == _T('"'))
495 {
496 cmdline++;
497 cmdline[lstrlen(cmdline) - 1] = 0;
498 }
499
502 {
504 }
505 else if (!HasFileExtension(cmdline))
506 {
507 static const TCHAR txt[] = _T(".txt");
508
509 /* try to find file with ".txt" extension */
510 if (!_tcscmp(txt, cmdline + _tcslen(cmdline) - _tcslen(txt)))
511 {
513 }
514 else
515 {
516 _tcsncpy(buf, cmdline, MAX_PATH - _tcslen(txt) - 1);
517 _tcscat(buf, txt);
518 file_name = buf;
520 }
521 }
522
524
525 if (file_exists)
526 {
529 if (opt_print)
530 {
532 return FALSE;
533 }
534 }
535 else
536 {
538 {
539 case IDYES:
541 break;
542
543 case IDNO:
544 break;
545 }
546 }
547 }
548
549 return TRUE;
550}
static BOOL file_exists(const WCHAR *file_name)
Definition: axinstall.c:70
BOOL HasFileExtension(LPCTSTR szFilename)
Definition: dialog.c:240
BOOL FileExists(LPCTSTR szFilename)
Definition: dialog.c:235
VOID DIALOG_FilePrint(VOID)
Definition: printing.c:565
static int AlertFileDoesNotExist(LPCTSTR szFileName)
Definition: main.c:456
static VOID DoOpenFile(PINFO pInfo)
Definition: connectdialog.c:34
#define TRUE
Definition: types.h:120
#define MAX_PATH
Definition: compat.h:34
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define _tcscmp
Definition: tchar.h:1424
#define _tcscat
Definition: tchar.h:622
#define _tcsncpy
Definition: tchar.h:1410
LPCWSTR szPath
Definition: env.c:37
static LPCWSTR file_name
Definition: protocol.c:147
#define _countof(array)
Definition: sndvol32.h:70
Definition: getopt.h:109
#define lstrlen
Definition: winbase.h:3901
#define GetFullPathName
Definition: winbase.h:3846
#define IDNO
Definition: winuser.h:839
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
#define IDYES
Definition: winuser.h:838
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define _tcslen
Definition: xmlstorage.h:198

Referenced by _tWinMain().

◆ NOTEPAD_EnableSearchMenu()

VOID NOTEPAD_EnableSearchMenu ( )

Definition at line 20 of file main.c.

21{
22 BOOL bEmpty = (GetWindowTextLengthW(Globals.hEdit) == 0);
23 UINT uEnable = MF_BYCOMMAND | (bEmpty ? MF_GRAYED : MF_ENABLED);
24 EnableMenuItem(Globals.hMenu, CMD_SEARCH, uEnable);
25 EnableMenuItem(Globals.hMenu, CMD_SEARCH_NEXT, uEnable);
26 EnableMenuItem(Globals.hMenu, CMD_SEARCH_PREV, uEnable);
27}
unsigned int UINT
Definition: ndis.h:50
#define CMD_SEARCH_PREV
Definition: notepad_res.h:48
#define CMD_SEARCH
Definition: notepad_res.h:44
#define CMD_SEARCH_NEXT
Definition: notepad_res.h:45
#define MF_BYCOMMAND
Definition: winuser.h:202
#define MF_ENABLED
Definition: winuser.h:128
int WINAPI GetWindowTextLengthW(_In_ HWND)
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define MF_GRAYED
Definition: winuser.h:129

Referenced by DIALOG_FileNew(), DoOpenFile(), and NOTEPAD_WndProc().

◆ NOTEPAD_FindNext()

BOOL NOTEPAD_FindNext ( FINDREPLACE pFindReplace,
BOOL  bReplace,
BOOL  bShowAlert 
)

Definition at line 132 of file main.c.

133{
134 int iTextLength, iTargetLength;
135 size_t iAdjustment = 0;
136 LPTSTR pszText = NULL;
137 DWORD dwPosition, dwBegin, dwEnd;
138 BOOL bMatches = FALSE;
139 TCHAR szResource[128], szText[128];
141
142 iTargetLength = (int) _tcslen(pFindReplace->lpstrFindWhat);
143
144 /* Retrieve the window text */
145 iTextLength = GetWindowTextLength(Globals.hEdit);
146 if (iTextLength > 0)
147 {
148 pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (iTextLength + 1) * sizeof(TCHAR));
149 if (!pszText)
150 return FALSE;
151
152 GetWindowText(Globals.hEdit, pszText, iTextLength + 1);
153 }
154
155 SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM) &dwBegin, (LPARAM) &dwEnd);
156 if (bReplace && ((dwEnd - dwBegin) == (DWORD) iTargetLength))
157 {
158 if (NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwBegin))
159 {
161 iAdjustment = _tcslen(pFindReplace->lpstrReplaceWith) - (dwEnd - dwBegin);
162 }
163 }
164
165 if (pFindReplace->Flags & FR_DOWN)
166 {
167 /* Find Down */
168 dwPosition = dwEnd;
169 while(dwPosition < (DWORD) iTextLength)
170 {
171 bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
172 if (bMatches)
173 break;
174 dwPosition++;
175 }
176 }
177 else
178 {
179 /* Find Up */
180 dwPosition = dwBegin;
181 while(dwPosition > 0)
182 {
183 dwPosition--;
184 bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
185 if (bMatches)
186 break;
187 }
188 }
189
190 if (bMatches)
191 {
192 /* Found target */
193 if (dwPosition > dwBegin)
194 dwPosition += (DWORD) iAdjustment;
195 SendMessage(Globals.hEdit, EM_SETSEL, dwPosition, dwPosition + iTargetLength);
196 SendMessage(Globals.hEdit, EM_SCROLLCARET, 0, 0);
197 bSuccess = TRUE;
198 }
199 else
200 {
201 /* Can't find target */
202 if (bShowAlert)
203 {
204 LoadString(Globals.hInstance, STRING_CANNOTFIND, szResource, _countof(szResource));
205 StringCchPrintf(szText, _countof(szText), szResource, pFindReplace->lpstrFindWhat);
206 LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, _countof(szResource));
207 MessageBox(Globals.hFindReplaceDlg, szText, szResource, MB_OK);
208 }
209 bSuccess = FALSE;
210 }
211
212 if (pszText)
213 HeapFree(GetProcessHeap(), 0, pszText);
214 return bSuccess;
215}
static BOOL NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, INT iTextLength, DWORD dwPosition)
Definition: main.c:94
#define FR_DOWN
Definition: commdlg.h:127
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
static BOOLEAN bSuccess
Definition: drive.cpp:355
unsigned long DWORD
Definition: ntddk_ex.h:95
#define STRING_CANNOTFIND
Definition: notepad_res.h:77
#define STRING_NOTEPAD
Definition: notepad_res.h:63
#define DWORD
Definition: nt_native.h:44
#define EM_SCROLLCARET
Definition: richedit.h:81
#define StringCchPrintf
Definition: strsafe.h:517
LPSTR lpstrFindWhat
Definition: commdlg.h:307
LPSTR lpstrReplaceWith
Definition: commdlg.h:308
DWORD Flags
Definition: commdlg.h:306
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define GetWindowTextLength
Definition: winuser.h:5811
#define EM_GETSEL
Definition: winuser.h:2000
#define EM_REPLACESEL
Definition: winuser.h:2009
#define SendMessage
Definition: winuser.h:5855
#define EM_SETSEL
Definition: winuser.h:2021
#define MB_OK
Definition: winuser.h:793
#define GetWindowText
Definition: winuser.h:5810
#define LoadString
Definition: winuser.h:5831
#define MessageBox
Definition: winuser.h:5834
CHAR * LPTSTR
Definition: xmlstorage.h:192

Referenced by DIALOG_SearchNext(), NOTEPAD_ReplaceAll(), and NOTEPAD_WndProc().

◆ NOTEPAD_FindTerm()

static VOID NOTEPAD_FindTerm ( VOID  )
static

Definition at line 235 of file main.c.

236{
237 Globals.hFindReplaceDlg = NULL;
238}

Referenced by NOTEPAD_WndProc().

◆ NOTEPAD_FindTextAt()

static BOOL NOTEPAD_FindTextAt ( FINDREPLACE pFindReplace,
LPCTSTR  pszText,
INT  iTextLength,
DWORD  dwPosition 
)
static

Definition at line 94 of file main.c.

95{
96 BOOL bMatches;
97 size_t iTargetLength;
98 LPCTSTR pchPosition;
99
100 if (!pFindReplace || !pszText)
101 return FALSE;
102
103 iTargetLength = _tcslen(pFindReplace->lpstrFindWhat);
104 pchPosition = &pszText[dwPosition];
105
106 /* Make proper comparison */
107 if (pFindReplace->Flags & FR_MATCHCASE)
108 bMatches = !_tcsncmp(pchPosition, pFindReplace->lpstrFindWhat, iTargetLength);
109 else
110 bMatches = !_tcsnicmp(pchPosition, pFindReplace->lpstrFindWhat, iTargetLength);
111
112 if (bMatches && (pFindReplace->Flags & FR_WHOLEWORD))
113 {
114 if (dwPosition > 0)
115 {
116 if (_istalnum(*(pchPosition - 1)) || *(pchPosition - 1) == _T('_'))
117 bMatches = FALSE;
118 }
119 if ((INT)dwPosition + iTargetLength < iTextLength)
120 {
121 if (_istalnum(pchPosition[iTargetLength]) || pchPosition[iTargetLength] == _T('_'))
122 bMatches = FALSE;
123 }
124 }
125
126 return bMatches;
127}
#define FR_WHOLEWORD
Definition: commdlg.h:145
#define FR_MATCHCASE
Definition: commdlg.h:136
#define _tcsncmp
Definition: tchar.h:1428
#define _istalnum
Definition: tchar.h:1490
int32_t INT
Definition: typedefs.h:58
#define _tcsnicmp
Definition: xmlstorage.h:207

Referenced by NOTEPAD_FindNext().

◆ NOTEPAD_InitData()

static VOID NOTEPAD_InitData ( HINSTANCE  hInstance)
static

Definition at line 243 of file main.c.

244{
245 LPTSTR p;
246 static const TCHAR txt_files[] = _T("*.txt");
247 static const TCHAR all_files[] = _T("*.*");
248
249 ZeroMemory(&Globals, sizeof(Globals));
251 Globals.encFile = ENCODING_DEFAULT;
252
253 p = Globals.szFilter;
256 p += _countof(txt_files);
257
260 p += _countof(all_files);
261 *p = '\0';
262 Globals.find.lpstrFindWhat = NULL;
263
264 Globals.hDevMode = NULL;
265 Globals.hDevNames = NULL;
266}
#define MAX_STRING_LEN
Definition: precomp.h:36
static const TCHAR txt_files[]
Definition: dialog.c:22
GLfloat GLfloat p
Definition: glext.h:8902
#define _tcscpy
Definition: tchar.h:623
int all_files
Definition: mkisofs.c:132
#define ENCODING_DEFAULT
Definition: notepad.h:49
#define STRING_ALL_FILES
Definition: notepad_res.h:68
#define STRING_TEXT_FILES_TXT
Definition: notepad_res.h:69

Referenced by _tWinMain().

◆ NOTEPAD_InitMenuPopup()

static VOID NOTEPAD_InitMenuPopup ( HMENU  menu,
LPARAM  index 
)
static

Definition at line 271 of file main.c.

272{
273 DWORD dwStart, dwEnd;
274 int enable;
275
277
278 CheckMenuItem(menu, CMD_WRAP, (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
279 CheckMenuItem(menu, CMD_STATUSBAR, (Globals.bShowStatusBar ? MF_CHECKED : MF_UNCHECKED));
284 SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
285 enable = ((dwStart == dwEnd) ? MF_GRAYED : MF_ENABLED);
289
292}
#define CMD_DELETE
Definition: resources.h:18
#define CF_TEXT
Definition: constants.h:396
GLuint index
Definition: glext.h:6031
GLboolean enable
Definition: glext.h:11120
#define CMD_PASTE
Definition: notepad_res.h:39
#define CMD_SELECT_ALL
Definition: notepad_res.h:41
#define CMD_COPY
Definition: notepad_res.h:38
#define CMD_WRAP
Definition: notepad_res.h:50
#define CMD_UNDO
Definition: notepad_res.h:36
#define CMD_STATUSBAR
Definition: notepad_res.h:53
#define CMD_CUT
Definition: notepad_res.h:37
#define MF_CHECKED
Definition: winuser.h:132
#define MF_UNCHECKED
Definition: winuser.h:204
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define EM_CANUNDO
Definition: winuser.h:1986
BOOL WINAPI IsClipboardFormatAvailable(_In_ UINT)

Referenced by NOTEPAD_WndProc().

◆ NOTEPAD_MenuCommand()

static int NOTEPAD_MenuCommand ( WPARAM  wParam)
static

Definition at line 49 of file main.c.

50{
51 switch (wParam)
52 {
53 case CMD_NEW: DIALOG_FileNew(); break;
55 case CMD_OPEN: DIALOG_FileOpen(); break;
56 case CMD_SAVE: DIALOG_FileSave(); break;
57 case CMD_SAVE_AS: DIALOG_FileSaveAs(); break;
58 case CMD_PRINT: DIALOG_FilePrint(); break;
60 case CMD_EXIT: DIALOG_FileExit(); break;
61
62 case CMD_UNDO: DIALOG_EditUndo(); break;
63 case CMD_CUT: DIALOG_EditCut(); break;
64 case CMD_COPY: DIALOG_EditCopy(); break;
65 case CMD_PASTE: DIALOG_EditPaste(); break;
66 case CMD_DELETE: DIALOG_EditDelete(); break;
69
70 case CMD_SEARCH: DIALOG_Search(); break;
72 case CMD_REPLACE: DIALOG_Replace(); break;
73 case CMD_GOTO: DIALOG_GoTo(); break;
75
76 case CMD_WRAP: DIALOG_EditWrap(); break;
77 case CMD_FONT: DIALOG_SelectFont(); break;
78
80
83
84 default:
85 break;
86 }
87 return 0;
88}
#define CMD_SAVE_AS
Definition: resources.h:16
#define CMD_OPEN
Definition: resources.h:15
#define CMD_EXIT
Definition: resources.h:17
BOOL DIALOG_FileSaveAs(VOID)
Definition: dialog.c:532
VOID DIALOG_Replace(VOID)
Definition: dialog.c:836
VOID DIALOG_HelpContents(VOID)
Definition: dialog.c:954
VOID DIALOG_EditSelectAll(VOID)
Definition: dialog.c:610
VOID DIALOG_FileNew(VOID)
Definition: dialog.c:397
VOID DIALOG_FileExit(VOID)
Definition: dialog.c:580
VOID DIALOG_FileNewWindow(VOID)
Definition: dialog.c:416
VOID DIALOG_EditUndo(VOID)
Definition: dialog.c:585
VOID DIALOG_GoTo(VOID)
Definition: dialog.c:891
VOID DIALOG_ViewStatusBar(VOID)
Definition: dialog.c:948
VOID DIALOG_EditTimeDate(VOID)
Definition: dialog.c:615
VOID DIALOG_FileOpen(VOID)
Definition: dialog.c:428
VOID DIALOG_SelectFont(VOID)
Definition: dialog.c:766
BOOL DIALOG_FileSave(VOID)
Definition: dialog.c:457
VOID DIALOG_Search(VOID)
Definition: dialog.c:818
VOID DIALOG_HelpAboutNotepad(VOID)
Definition: dialog.c:959
VOID DIALOG_EditCut(VOID)
Definition: dialog.c:590
VOID DIALOG_EditWrap(VOID)
Definition: dialog.c:756
VOID DIALOG_SearchNext(BOOL bDown)
Definition: dialog.c:823
VOID DIALOG_EditPaste(VOID)
Definition: dialog.c:600
VOID DIALOG_EditCopy(VOID)
Definition: dialog.c:595
VOID DIALOG_EditDelete(VOID)
Definition: dialog.c:605
VOID DIALOG_FilePageSetup(VOID)
Definition: printing.c:670
#define CMD_GOTO
Definition: notepad_res.h:47
#define CMD_FONT
Definition: notepad_res.h:51
#define CMD_REPLACE
Definition: notepad_res.h:46
#define CMD_SAVE
Definition: notepad_res.h:30
#define CMD_NEW
Definition: notepad_res.h:27
#define CMD_HELP_CONTENTS
Definition: notepad_res.h:56
#define CMD_PAGE_SETUP
Definition: notepad_res.h:33
#define CMD_NEW_WINDOW
Definition: notepad_res.h:28
#define CMD_HELP_ABOUT_NOTEPAD
Definition: notepad_res.h:57
#define CMD_TIME_DATE
Definition: notepad_res.h:42
#define CMD_PRINT
Definition: notepad_res.h:32

Referenced by NOTEPAD_WndProc().

◆ NOTEPAD_ReplaceAll()

static VOID NOTEPAD_ReplaceAll ( FINDREPLACE pFindReplace)
static

Definition at line 220 of file main.c.

221{
222 BOOL bShowAlert = TRUE;
223
224 SendMessage(Globals.hEdit, EM_SETSEL, 0, 0);
225
226 while (NOTEPAD_FindNext(pFindReplace, TRUE, bShowAlert))
227 {
228 bShowAlert = FALSE;
229 }
230}
BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bShowAlert)
Definition: main.c:132

Referenced by NOTEPAD_WndProc().

◆ NOTEPAD_WndProc()

static LRESULT WINAPI NOTEPAD_WndProc ( HWND  hWnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 330 of file main.c.

331{
332 switch (msg)
333 {
334
335 case WM_CREATE:
337 Globals.hMenu = GetMenu(hWnd);
338
339 DragAcceptFiles(hWnd, TRUE); /* Accept Drag & Drop */
340
341 /* Create controls */
344
345 DIALOG_FileNew(); /* Initialize file info */
346
347 // For now, the "Help" dialog is disabled due to the lack of HTML Help support
349 break;
350
351 case WM_COMMAND:
354 if ((HIWORD(wParam) == EN_CHANGE))
357 break;
358
359 case WM_CLOSE:
360 if (DoCloseFile())
362 break;
363
365 if (DoCloseFile()) {
366 return 1;
367 }
368 break;
369
370 case WM_DESTROY:
371 if (Globals.hFont)
373 if (Globals.hDevMode)
374 GlobalFree(Globals.hDevMode);
375 if (Globals.hDevNames)
376 GlobalFree(Globals.hDevNames);
380 break;
381
382 case WM_SIZE:
383 {
384 RECT rc;
385 GetClientRect(hWnd, &rc);
386
387 if (Globals.bShowStatusBar)
388 {
389 RECT rcStatus;
390 SendMessageW(Globals.hStatusBar, WM_SIZE, 0, 0);
391 GetWindowRect(Globals.hStatusBar, &rcStatus);
392 rc.bottom -= rcStatus.bottom - rcStatus.top;
393 }
394
395 MoveWindow(Globals.hEdit, 0, 0, rc.right, rc.bottom, TRUE);
396
397 if (Globals.bShowStatusBar)
398 {
399 /* Align status bar parts, only if the status bar resize operation succeeds */
401 }
402 break;
403 }
404
405 /* The entire client area is covered by edit control and by
406 * the status bar. So there is no need to erase main background.
407 * This resolves the horrible flicker effect during windows resizes. */
408 case WM_ERASEBKGND:
409 return 1;
410
411 case WM_SETFOCUS:
412 SetFocus(Globals.hEdit);
413 break;
414
415 case WM_DROPFILES:
416 {
417 TCHAR szFileName[MAX_PATH];
418 HDROP hDrop = (HDROP) wParam;
419
420 DragQueryFile(hDrop, 0, szFileName, _countof(szFileName));
421 DragFinish(hDrop);
422 DoOpenFile(szFileName);
423 break;
424 }
425
426 case WM_INITMENUPOPUP:
428 break;
429
430 default:
431 if (msg == aFINDMSGSTRING)
432 {
433 FINDREPLACE *pFindReplace = (FINDREPLACE *) lParam;
434 Globals.find = *(FINDREPLACE *) lParam;
435
437
438 if (pFindReplace->Flags & FR_FINDNEXT)
439 NOTEPAD_FindNext(pFindReplace, FALSE, TRUE);
440 else if (pFindReplace->Flags & FR_REPLACE)
441 NOTEPAD_FindNext(pFindReplace, TRUE, TRUE);
442 else if (pFindReplace->Flags & FR_REPLACEALL)
443 NOTEPAD_ReplaceAll(pFindReplace);
444 else if (pFindReplace->Flags & FR_DIALOGTERM)
446
448 break;
449 }
450
452 }
453 return 0;
454}
VOID DoShowHideStatusBar(VOID)
Definition: dialog.c:631
VOID DIALOG_StatusBarAlignParts(VOID)
Definition: dialog.c:147
VOID WaitCursor(BOOL bBegin)
Definition: dialog.c:120
VOID DoCreateEditWindow(VOID)
Definition: dialog.c:665
BOOL DoCloseFile(VOID)
Definition: dialog.c:311
static VOID NOTEPAD_ReplaceAll(FINDREPLACE *pFindReplace)
Definition: main.c:220
static int NOTEPAD_MenuCommand(WPARAM wParam)
Definition: main.c:49
VOID NOTEPAD_EnableSearchMenu()
Definition: main.c:20
static VOID NOTEPAD_FindTerm(VOID)
Definition: main.c:235
static VOID NOTEPAD_InitMenuPopup(HMENU menu, LPARAM index)
Definition: main.c:271
#define FR_REPLACE
Definition: commdlg.h:142
#define FR_DIALOGTERM
Definition: commdlg.h:126
#define FR_REPLACEALL
Definition: commdlg.h:143
#define FR_FINDNEXT
Definition: commdlg.h:131
void WINAPI DragFinish(HDROP h)
Definition: shellole.c:538
void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
Definition: shellole.c:522
pKey DeleteObject()
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
void NOTEPAD_SaveSettingsToRegistry(void)
Definition: settings.c:236
#define LOWORD(l)
Definition: pedump.c:82
#define DefWindowProc
Definition: ros2win.h:31
#define DragQueryFile
Definition: shellapi.h:687
HFONT hFont
Definition: precomp.h:58
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
#define SetWindowLongPtr
Definition: treelist.c:70
#define GWLP_WNDPROC
Definition: treelist.c:66
#define HIWORD(l)
Definition: typedefs.h:247
#define WM_ERASEBKGND
Definition: winuser.h:1628
#define WM_CLOSE
Definition: winuser.h:1624
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
#define WM_CREATE
Definition: winuser.h:1611
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_SIZE
Definition: winuser.h:1614
#define WM_DROPFILES
Definition: winuser.h:1828
#define WM_COMMAND
Definition: winuser.h:1743
#define WM_SETFOCUS
Definition: winuser.h:1616
#define EN_HSCROLL
Definition: winuser.h:2027
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
HWND WINAPI SetFocus(_In_opt_ HWND)
#define WM_INITMENUPOPUP
Definition: winuser.h:1749
#define WM_QUERYENDSESSION
Definition: winuser.h:1625
#define EN_VSCROLL
Definition: winuser.h:2032
#define WM_DESTROY
Definition: winuser.h:1612
BOOL WINAPI DestroyWindow(_In_ HWND)
BOOL WINAPI MoveWindow(_In_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ BOOL)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
HMENU WINAPI GetMenu(_In_ HWND)
#define EN_CHANGE
Definition: winuser.h:2025

Referenced by _tWinMain().

◆ SetFileName()

VOID SetFileName ( LPCTSTR  szFileName)

Definition at line 34 of file main.c.

35{
36 StringCchCopy(Globals.szFileName, _countof(Globals.szFileName), szFileName);
37 Globals.szFileTitle[0] = 0;
38 GetFileTitle(szFileName, Globals.szFileTitle, _countof(Globals.szFileTitle));
39
40 if (szFileName && szFileName[0])
41 SHAddToRecentDocs(SHARD_PATHW, szFileName);
42}
#define GetFileTitle
Definition: commdlg.h:664
void WINAPI SHAddToRecentDocs(UINT uFlags, LPCVOID pv)
Definition: shellord.c:1010
#define SHARD_PATHW
Definition: shlobj.h:1176
#define StringCchCopy
Definition: strsafe.h:139

Variable Documentation

◆ aFINDMSGSTRING

ATOM aFINDMSGSTRING
static

Definition at line 18 of file main.c.

Referenced by _tWinMain(), and NOTEPAD_WndProc().

◆ Globals