ReactOS  0.4.15-dev-5446-g3f3714b
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 (VOID)
 
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 592 of file main.c.

593 {
594  MSG msg;
595  HACCEL hAccel;
596  WNDCLASSEX wndclass;
597  HMONITOR monitor;
599  INT x, y;
600 
601  static const TCHAR className[] = _T("Notepad");
602  static const TCHAR winName[] = _T("Notepad");
603 
604  switch (GetUserDefaultUILanguage())
605  {
608  break;
609 
610  default:
611  break;
612  }
613 
615 
617 
618  ZeroMemory(&Globals, sizeof(Globals));
621 
622  ZeroMemory(&wndclass, sizeof(wndclass));
623  wndclass.cbSize = sizeof(wndclass);
624  wndclass.lpfnWndProc = NOTEPAD_WndProc;
625  wndclass.hInstance = Globals.hInstance;
627  wndclass.hCursor = LoadCursor(0, IDC_ARROW);
628  wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
630  wndclass.lpszClassName = className;
631  wndclass.hIconSm = (HICON)LoadImage(hInstance,
633  IMAGE_ICON,
634  16,
635  16,
636  0);
637 
638  if (!RegisterClassEx(&wndclass)) return FALSE;
639 
640  /* Setup windows */
641 
642  monitor = MonitorFromRect(&Globals.main_rect, MONITOR_DEFAULTTOPRIMARY);
643  info.cbSize = sizeof(info);
644  GetMonitorInfoW(monitor, &info);
645 
648  if (Globals.main_rect.left >= info.rcWork.right ||
649  Globals.main_rect.top >= info.rcWork.bottom ||
650  Globals.main_rect.right < info.rcWork.left ||
651  Globals.main_rect.bottom < info.rcWork.top)
652  x = y = CW_USEDEFAULT;
653 
654  Globals.hMainWnd = CreateWindow(className,
655  winName,
657  x,
658  y,
661  NULL,
662  NULL,
664  NULL);
665  if (!Globals.hMainWnd)
666  {
667  ShowLastError();
668  ExitProcess(1);
669  }
670 
672 
674  DIALOG_FileNew();
675 
676  ShowWindow(Globals.hMainWnd, show);
679 
681 
683  {
684  return 0;
685  }
686 
688 
689  while (GetMessage(&msg, 0, 0, 0))
690  {
693  {
696  }
697  }
698  return (int) msg.wParam;
699 }
HWND hFindReplaceDlg
Definition: main.h:58
#define TranslateAccelerator
Definition: winuser.h:5850
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define DispatchMessage
Definition: winuser.h:5755
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: lang.c:810
BOOL WINAPI TranslateMessage(_In_ const MSG *)
static HICON
Definition: imagelist.c:84
LPCSTR lpszMenuName
Definition: winuser.h:3200
NOTEPAD_GLOBALS Globals
Definition: main.c:31
#define IMAGE_ICON
Definition: winuser.h:212
#define RegisterClassEx
Definition: winuser.h:5827
#define LAYOUT_RTL
Definition: wingdi.h:1371
HCURSOR hCursor
Definition: winuser.h:3198
WNDPROC lpfnWndProc
Definition: winuser.h:3193
#define CreateWindow
Definition: winuser.h:5744
static VOID NOTEPAD_InitData(VOID)
Definition: main.c:259
LPCSTR lpszClassName
Definition: winuser.h:3201
WORD ATOM
Definition: dimm.idl:113
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define MAIN_MENU
Definition: resources.h:12
BOOL WINAPI UpdateWindow(_In_ HWND)
void NOTEPAD_LoadSettingsFromRegistry(void)
Definition: settings.c:114
void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
Definition: shellole.c:522
LONG top
Definition: windef.h:307
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
#define ZeroMemory
Definition: winbase.h:1670
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
TCHAR * cmdline
Definition: stretchblt.cpp:32
HICON hIconSm
Definition: winuser.h:3202
LONG left
Definition: windef.h:306
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define IsDialogMessage
Definition: winuser.h:5799
LONG right
Definition: windef.h:308
#define COLOR_WINDOW
Definition: winuser.h:912
int32_t INT
Definition: typedefs.h:58
#define LANG_HEBREW
Definition: nls.h:67
HINSTANCE hInstance
Definition: main.h:56
#define LoadAccelerators
Definition: winuser.h:5800
#define FALSE
Definition: types.h:117
HINSTANCE hInstance
Definition: winuser.h:3196
HACCEL hAccel
Definition: main.c:47
static struct _test_info info[]
Definition: SetCursorPos.c:19
#define CW_USEDEFAULT
Definition: winuser.h:225
UINT cbSize
Definition: winuser.h:3191
HBRUSH hbrBackground
Definition: winuser.h:3199
VOID DoCreateEditWindow(VOID)
Definition: dialog.c:1000
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1720
RECT main_rect
Definition: main.h:83
char TCHAR
Definition: xmlstorage.h:189
#define FINDMSGSTRING
Definition: commdlg.h:653
#define _T(x)
Definition: vfdio.h:22
VOID ShowLastError(VOID)
Definition: dialog.c:59
BOOL WINAPI GetMonitorInfoW(_In_ HMONITOR, _Inout_ LPMONITORINFO)
HINSTANCE hInstance
Definition: main.c:36
HICON hIcon
Definition: winuser.h:3197
static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: main.c:347
#define LoadCursor
Definition: winuser.h:5802
#define RegisterWindowMessage
Definition: winuser.h:5830
static BOOL HandleCommandLine(LPTSTR cmdline)
Definition: main.c:503
#define IDI_NPICON
Definition: notepad_res.h:32
#define NULL
Definition: types.h:112
#define GetMessage
Definition: winuser.h:5780
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define ID_ACCEL
Definition: resources.h:13
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define MAKELANGID(p, s)
Definition: nls.h:15
HMONITOR WINAPI MonitorFromRect(LPCRECT, DWORD)
LONG bottom
Definition: windef.h:309
VOID DIALOG_FileNew(VOID)
Definition: dialog.c:478
static ATOM aFINDMSGSTRING
Definition: main.c:32
#define LoadImage
Definition: winuser.h:5805
#define LoadIcon
Definition: winuser.h:5803
VOID DIALOG_ViewStatusBar(VOID)
Definition: dialog.c:1278
HWND hMainWnd
Definition: main.h:57

