ReactOS 0.4.15-dev-7924-g5949c20
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;
560 HMONITOR monitor;
562 INT x, y;
563 RECT rcIntersect;
564 static const TCHAR className[] = _T("Notepad");
565 static const TCHAR winName[] = _T("Notepad");
566
567 switch (GetUserDefaultUILanguage())
568 {
571 break;
572
573 default:
574 break;
575 }
576
578
580
583
584 ZeroMemory(&wndclass, sizeof(wndclass));
585 wndclass.cbSize = sizeof(wndclass);
586 wndclass.lpfnWndProc = NOTEPAD_WndProc;
587 wndclass.hInstance = Globals.hInstance;
589 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
590 wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
592 wndclass.lpszClassName = className;
593 wndclass.hIconSm = (HICON)LoadImage(hInstance,
598 0);
599 if (!RegisterClassEx(&wndclass))
600 {
602 return 1;
603 }
604
605 /* Setup windows */
606
607 monitor = MonitorFromRect(&Globals.main_rect, MONITOR_DEFAULTTOPRIMARY);
608 info.cbSize = sizeof(info);
609 GetMonitorInfoW(monitor, &info);
610
611 x = Globals.main_rect.left;
612 y = Globals.main_rect.top;
613 if (!IntersectRect(&rcIntersect, &Globals.main_rect, &info.rcWork))
614 x = y = CW_USEDEFAULT;
615
616 /* Globals.hMainWnd will be set in WM_CREATE handling */
617 CreateWindow(className,
618 winName,
620 x,
621 y,
622 Globals.main_rect.right - Globals.main_rect.left,
623 Globals.main_rect.bottom - Globals.main_rect.top,
624 NULL,
625 NULL,
627 NULL);
628 if (!Globals.hMainWnd)
629 {
631 return 1;
632 }
633
636
638 return 0;
639
641
642 while (GetMessage(&msg, NULL, 0, 0))
643 {
645 !IsDialogMessage(Globals.hFindReplaceDlg, &msg))
646 {
649 }
650 }
651
653
654 return (int) msg.wParam;
655}
#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
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: lang.c:816
HACCEL hAccel
Definition: main.c:47
static HICON
Definition: imagelist.c:84
HMONITOR WINAPI MonitorFromRect(LPCRECT, DWORD)
void NOTEPAD_LoadSettingsFromRegistry(void)
Definition: settings.c:105
#define IDI_NPICON
Definition: notepad_res.h:19
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#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
HINSTANCE hInstance
Definition: winuser.h:3206
HCURSOR hCursor
Definition: winuser.h:3208
LPCSTR lpszMenuName
Definition: winuser.h:3210
HICON hIconSm
Definition: winuser.h:3212
UINT cbSize
Definition: winuser.h:3201
WNDPROC lpfnWndProc
Definition: winuser.h:3203
LPCSTR lpszClassName
Definition: winuser.h:3211
HICON hIcon
Definition: winuser.h:3207
HBRUSH hbrBackground
Definition: winuser.h:3209
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1719
#define ZeroMemory
Definition: winbase.h:1712
#define LAYOUT_RTL
Definition: wingdi.h:1371
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define COLOR_WINDOW
Definition: winuser.h:918
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define IsDialogMessage
Definition: winuser.h:5809
#define IMAGE_ICON
Definition: winuser.h:212
#define IDC_ARROW
Definition: winuser.h:687
#define SM_CYSMICON
Definition: winuser.h:1013
#define CreateWindow
Definition: winuser.h:5754
#define GetMessage
Definition: winuser.h:5790
#define SM_CXSMICON
Definition: winuser.h:1012
#define RegisterClassEx
Definition: winuser.h:5837
#define RegisterWindowMessage
Definition: winuser.h:5840
BOOL WINAPI IntersectRect(_Out_ LPRECT, _In_ LPCRECT, _In_ LPCRECT)
#define LoadIcon
Definition: winuser.h:5813
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5812
#define CW_USEDEFAULT
Definition: winuser.h:225
#define LoadImage
Definition: winuser.h:5815
#define DispatchMessage
Definition: winuser.h:5765
BOOL WINAPI GetMonitorInfoW(_In_ HMONITOR, _Inout_ LPMONITORINFO)
BOOL WINAPI DestroyAcceleratorTable(_In_ HACCEL)
#define TranslateAccelerator
Definition: winuser.h:5860
#define MAKEINTRESOURCE
Definition: winuser.h:591
int WINAPI GetSystemMetrics(_In_ int)
#define LoadAccelerators
Definition: winuser.h:5810
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:187
#define STRING_DOESNOTEXIST
Definition: notepad_res.h:72
#define MB_YESNO
Definition: winuser.h:817
#define MB_ICONEXCLAMATION
Definition: winuser.h:785

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:920
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:1716
#define CallWindowProc
Definition: winuser.h:5735
#define VK_UP
Definition: winuser.h:2225
#define WM_LBUTTONUP
Definition: winuser.h:1777
#define VK_LEFT
Definition: winuser.h:2224
#define VK_RIGHT
Definition: winuser.h:2226
#define VK_DOWN
Definition: winuser.h:2227
#define WM_KEYDOWN
Definition: winuser.h:1715

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:234
BOOL FileExists(LPCTSTR szFilename)
Definition: dialog.c:229
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:68
Definition: getopt.h:109
#define lstrlen
Definition: winbase.h:3876
#define GetFullPathName
Definition: winbase.h:3821
#define IDNO
Definition: winuser.h:836
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
#define IDYES
Definition: winuser.h:835
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:433
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:5799
#define EM_GETSEL
Definition: winuser.h:1997
#define EM_REPLACESEL
Definition: winuser.h:2006
#define SendMessage
Definition: winuser.h:5843
#define EM_SETSEL
Definition: winuser.h:2018
#define MB_OK
Definition: winuser.h:790
#define GetWindowText
Definition: winuser.h:5798
#define LoadString
Definition: winuser.h:5819
#define MessageBox
Definition: winuser.h:5822
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
#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:1983
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:521
VOID DIALOG_Replace(VOID)
Definition: dialog.c:825
VOID DIALOG_HelpContents(VOID)
Definition: dialog.c:943
VOID DIALOG_EditSelectAll(VOID)
Definition: dialog.c:599
VOID DIALOG_FileNew(VOID)
Definition: dialog.c:386
VOID DIALOG_FileExit(VOID)
Definition: dialog.c:569
VOID DIALOG_FileNewWindow(VOID)
Definition: dialog.c:405
VOID DIALOG_EditUndo(VOID)
Definition: dialog.c:574
VOID DIALOG_GoTo(VOID)
Definition: dialog.c:880
VOID DIALOG_ViewStatusBar(VOID)
Definition: dialog.c:937
VOID DIALOG_EditTimeDate(VOID)
Definition: dialog.c:604
VOID DIALOG_FileOpen(VOID)
Definition: dialog.c:417
VOID DIALOG_SelectFont(VOID)
Definition: dialog.c:755
BOOL DIALOG_FileSave(VOID)
Definition: dialog.c:446
VOID DIALOG_Search(VOID)
Definition: dialog.c:807
VOID DIALOG_HelpAboutNotepad(VOID)
Definition: dialog.c:948
VOID DIALOG_EditCut(VOID)
Definition: dialog.c:579
VOID DIALOG_EditWrap(VOID)
Definition: dialog.c:745
VOID DIALOG_SearchNext(BOOL bDown)
Definition: dialog.c:812
VOID DIALOG_EditPaste(VOID)
Definition: dialog.c:589
VOID DIALOG_EditCopy(VOID)
Definition: dialog.c:584
VOID DIALOG_EditDelete(VOID)
Definition: dialog.c:594
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:620
VOID DIALOG_StatusBarAlignParts(VOID)
Definition: dialog.c:141
VOID WaitCursor(BOOL bBegin)
Definition: dialog.c:114
VOID DoCreateEditWindow(VOID)
Definition: dialog.c:654
BOOL DoCloseFile(VOID)
Definition: dialog.c:301
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:227
#define LOWORD(l)
Definition: pedump.c:82
#define DefWindowProc
Definition: ros2win.h:31
#define DragQueryFile
Definition: shellapi.h:686
HFONT hFont
Definition: precomp.h:58
LONG right
Definition: windef.h:308
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:1625
#define WM_CLOSE
Definition: winuser.h:1621
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
#define WM_CREATE
Definition: winuser.h:1608
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_SIZE
Definition: winuser.h:1611
#define WM_DROPFILES
Definition: winuser.h:1825
#define WM_COMMAND
Definition: winuser.h:1740
#define WM_SETFOCUS
Definition: winuser.h:1613
#define EN_HSCROLL
Definition: winuser.h:2024
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
HWND WINAPI SetFocus(_In_opt_ HWND)
#define WM_INITMENUPOPUP
Definition: winuser.h:1746
#define WM_QUERYENDSESSION
Definition: winuser.h:1622
#define EN_VSCROLL
Definition: winuser.h:2029
#define WM_DESTROY
Definition: winuser.h:1609
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:2022

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:813
#define SHARD_PATHW
Definition: shlobj.h:1169
#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