◆ AlertFileDoesNotExist()

static int AlertFileDoesNotExist ( LPCTSTR  szFileName)
static

Definition at line 496 of file main.c.

497 {
499  szFileName,
501 }
NOTEPAD_GLOBALS Globals
Definition: main.c:31
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
#define STRING_DOESNOTEXIST
Definition: notepad_res.h:84
#define MB_YESNO
Definition: winuser.h:811
int DIALOG_StringMsgBox(HWND hParent, int formatId, LPCTSTR szString, DWORD dwFlags)
Definition: dialog.c:167
HWND hMainWnd
Definition: main.h:57

Referenced by HandleCommandLine().

◆ EDIT_WndProc()

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

Definition at line 310 of file main.c.

311 {
312  switch (msg)
313  {
314  case WM_KEYDOWN:
315  case WM_KEYUP:
316  {
317  switch (wParam)
318  {
319  case VK_UP:
320  case VK_DOWN:
321  case VK_LEFT:
322  case VK_RIGHT:
324  break;
325  default:
326  {
328  break;
329  }
330  }
331  }
332  case WM_LBUTTONUP:
333  {
335  break;
336  }
337  }
339 }
#define CallWindowProc
Definition: winuser.h:5725
NOTEPAD_GLOBALS Globals
Definition: main.c:31
HWND hWnd
Definition: settings.c:17
#define VK_LEFT
Definition: winuser.h:2214
#define VK_DOWN
Definition: winuser.h:2217
WNDPROC EditProc
Definition: main.h:82
WPARAM wParam
Definition: combotst.c:138
#define VK_UP
Definition: winuser.h:2215
#define FALSE
Definition: types.h:117
#define WM_KEYDOWN
Definition: winuser.h:1705
VOID DIALOG_StatusBarUpdateCaretPos(VOID)
Definition: dialog.c:1264
#define WM_KEYUP
Definition: winuser.h:1706
#define VK_RIGHT
Definition: winuser.h:2216
#define WM_LBUTTONUP
Definition: winuser.h:1767
#define msg(x)
Definition: auth_time.c:54
LPARAM lParam
Definition: combotst.c:139
void UpdateWindowCaption(HWND hwnd)
Definition: mplay32.c:102

Referenced by DoCreateEditWindow().

◆ HandleCommandLine()

static BOOL HandleCommandLine ( LPTSTR  cmdline)
static

Definition at line 503 of file main.c.

504 {
505  BOOL opt_print = FALSE;
506 
507  while (*cmdline == _T(' ') || *cmdline == _T('-') || *cmdline == _T('/'))
508  {
509  TCHAR option;
510 
511  if (*cmdline++ == _T(' ')) continue;
512 
513  option = *cmdline;
514  if (option) cmdline++;
515  while (*cmdline == _T(' ')) cmdline++;
516 
517  switch(option)
518  {
519  case 'p':
520  case 'P':
521  opt_print = TRUE;
522  break;
523  }
524  }
525 
526  if (*cmdline)
527  {
528  /* file name is passed in the command line */
531  TCHAR buf[MAX_PATH];
532 
533  if (cmdline[0] == _T('"'))
534  {
535  cmdline++;
536  cmdline[lstrlen(cmdline) - 1] = 0;
537  }
538 
539  file_name = cmdline;
540  if (FileExists(file_name))
541  {
542  file_exists = TRUE;
543  }
544  else if (!HasFileExtension(cmdline))
545  {
546  static const TCHAR txt[] = _T(".txt");
547 
548  /* try to find file with ".txt" extension */
549  if (!_tcscmp(txt, cmdline + _tcslen(cmdline) - _tcslen(txt)))
550  {
551  file_exists = FALSE;
552  }
553  else
554  {
555  _tcsncpy(buf, cmdline, MAX_PATH - _tcslen(txt) - 1);
556  _tcscat(buf, txt);
557  file_name = buf;
559  }
560  }
561 
562  if (file_exists)
563  {
566  if (opt_print)
567  {
569  return FALSE;
570  }
571  }
572  else
573  {
574  switch (AlertFileDoesNotExist(file_name)) {
575  case IDYES:
577  break;
578 
579  case IDNO:
580  break;
581  }
582  }
583  }
584 
585  return TRUE;
586 }
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
NOTEPAD_GLOBALS Globals
Definition: main.c:31
#define IDYES
Definition: winuser.h:829
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define TRUE
Definition: types.h:120
_TCHAR * _tcsncpy(_TCHAR *dst, const _TCHAR *src, size_t n)
Definition: tcsncpy.h:9
TCHAR * cmdline
Definition: stretchblt.cpp:32
BOOL HasFileExtension(LPCTSTR szFilename)
Definition: dialog.c:231
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define FALSE
Definition: types.h:117
BOOL FileExists(LPCTSTR szFilename)
Definition: dialog.c:220
unsigned int BOOL
Definition: ntddk_ex.h:94
static VOID DoOpenFile(PINFO pInfo)
Definition: connectdialog.c:34
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
Definition: getopt.h:108
GLuint GLenum option
Definition: glext.h:11211
static int AlertFileDoesNotExist(LPCTSTR szFileName)
Definition: main.c:496
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define MAX_PATH
Definition: compat.h:34
VOID DIALOG_FilePrint(VOID)
Definition: dialog.c:652
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
static BOOL file_exists(const WCHAR *file_name)
Definition: axinstall.c:70
#define lstrlen
Definition: winbase.h:3747
#define NULL
Definition: types.h:112
static LPCWSTR file_name
Definition: protocol.c:147
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
#define IDNO
Definition: winuser.h:830
HWND hMainWnd
Definition: main.h:57

Referenced by _tWinMain().

◆ NOTEPAD_EnableSearchMenu()

VOID NOTEPAD_EnableSearchMenu ( )

Definition at line 34 of file main.c.

35 {
40 }
#define MF_DISABLED
Definition: winuser.h:130
NOTEPAD_GLOBALS Globals
Definition: main.c:31
#define MF_BYCOMMAND
Definition: winuser.h:202
#define CMD_SEARCH
Definition: notepad_res.h:53
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
HMENU hMenu
Definition: main.h:62
#define MF_ENABLED
Definition: winuser.h:128
#define CMD_SEARCH_NEXT
Definition: notepad_res.h:54
#define GetWindowTextLength
Definition: winuser.h:5789
#define MF_GRAYED
Definition: winuser.h:129
HWND hEdit
Definition: main.h:59

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

◆ NOTEPAD_FindNext()

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

Definition at line 144 of file main.c.

145 {
146  int iTextLength, iTargetLength;
147  size_t iAdjustment = 0;
148  LPTSTR pszText = NULL;
149  DWORD dwPosition, dwBegin, dwEnd;
150  BOOL bMatches = FALSE;
151  TCHAR szResource[128], szText[128];
152  BOOL bSuccess;
153 
154  iTargetLength = (int) _tcslen(pFindReplace->lpstrFindWhat);
155 
156  /* Retrieve the window text */
157  iTextLength = GetWindowTextLength(Globals.hEdit);
158  if (iTextLength > 0)
159  {
160  pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (iTextLength + 1) * sizeof(TCHAR));
161  if (!pszText)
162  return FALSE;
163 
164  GetWindowText(Globals.hEdit, pszText, iTextLength + 1);
165  }
166 
167  SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM) &dwBegin, (LPARAM) &dwEnd);
168  if (bReplace && ((dwEnd - dwBegin) == (DWORD) iTargetLength))
169  {
170  if (NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwBegin))
171  {
173  iAdjustment = _tcslen(pFindReplace->lpstrReplaceWith) - (dwEnd - dwBegin);
174  }
175  }
176 
177  if (pFindReplace->Flags & FR_DOWN)
178  {
179  /* Find Down */
180  dwPosition = dwEnd;
181  while(dwPosition < (DWORD) iTextLength)
182  {
183  bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
184  if (bMatches)
185  break;
186  dwPosition++;
187  }
188  }
189  else
190  {
191  /* Find Up */
192  dwPosition = dwBegin;
193  while(dwPosition > 0)
194  {
195  dwPosition--;
196  bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
197  if (bMatches)
198  break;
199  }
200  }
201 
202  if (bMatches)
203  {
204  /* Found target */
205  if (dwPosition > dwBegin)
206  dwPosition += (DWORD) iAdjustment;
207  SendMessage(Globals.hEdit, EM_SETSEL, dwPosition, dwPosition + iTargetLength);
209  bSuccess = TRUE;
210  }
211  else
212  {
213  /* Can't find target */
214  if (bShowAlert)
215  {
216  LoadString(Globals.hInstance, STRING_CANNOTFIND, szResource, ARRAY_SIZE(szResource));
217  _sntprintf(szText, ARRAY_SIZE(szText), szResource, pFindReplace->lpstrFindWhat);
218  LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, ARRAY_SIZE(szResource));
219  MessageBox(Globals.hFindReplaceDlg, szText, szResource, MB_OK);
220  }
221  bSuccess = FALSE;
222  }
223 
224  if (pszText)
225  HeapFree(GetProcessHeap(), 0, pszText);
226  return bSuccess;
227 }
HWND hFindReplaceDlg
Definition: main.h:58
NOTEPAD_GLOBALS Globals
Definition: main.c:31
#define TRUE
Definition: types.h:120
LPSTR lpstrFindWhat
Definition: commdlg.h:307
UINT_PTR WPARAM
Definition: windef.h:207
#define DWORD
Definition: nt_native.h:44
static BOOLEAN bSuccess
Definition: drive.cpp:433
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define GetWindowText
Definition: winuser.h:5788
HINSTANCE hInstance
Definition: main.h:56
#define EM_GETSEL
Definition: winuser.h:1987
#define STRING_NOTEPAD
Definition: notepad_res.h:75
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
static BOOL NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, int iTextLength, DWORD dwPosition)
Definition: main.c:110
DWORD Flags
Definition: commdlg.h:306
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
LONG_PTR LPARAM
Definition: windef.h:208
char TCHAR
Definition: xmlstorage.h:189
#define GetProcessHeap()
Definition: compat.h:736
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define EM_SETSEL
Definition: winuser.h:2008
unsigned long DWORD
Definition: ntddk_ex.h:95
#define _sntprintf
Definition: xmlstorage.h:201
#define MessageBox
Definition: winuser.h:5812
LPSTR lpstrReplaceWith
Definition: commdlg.h:308
#define ARRAY_SIZE(a)
Definition: main.h:24
#define NULL
Definition: types.h:112
#define MB_OK
Definition: winuser.h:784
#define FR_DOWN
Definition: commdlg.h:127
#define STRING_CANNOTFIND
Definition: notepad_res.h:89
#define SendMessage
Definition: winuser.h:5833
#define GetWindowTextLength
Definition: winuser.h:5789
HWND hEdit
Definition: main.h:59
#define HeapFree(x, y, z)
Definition: compat.h:735
#define LoadString
Definition: winuser.h:5809
#define EM_REPLACESEL
Definition: winuser.h:1996
#define EM_SCROLLCARET
Definition: richedit.h:81
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

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

◆ NOTEPAD_FindTerm()

static VOID NOTEPAD_FindTerm ( VOID  )
static

Definition at line 251 of file main.c.

252 {
254 }
HWND hFindReplaceDlg
Definition: main.h:58
NOTEPAD_GLOBALS Globals
Definition: main.c:31
#define NULL
Definition: types.h:112

Referenced by NOTEPAD_WndProc().

◆ NOTEPAD_FindTextAt()

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

Definition at line 110 of file main.c.

111 {
112  BOOL bMatches;
113  size_t iTargetLength;
114 
115  if ((!pFindReplace) || (!pszText))
116  {
117  return FALSE;
118  }
119 
120  iTargetLength = _tcslen(pFindReplace->lpstrFindWhat);
121 
122  /* Make proper comparison */
123  if (pFindReplace->Flags & FR_MATCHCASE)
124  bMatches = !_tcsncmp(&pszText[dwPosition], pFindReplace->lpstrFindWhat, iTargetLength);
125  else
126  bMatches = !_tcsnicmp(&pszText[dwPosition], pFindReplace->lpstrFindWhat, iTargetLength);
127 
128  if (bMatches && pFindReplace->Flags & FR_WHOLEWORD)
129  {
130  if ((dwPosition > 0) && !_istspace(pszText[dwPosition-1]))
131  bMatches = FALSE;
132  if ((dwPosition < (DWORD) iTextLength - 1) && !_istspace(pszText[dwPosition+1]))
133  bMatches = FALSE;
134  }
135 
136  return bMatches;
137 }
LPSTR lpstrFindWhat
Definition: commdlg.h:307
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define _tcsnicmp
Definition: xmlstorage.h:207
DWORD Flags
Definition: commdlg.h:306
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
#define FR_MATCHCASE
Definition: commdlg.h:136
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FR_WHOLEWORD
Definition: commdlg.h:145
#define _istspace
Definition: tchar.h:1504
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

Referenced by NOTEPAD_FindNext().

◆ NOTEPAD_InitData()

static VOID NOTEPAD_InitData ( VOID  )
static

Definition at line 259 of file main.c.

260 {
262  static const TCHAR txt_files[] = _T("*.txt");
263  static const TCHAR all_files[] = _T("*.*");
264 
266  _tcscpy(p, txt_files);
267  p += ARRAY_SIZE(txt_files);
268 
270  _tcscpy(p, all_files);
271  p += ARRAY_SIZE(all_files);
272  *p = '\0';
274 
277 }
NOTEPAD_GLOBALS Globals
Definition: main.c:31
LPSTR lpstrFindWhat
Definition: commdlg.h:307
HGLOBAL hDevNames
Definition: main.h:64
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
HGLOBAL hDevMode
Definition: main.h:63
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define STRING_TEXT_FILES_TXT
Definition: notepad_res.h:81
HINSTANCE hInstance
Definition: main.h:56
#define STRING_ALL_FILES
Definition: notepad_res.h:80
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
static const TCHAR txt_files[]
Definition: dialog.c:34
TCHAR szFilter[2 *MAX_STRING_LEN+100]
Definition: main.h:72
int all_files
Definition: mkisofs.c:132
#define ARRAY_SIZE(a)
Definition: main.h:24
#define MAX_STRING_LEN
Definition: main.c:73
#define NULL
Definition: types.h:112
GLfloat GLfloat p
Definition: glext.h:8902
#define LoadString
Definition: winuser.h:5809
FINDREPLACE find
Definition: main.h:81

Referenced by _tWinMain().

◆ NOTEPAD_InitMenuPopup()

static VOID NOTEPAD_InitMenuPopup ( HMENU  menu,
LPARAM  index 
)
static

Definition at line 282 of file main.c.

283 {
284  int enable;
285 
287 
290  if (!Globals.bWrapLongLines)
291  {
294  }
295  EnableMenuItem(menu, CMD_UNDO,
301  EnableMenuItem(menu, CMD_CUT, enable);
304 
308 }
NOTEPAD_GLOBALS Globals
Definition: main.c:31
BOOL WINAPI DrawMenuBar(_In_ HWND)
BOOL WINAPI IsClipboardFormatAvailable(_In_ UINT)
#define MF_BYCOMMAND
Definition: winuser.h:202
#define CMD_WRAP
Definition: notepad_res.h:58
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define CMD_DELETE
Definition: resources.h:18
#define EM_GETSEL
Definition: winuser.h:1987
#define CMD_STATUSBAR
Definition: notepad_res.h:61
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
BOOL bShowStatusBar
Definition: main.h:67
GLuint index
Definition: glext.h:6031
#define CF_TEXT
Definition: constants.h:396
#define MF_CHECKED
Definition: winuser.h:132
#define CMD_COPY
Definition: notepad_res.h:47
#define MF_ENABLED
Definition: winuser.h:128
#define CMD_CUT
Definition: notepad_res.h:46
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define CMD_SELECT_ALL
Definition: notepad_res.h:50
#define CMD_UNDO
Definition: notepad_res.h:45
#define MF_UNCHECKED
Definition: winuser.h:204
#define CMD_PASTE
Definition: notepad_res.h:48
BOOL bWrapLongLines
Definition: main.h:66
GLboolean enable
Definition: glext.h:11120
#define SendMessage
Definition: winuser.h:5833
#define EM_CANUNDO
Definition: winuser.h:1973
#define HIWORD(l)
Definition: typedefs.h:247
#define GetWindowTextLength
Definition: winuser.h:5789
#define MF_GRAYED
Definition: winuser.h:129
HWND hEdit
Definition: main.h:59
HMENU WINAPI GetMenu(_In_ HWND)
HWND hMainWnd
Definition: main.h:57
#define LOWORD(l)
Definition: pedump.c:82
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by NOTEPAD_WndProc().

◆ NOTEPAD_MenuCommand()

static int NOTEPAD_MenuCommand ( WPARAM  wParam)
static

Definition at line 64 of file main.c.

65 {
66  switch (wParam)
67  {
68  case CMD_NEW: DIALOG_FileNew(); break;
69  case CMD_NEW_WINDOW: DIALOG_FileNewWindow(); break;
70  case CMD_OPEN: DIALOG_FileOpen(); break;
71  case CMD_SAVE: DIALOG_FileSave(); break;
72  case CMD_SAVE_AS: DIALOG_FileSaveAs(); break;
73  case CMD_PRINT: DIALOG_FilePrint(); break;
74  case CMD_PAGE_SETUP: DIALOG_FilePageSetup(); break;
75  case CMD_EXIT: DIALOG_FileExit(); break;
76 
77  case CMD_UNDO: DIALOG_EditUndo(); break;
78  case CMD_CUT: DIALOG_EditCut(); break;
79  case CMD_COPY: DIALOG_EditCopy(); break;
80  case CMD_PASTE: DIALOG_EditPaste(); break;
81  case CMD_DELETE: DIALOG_EditDelete(); break;
82  case CMD_SELECT_ALL: DIALOG_EditSelectAll(); break;
83  case CMD_TIME_DATE: DIALOG_EditTimeDate(); break;
84 
85  case CMD_SEARCH: DIALOG_Search(); break;
86  case CMD_SEARCH_NEXT: DIALOG_SearchNext(); break;
87  case CMD_REPLACE: DIALOG_Replace(); break;
88  case CMD_GOTO: DIALOG_GoTo(); break;
89 
90  case CMD_WRAP: DIALOG_EditWrap(); break;
91  case CMD_FONT: DIALOG_SelectFont(); break;
92 
93  case CMD_STATUSBAR: DIALOG_ViewStatusBar(); break;
94 
97 
98  default:
99  break;
100  }
101  return 0;
102 }
VOID DIALOG_Search(VOID)
Definition: dialog.c:1168
#define CMD_HELP_CONTENTS
Definition: notepad_res.h:64
#define CMD_WRAP
Definition: notepad_res.h:58
VOID DIALOG_FileExit(VOID)
Definition: dialog.c:867
VOID DIALOG_EditSelectAll(VOID)
Definition: dialog.c:897
#define CMD_EXIT
Definition: resources.h:17
#define CMD_SEARCH
Definition: notepad_res.h:53
VOID DIALOG_EditCopy(VOID)
Definition: dialog.c:882
#define CMD_GOTO
Definition: notepad_res.h:56
#define CMD_DELETE
Definition: resources.h:18
#define CMD_SAVE_AS
Definition: resources.h:16
WPARAM wParam
Definition: combotst.c:138
#define CMD_PRINT
Definition: notepad_res.h:41
#define CMD_STATUSBAR
Definition: notepad_res.h:61
VOID DIALOG_EditDelete(VOID)
Definition: dialog.c:892
VOID DIALOG_FilePageSetup(void)
Definition: dialog.c:1308
#define CMD_OPEN
Definition: resources.h:15
#define CMD_REPLACE
Definition: notepad_res.h:55
VOID DIALOG_SelectFont(VOID)
Definition: dialog.c:1118
VOID DIALOG_GoTo(VOID)
Definition: dialog.c:1222
VOID DIALOG_SearchNext(VOID)
Definition: dialog.c:1173
#define CMD_NEW_WINDOW
Definition: notepad_res.h:37
#define CMD_SAVE
Definition: notepad_res.h:39
#define CMD_COPY
Definition: notepad_res.h:47
VOID DIALOG_EditPaste(VOID)
Definition: dialog.c:887
VOID DIALOG_FileOpen(VOID)
Definition: dialog.c:496
#define CMD_CUT
Definition: notepad_res.h:46
VOID DIALOG_FilePrint(VOID)
Definition: dialog.c:652
#define CMD_PAGE_SETUP
Definition: notepad_res.h:42
#define CMD_SELECT_ALL
Definition: notepad_res.h:50
#define CMD_UNDO
Definition: notepad_res.h:45
#define CMD_PASTE
Definition: notepad_res.h:48
#define CMD_SEARCH_NEXT
Definition: notepad_res.h:54
VOID DIALOG_EditUndo(VOID)
Definition: dialog.c:872
VOID DIALOG_Replace(VOID)
Definition: dialog.c:1181
VOID DIALOG_EditCut(VOID)
Definition: dialog.c:877
BOOL DIALOG_FileSaveAs(VOID)
Definition: dialog.c:600
#define CMD_HELP_ABOUT_NOTEPAD
Definition: notepad_res.h:65
VOID DIALOG_HelpAboutNotepad(VOID)
Definition: dialog.c:1290
VOID DIALOG_FileNew(VOID)
Definition: dialog.c:478
#define CMD_TIME_DATE
Definition: notepad_res.h:51
VOID DIALOG_EditWrap(VOID)
Definition: dialog.c:1102
VOID DIALOG_HelpContents(VOID)
Definition: dialog.c:1285
VOID DIALOG_EditTimeDate(VOID)
Definition: dialog.c:902
VOID DIALOG_ViewStatusBar(VOID)
Definition: dialog.c:1278
#define CMD_NEW
Definition: notepad_res.h:36
VOID DIALOG_FileNewWindow(VOID)
Definition: dialog.c:489
BOOL DIALOG_FileSave(VOID)
Definition: dialog.c:525
#define CMD_FONT
Definition: notepad_res.h:59

Referenced by NOTEPAD_WndProc().

◆ NOTEPAD_ReplaceAll()

static VOID NOTEPAD_ReplaceAll ( FINDREPLACE pFindReplace)
static

Definition at line 234 of file main.c.

235 {
236  BOOL bShowAlert = TRUE;
237 
239 
240  while (NOTEPAD_FindNext(pFindReplace, TRUE, bShowAlert))
241  {
242  bShowAlert = FALSE;
243  }
244 }
NOTEPAD_GLOBALS Globals
Definition: main.c:31
#define TRUE
Definition: types.h:120
BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bShowAlert)
Definition: main.c:144
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define EM_SETSEL
Definition: winuser.h:2008
#define SendMessage
Definition: winuser.h:5833
HWND hEdit
Definition: main.h:59

Referenced by NOTEPAD_WndProc().

◆ NOTEPAD_WndProc()

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

Definition at line 347 of file main.c.

348 {
349  switch (msg)
350  {
351 
352  case WM_CREATE:
354 
355  // For now, the "Help" dialog is disabled due to the lack of HTML Help support
357  break;
358 
359  case WM_COMMAND:
362  if ((HIWORD(wParam) == EN_CHANGE))
365  break;
366 
367  case WM_DESTROYCLIPBOARD:
368  /*MessageBox(Globals.hMainWnd, "Empty clipboard", "Debug", MB_ICONEXCLAMATION);*/
369  break;
370 
371  case WM_CLOSE:
372  if (DoCloseFile()) {
373  if (Globals.hFont)
375  if (Globals.hDevMode)
377  if (Globals.hDevNames)
380  }
381  break;
382 
383  case WM_QUERYENDSESSION:
384  if (DoCloseFile()) {
385  return 1;
386  }
387  break;
388 
389  case WM_DESTROY:
392  PostQuitMessage(0);
393  break;
394 
395  case WM_SIZE:
396  {
398  {
399  RECT rcStatusBar;
400  HDWP hdwp;
401 
402  if (!GetWindowRect(Globals.hStatusBar, &rcStatusBar))
403  break;
404 
405  hdwp = BeginDeferWindowPos(2);
406  if (hdwp == NULL)
407  break;
408 
409  hdwp = DeferWindowPos(hdwp,
410  Globals.hEdit,
411  NULL,
412  0,
413  0,
414  LOWORD(lParam),
415  HIWORD(lParam) - (rcStatusBar.bottom - rcStatusBar.top),
417 
418  if (hdwp == NULL)
419  break;
420 
421  hdwp = DeferWindowPos(hdwp,
423  NULL,
424  0,
425  0,
426  LOWORD(lParam),
427  LOWORD(wParam),
428  SWP_NOZORDER);
429 
430  if (hdwp == NULL)
431  break;
432 
433  EndDeferWindowPos(hdwp);
434 
435  /* Align status bar parts, only if the status bar resize operation succeeds */
437  }
438  else
440  NULL,
441  0,
442  0,
443  LOWORD(lParam),
444  HIWORD(lParam),
446 
447  break;
448  }
449 
450  /* The entire client area is covered by edit control and by
451  * the status bar. So there is no need to erase main background.
452  * This resolves the horrible flicker effect during windows resizes. */
453  case WM_ERASEBKGND:
454  return 1;
455 
456  case WM_SETFOCUS:
458  break;
459 
460  case WM_DROPFILES:
461  {
462  TCHAR szFileName[MAX_PATH];
463  HDROP hDrop = (HDROP) wParam;
464 
465  DragQueryFile(hDrop, 0, szFileName, ARRAY_SIZE(szFileName));
466  DragFinish(hDrop);
467  DoOpenFile(szFileName);
468  break;
469  }
470  case WM_CHAR:
471  case WM_INITMENUPOPUP:
473  break;
474  default:
475  if (msg == aFINDMSGSTRING)
476  {
477  FINDREPLACE *pFindReplace = (FINDREPLACE *) lParam;
479 
480  if (pFindReplace->Flags & FR_FINDNEXT)
481  NOTEPAD_FindNext(pFindReplace, FALSE, TRUE);
482  else if (pFindReplace->Flags & FR_REPLACE)
483  NOTEPAD_FindNext(pFindReplace, TRUE, TRUE);
484  else if (pFindReplace->Flags & FR_REPLACEALL)
485  NOTEPAD_ReplaceAll(pFindReplace);
486  else if (pFindReplace->Flags & FR_DIALOGTERM)
488  break;
489  }
490 
491  return DefWindowProc(hWnd, msg, wParam, lParam);
492  }
493  return 0;
494 }
#define FR_FINDNEXT
Definition: commdlg.h:131
#define CMD_HELP_CONTENTS
Definition: notepad_res.h:64
HDWP WINAPI BeginDeferWindowPos(_In_ int)
NOTEPAD_GLOBALS Globals
Definition: main.c:31
#define MF_BYCOMMAND
Definition: winuser.h:202
#define WM_CHAR
Definition: winuser.h:1707
#define TRUE
Definition: types.h:120
#define WM_INITMENUPOPUP
Definition: winuser.h:1736
#define WM_QUERYENDSESSION
Definition: winuser.h:1612
HWND hWnd
Definition: settings.c:17
LONG top
Definition: windef.h:307
HGLOBAL hDevNames
Definition: main.h:64
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HWND WINAPI SetFocus(_In_opt_ HWND)
WNDPROC EditProc
Definition: main.h:82
HGLOBAL hDevMode
Definition: main.h:63
#define SWP_NOZORDER
Definition: winuser.h:1237
BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bShowAlert)
Definition: main.c:144
BOOL WINAPI DestroyWindow(_In_ HWND)
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
#define FR_REPLACEALL
Definition: commdlg.h:143
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
HMENU hMenu
Definition: main.h:62
#define FALSE
Definition: types.h:117
static VOID DoOpenFile(PINFO pInfo)
Definition: connectdialog.c:34
DWORD Flags
Definition: commdlg.h:306
static VOID NOTEPAD_ReplaceAll(FINDREPLACE *pFindReplace)
Definition: main.c:234
BOOL WINAPI EndDeferWindowPos(_In_ HDWP)
BOOL DoCloseFile(VOID)
Definition: dialog.c:388
#define WM_DROPFILES
Definition: winuser.h:1815
BOOL bShowStatusBar
Definition: main.h:67
static int NOTEPAD_MenuCommand(WPARAM wParam)
Definition: main.c:64
HFONT hFont
Definition: main.h:61
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1599
char TCHAR
Definition: xmlstorage.h:189
HWND hStatusBar
Definition: main.h:60
HDWP WINAPI DeferWindowPos(_In_ HDWP, _In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define WM_SIZE
Definition: winuser.h:1601
#define WM_CLOSE
Definition: winuser.h:1611
#define MAX_PATH
Definition: compat.h:34
VOID DIALOG_StatusBarUpdateCaretPos(VOID)
Definition: dialog.c:1264
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define FR_REPLACE
Definition: commdlg.h:142
#define WM_COMMAND
Definition: winuser.h:1730
#define EN_HSCROLL
Definition: winuser.h:2014
#define GWLP_WNDPROC
Definition: treelist.c:66
#define EN_VSCROLL
Definition: winuser.h:2019
BOOL bWrapLongLines
Definition: main.h:66
#define ARRAY_SIZE(a)
Definition: main.h:24
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define NULL
Definition: types.h:112
#define DragQueryFile
Definition: shellapi.h:684
#define msg(x)
Definition: auth_time.c:54
VOID NOTEPAD_EnableSearchMenu()
Definition: main.c:34
void WINAPI DragFinish(HDROP h)
Definition: shellole.c:538
#define WM_DESTROYCLIPBOARD
Definition: winuser.h:1858
#define WM_CREATE
Definition: winuser.h:1598
#define HIWORD(l)
Definition: typedefs.h:247
void NOTEPAD_SaveSettingsToRegistry(void)
Definition: settings.c:241
LONG bottom
Definition: windef.h:309
#define SWP_NOMOVE
Definition: winuser.h:1234
static ATOM aFINDMSGSTRING
Definition: main.c:32
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
#define FR_DIALOGTERM
Definition: commdlg.h:126
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define WM_ERASEBKGND
Definition: winuser.h:1615
#define WM_SETFOCUS
Definition: winuser.h:1603
#define MF_GRAYED
Definition: winuser.h:129
HWND hEdit
Definition: main.h:59
static VOID NOTEPAD_InitMenuPopup(HMENU menu, LPARAM index)
Definition: main.c:282
HMENU WINAPI GetMenu(_In_ HWND)
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
static VOID NOTEPAD_FindTerm(VOID)
Definition: main.c:251
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
FINDREPLACE find
Definition: main.h:81
VOID DIALOG_StatusBarAlignParts(VOID)
Definition: dialog.c:128
#define EN_CHANGE
Definition: winuser.h:2012

Referenced by _tWinMain().

◆ SetFileName()

VOID SetFileName ( LPCTSTR  szFileName)

Definition at line 48 of file main.c.

49 {
51  Globals.szFileTitle[0] = 0;
53 
54  if (szFileName && szFileName[0])
55  SHAddToRecentDocs(SHARD_PATHW, szFileName);
56 }
NOTEPAD_GLOBALS Globals
Definition: main.c:31
TCHAR szFileName[MAX_PATH]
Definition: main.h:70
void WINAPI SHAddToRecentDocs(UINT uFlags, LPCVOID pv)
Definition: shellord.c:809
#define GetFileTitle
Definition: commdlg.h:664
#define StringCchCopy
Definition: strsafe.h:139
#define ARRAY_SIZE(a)
Definition: main.h:24
#define SHARD_PATHW
Definition: shlobj.h:1103
TCHAR szFileTitle[MAX_PATH]
Definition: main.h:71

Variable Documentation

◆ aFINDMSGSTRING

ATOM aFINDMSGSTRING
static

Definition at line 32 of file main.c.

Referenced by _tWinMain(), and NOTEPAD_WndProc().

◆ Globals