ReactOS  0.4.11-dev-946-g431643b
main.c File Reference
#include "notepad.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 581 of file main.c.

582 {
583  MSG msg;
584  HACCEL hAccel;
585  WNDCLASSEX wndclass;
586  HMONITOR monitor;
588  INT x, y;
589 
590  static const TCHAR className[] = _T("Notepad");
591  static const TCHAR winName[] = _T("Notepad");
592 
593  switch (GetUserDefaultUILanguage())
594  {
597  break;
598 
599  default:
600  break;
601  }
602 
604 
606 
607  ZeroMemory(&Globals, sizeof(Globals));
610 
611  ZeroMemory(&wndclass, sizeof(wndclass));
612  wndclass.cbSize = sizeof(wndclass);
613  wndclass.lpfnWndProc = NOTEPAD_WndProc;
614  wndclass.hInstance = Globals.hInstance;
615  wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NPICON));
616  wndclass.hCursor = LoadCursor(0, IDC_ARROW);
617  wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
619  wndclass.lpszClassName = className;
620  wndclass.hIconSm = (HICON)LoadImage(hInstance,
622  IMAGE_ICON,
623  16,
624  16,
625  0);
626 
627  if (!RegisterClassEx(&wndclass)) return FALSE;
628 
629  /* Setup windows */
630 
631  monitor = MonitorFromRect(&Globals.main_rect, MONITOR_DEFAULTTOPRIMARY);
632  info.cbSize = sizeof(info);
633  GetMonitorInfoW(monitor, &info);
634 
635  x = Globals.main_rect.left;
636  y = Globals.main_rect.top;
637  if (Globals.main_rect.left >= info.rcWork.right ||
638  Globals.main_rect.top >= info.rcWork.bottom ||
639  Globals.main_rect.right < info.rcWork.left ||
641  x = y = CW_USEDEFAULT;
642 
643  Globals.hMainWnd = CreateWindow(className,
644  winName,
646  x,
647  y,
650  NULL,
651  NULL,
653  NULL);
654  if (!Globals.hMainWnd)
655  {
656  ShowLastError();
657  ExitProcess(1);
658  }
659 
661 
663  DIALOG_FileNew();
664 
665  ShowWindow(Globals.hMainWnd, show);
668 
670 
672  {
673  return 0;
674  }
675 
676  hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(ID_ACCEL));
677 
678  while (GetMessage(&msg, 0, 0, 0))
679  {
681  !TranslateAccelerator(Globals.hMainWnd, hAccel, &msg))
682  {
683  TranslateMessage(&msg);
684  DispatchMessage(&msg);
685  }
686  }
687  return (int) msg.wParam;
688 }
HWND hFindReplaceDlg
Definition: main.h:61
#define TranslateAccelerator
Definition: winuser.h:5726
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define DispatchMessage
Definition: winuser.h:5631
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: lang.c:561
BOOL WINAPI TranslateMessage(_In_ const MSG *)
static HICON
Definition: imagelist.c:84
LPCSTR lpszMenuName
Definition: winuser.h:3163
#define TRUE
Definition: types.h:120
NOTEPAD_GLOBALS Globals
Definition: main.c:29
#define IMAGE_ICON
Definition: winuser.h:212
#define RegisterClassEx
Definition: winuser.h:5703
#define LAYOUT_RTL
Definition: wingdi.h:1352
HCURSOR hCursor
Definition: winuser.h:3161
WNDPROC lpfnWndProc
Definition: winuser.h:3156
#define CreateWindow
Definition: winuser.h:5620
static VOID NOTEPAD_InitData(VOID)
Definition: main.c:253
LPCSTR lpszClassName
Definition: winuser.h:3164
WORD ATOM
Definition: dimm.idl:113
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
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:527
LONG top
Definition: windef.h:297
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1517
#define ZeroMemory
Definition: winbase.h:1635
TCHAR * cmdline
Definition: stretchblt.cpp:32
HICON hIconSm
Definition: winuser.h:3165
LONG left
Definition: windef.h:296
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define IsDialogMessage
Definition: winuser.h:5675
LONG right
Definition: windef.h:298
#define COLOR_WINDOW
Definition: winuser.h:908
int32_t INT
Definition: typedefs.h:56
#define LANG_HEBREW
Definition: nls.h:67
struct _test_info info[]
Definition: SetCursorPos.c:19
HINSTANCE hInstance
Definition: main.h:59
INT INT y
Definition: msvc.h:62
#define LoadAccelerators
Definition: winuser.h:5676
HINSTANCE hInstance
Definition: winuser.h:3159
HACCEL hAccel
Definition: main.c:47
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
UINT cbSize
Definition: winuser.h:3154
HBRUSH hbrBackground
Definition: winuser.h:3162
VOID DoCreateEditWindow(VOID)
Definition: dialog.c:901
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1686
RECT main_rect
Definition: main.h:86
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:38
BOOL WINAPI GetMonitorInfoW(_In_ HMONITOR, _Inout_ LPMONITORINFO)
HINSTANCE hInstance
Definition: main.c:36
HICON hIcon
Definition: winuser.h:3160
static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: main.c:341
#define LoadCursor
Definition: winuser.h:5678
#define RegisterWindowMessage
Definition: winuser.h:5706
INT x
Definition: msvc.h:62
DWORD cbSize
Definition: winuser.h:3726
static BOOL HandleCommandLine(LPTSTR cmdline)
Definition: main.c:492
#define IDI_NPICON
Definition: notepad_res.h:32
#define GetMessage
Definition: winuser.h:5656
#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:299
VOID DIALOG_FileNew(VOID)
Definition: dialog.c:398
static ATOM aFINDMSGSTRING
Definition: main.c:30
#define LoadImage
Definition: winuser.h:5681
#define LoadIcon
Definition: winuser.h:5679
VOID DIALOG_ViewStatusBar(VOID)
Definition: dialog.c:1179
HWND hMainWnd
Definition: main.h:60

◆ AlertFileDoesNotExist()

static int AlertFileDoesNotExist ( LPCTSTR  szFileName)
static

Definition at line 485 of file main.c.

Referenced by HandleCommandLine().

486 {
488  szFileName,
490 }
NOTEPAD_GLOBALS Globals
Definition: main.c:29
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
#define STRING_DOESNOTEXIST
Definition: notepad_res.h:83
#define MB_YESNO
Definition: winuser.h:811
int DIALOG_StringMsgBox(HWND hParent, int formatId, LPCTSTR szString, DWORD dwFlags)
Definition: dialog.c:98
HWND hMainWnd
Definition: main.h:60

◆ EDIT_WndProc()

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

Definition at line 304 of file main.c.

Referenced by DoCreateEditWindow().

305 {
306  switch (msg)
307  {
308  case WM_KEYDOWN:
309  case WM_KEYUP:
310  {
311  switch (wParam)
312  {
313  case VK_UP:
314  case VK_DOWN:
315  case VK_LEFT:
316  case VK_RIGHT:
318  break;
319  default:
320  {
322  break;
323  }
324  }
325  }
326  case WM_LBUTTONUP:
327  {
329  break;
330  }
331  }
332  return CallWindowProc( Globals.EditProc, hWnd, msg, wParam, lParam);
333 }
#define CallWindowProc
Definition: winuser.h:5601
NOTEPAD_GLOBALS Globals
Definition: main.c:29
#define VK_LEFT
Definition: winuser.h:2178
#define VK_DOWN
Definition: winuser.h:2181
WNDPROC EditProc
Definition: main.h:85
WPARAM wParam
Definition: combotst.c:138
#define VK_UP
Definition: winuser.h:2179
UINT msg
Definition: msvc.h:92
#define WM_KEYDOWN
Definition: winuser.h:1691
VOID DIALOG_StatusBarUpdateCaretPos(VOID)
Definition: dialog.c:1165
#define WM_KEYUP
Definition: winuser.h:1692
#define VK_RIGHT
Definition: winuser.h:2180
#define WM_LBUTTONUP
Definition: winuser.h:1753
LPARAM lParam
Definition: combotst.c:139
void UpdateWindowCaption(HWND hwnd)
Definition: mplay32.c:96

◆ HandleCommandLine()

static BOOL HandleCommandLine ( LPTSTR  cmdline)
static

Definition at line 492 of file main.c.

Referenced by _tWinMain().

493 {
494  BOOL opt_print = FALSE;
495 
496  while (*cmdline == _T(' ') || *cmdline == _T('-') || *cmdline == _T('/'))
497  {
498  TCHAR option;
499 
500  if (*cmdline++ == _T(' ')) continue;
501 
502  option = *cmdline;
503  if (option) cmdline++;
504  while (*cmdline == _T(' ')) cmdline++;
505 
506  switch(option)
507  {
508  case 'p':
509  case 'P':
510  opt_print = TRUE;
511  break;
512  }
513  }
514 
515  if (*cmdline)
516  {
517  /* file name is passed in the command line */
520  TCHAR buf[MAX_PATH];
521 
522  if (cmdline[0] == _T('"'))
523  {
524  cmdline++;
525  cmdline[lstrlen(cmdline) - 1] = 0;
526  }
527 
528  file_name = cmdline;
529  if (FileExists(file_name))
530  {
531  file_exists = TRUE;
532  }
533  else if (!HasFileExtension(cmdline))
534  {
535  static const TCHAR txt[] = _T(".txt");
536 
537  /* try to find file with ".txt" extension */
538  if (!_tcscmp(txt, cmdline + _tcslen(cmdline) - _tcslen(txt)))
539  {
540  file_exists = FALSE;
541  }
542  else
543  {
544  _tcsncpy(buf, cmdline, MAX_PATH - _tcslen(txt) - 1);
545  _tcscat(buf, txt);
546  file_name = buf;
547  file_exists = FileExists(file_name);
548  }
549  }
550 
551  if (file_exists)
552  {
553  DoOpenFile(file_name);
555  if (opt_print)
556  {
558  return FALSE;
559  }
560  }
561  else
562  {
563  switch (AlertFileDoesNotExist(file_name)) {
564  case IDYES:
565  DoOpenFile(file_name);
566  break;
567 
568  case IDNO:
569  break;
570  }
571  }
572  }
573 
574  return TRUE;
575 }
#define TRUE
Definition: types.h:120
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
NOTEPAD_GLOBALS Globals
Definition: main.c:29
#define IDYES
Definition: winuser.h:829
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
_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:162
BOOL FileExists(LPCTSTR szFilename)
Definition: dialog.c:151
static VOID DoOpenFile(PINFO pInfo)
Definition: connectdialog.c:34
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
GLuint GLenum option
Definition: glext.h:11211
static int AlertFileDoesNotExist(LPCTSTR szFileName)
Definition: main.c:485
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
unsigned int BOOL
Definition: ntddk_ex.h:94
#define MAX_PATH
Definition: compat.h:26
VOID DIALOG_FilePrint(VOID)
Definition: dialog.c:557
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:3690
static LPCWSTR file_name
Definition: protocol.c:146
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
#define IDNO
Definition: winuser.h:830
HWND hMainWnd
Definition: main.h:60

◆ NOTEPAD_EnableSearchMenu()

VOID NOTEPAD_EnableSearchMenu ( )

Definition at line 32 of file main.c.

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

33 {
38 }
#define MF_DISABLED
Definition: winuser.h:130
NOTEPAD_GLOBALS Globals
Definition: main.c:29
#define MF_BYCOMMAND
Definition: winuser.h:202
#define CMD_SEARCH
Definition: notepad_res.h:52
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
HMENU hMenu
Definition: main.h:65
#define MF_ENABLED
Definition: winuser.h:128
#define CMD_SEARCH_NEXT
Definition: notepad_res.h:53
#define GetWindowTextLength
Definition: winuser.h:5665
#define MF_GRAYED
Definition: winuser.h:129
HWND hEdit
Definition: main.h:62

◆ NOTEPAD_FindNext()

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

Definition at line 138 of file main.c.

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

139 {
140  int iTextLength, iTargetLength;
141  size_t iAdjustment = 0;
142  LPTSTR pszText = NULL;
143  DWORD dwPosition, dwBegin, dwEnd;
144  BOOL bMatches = FALSE;
145  TCHAR szResource[128], szText[128];
146  BOOL bSuccess;
147 
148  iTargetLength = (int) _tcslen(pFindReplace->lpstrFindWhat);
149 
150  /* Retrieve the window text */
151  iTextLength = GetWindowTextLength(Globals.hEdit);
152  if (iTextLength > 0)
153  {
154  pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (iTextLength + 1) * sizeof(TCHAR));
155  if (!pszText)
156  return FALSE;
157 
158  GetWindowText(Globals.hEdit, pszText, iTextLength + 1);
159  }
160 
161  SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM) &dwBegin, (LPARAM) &dwEnd);
162  if (bReplace && ((dwEnd - dwBegin) == (DWORD) iTargetLength))
163  {
164  if (NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwBegin))
165  {
167  iAdjustment = _tcslen(pFindReplace->lpstrReplaceWith) - (dwEnd - dwBegin);
168  }
169  }
170 
171  if (pFindReplace->Flags & FR_DOWN)
172  {
173  /* Find Down */
174  dwPosition = dwEnd;
175  while(dwPosition < (DWORD) iTextLength)
176  {
177  bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
178  if (bMatches)
179  break;
180  dwPosition++;
181  }
182  }
183  else
184  {
185  /* Find Up */
186  dwPosition = dwBegin;
187  while(dwPosition > 0)
188  {
189  dwPosition--;
190  bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
191  if (bMatches)
192  break;
193  }
194  }
195 
196  if (bMatches)
197  {
198  /* Found target */
199  if (dwPosition > dwBegin)
200  dwPosition += (DWORD) iAdjustment;
201  SendMessage(Globals.hEdit, EM_SETSEL, dwPosition, dwPosition + iTargetLength);
203  bSuccess = TRUE;
204  }
205  else
206  {
207  /* Can't find target */
208  if (bShowAlert)
209  {
210  LoadString(Globals.hInstance, STRING_CANNOTFIND, szResource, ARRAY_SIZE(szResource));
211  _sntprintf(szText, ARRAY_SIZE(szText), szResource, pFindReplace->lpstrFindWhat);
212  LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, ARRAY_SIZE(szResource));
213  MessageBox(Globals.hFindReplaceDlg, szText, szResource, MB_OK);
214  }
215  bSuccess = FALSE;
216  }
217 
218  if (pszText)
219  HeapFree(GetProcessHeap(), 0, pszText);
220  return bSuccess;
221 }
HWND hFindReplaceDlg
Definition: main.h:61
#define TRUE
Definition: types.h:120
NOTEPAD_GLOBALS Globals
Definition: main.c:29
#define DWORD
Definition: msvc.h:34
LPCWSTR pszText
Definition: msvc.h:103
LPSTR lpstrFindWhat
Definition: commdlg.h:307
static BOOLEAN bSuccess
Definition: drive.cpp:419
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define GetWindowText
Definition: winuser.h:5664
UINT_PTR WPARAM
Definition: windef.h:207
HINSTANCE hInstance
Definition: main.h:59
#define EM_GETSEL
Definition: winuser.h:1958
#define STRING_NOTEPAD
Definition: notepad_res.h:74
static const WCHAR szText[]
Definition: dialog.c:139
static BOOL NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, int iTextLength, DWORD dwPosition)
Definition: main.c:104
DWORD Flags
Definition: commdlg.h:306
LONG_PTR LPARAM
Definition: windef.h:208
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
char TCHAR
Definition: xmlstorage.h:189
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define EM_SETSEL
Definition: winuser.h:1979
unsigned long DWORD
Definition: ntddk_ex.h:95
#define _sntprintf
Definition: xmlstorage.h:201
#define MessageBox
Definition: winuser.h:5688
LPSTR lpstrReplaceWith
Definition: commdlg.h:308
#define ARRAY_SIZE(a)
Definition: main.h:24
#define MB_OK
Definition: winuser.h:784
#define FR_DOWN
Definition: commdlg.h:127
#define STRING_CANNOTFIND
Definition: notepad_res.h:88
#define SendMessage
Definition: winuser.h:5709
#define GetWindowTextLength
Definition: winuser.h:5665
HWND hEdit
Definition: main.h:62
#define HeapFree(x, y, z)
Definition: compat.h:394
#define LoadString
Definition: winuser.h:5685
#define EM_REPLACESEL
Definition: winuser.h:1967
#define EM_SCROLLCARET
Definition: richedit.h:81
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:29

◆ NOTEPAD_FindTerm()

static VOID NOTEPAD_FindTerm ( VOID  )
static

Definition at line 245 of file main.c.

Referenced by NOTEPAD_WndProc().

246 {
248 }
HWND hFindReplaceDlg
Definition: main.h:61
NOTEPAD_GLOBALS Globals
Definition: main.c:29
smooth NULL
Definition: ftsmooth.c:416

◆ NOTEPAD_FindTextAt()

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

Definition at line 104 of file main.c.

Referenced by NOTEPAD_FindNext().

105 {
106  BOOL bMatches;
107  size_t iTargetLength;
108 
109  if ((!pFindReplace) || (!pszText))
110  {
111  return FALSE;
112  }
113 
114  iTargetLength = _tcslen(pFindReplace->lpstrFindWhat);
115 
116  /* Make proper comparison */
117  if (pFindReplace->Flags & FR_MATCHCASE)
118  bMatches = !_tcsncmp(&pszText[dwPosition], pFindReplace->lpstrFindWhat, iTargetLength);
119  else
120  bMatches = !_tcsnicmp(&pszText[dwPosition], pFindReplace->lpstrFindWhat, iTargetLength);
121 
122  if (bMatches && pFindReplace->Flags & FR_WHOLEWORD)
123  {
124  if ((dwPosition > 0) && !_istspace(pszText[dwPosition-1]))
125  bMatches = FALSE;
126  if ((dwPosition < (DWORD) iTextLength - 1) && !_istspace(pszText[dwPosition+1]))
127  bMatches = FALSE;
128  }
129 
130  return bMatches;
131 }
LPCWSTR pszText
Definition: msvc.h:103
LPSTR lpstrFindWhat
Definition: commdlg.h:307
#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 int BOOL
Definition: ntddk_ex.h:94
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

◆ NOTEPAD_InitData()

static VOID NOTEPAD_InitData ( VOID  )
static

Definition at line 253 of file main.c.

Referenced by _tWinMain().

254 {
256  static const TCHAR txt_files[] = _T("*.txt");
257  static const TCHAR all_files[] = _T("*.*");
258 
260  _tcscpy(p, txt_files);
261  p += ARRAY_SIZE(txt_files);
262 
264  _tcscpy(p, all_files);
265  p += ARRAY_SIZE(all_files);
266  *p = '\0';
268 
271 }
NOTEPAD_GLOBALS Globals
Definition: main.c:29
LPSTR lpstrFindWhat
Definition: commdlg.h:307
HGLOBAL hDevNames
Definition: main.h:67
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
HGLOBAL hDevMode
Definition: main.h:66
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define STRING_TEXT_FILES_TXT
Definition: notepad_res.h:80
HINSTANCE hInstance
Definition: main.h:59
smooth NULL
Definition: ftsmooth.c:416
#define STRING_ALL_FILES
Definition: notepad_res.h:79
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:75
int all_files
Definition: mkisofs.c:132
#define ARRAY_SIZE(a)
Definition: main.h:24
#define MAX_STRING_LEN
Definition: main.c:65
GLfloat GLfloat p
Definition: glext.h:8902
#define LoadString
Definition: winuser.h:5685
FINDREPLACE find
Definition: main.h:84

◆ NOTEPAD_InitMenuPopup()

static VOID NOTEPAD_InitMenuPopup ( HMENU  menu,
LPARAM  index 
)
static

Definition at line 276 of file main.c.

Referenced by NOTEPAD_WndProc().

277 {
278  int enable;
279 
281 
284  if (!Globals.bWrapLongLines)
285  {
288  }
289  EnableMenuItem(menu, CMD_UNDO,
293  enable = (int) SendMessage(Globals.hEdit, EM_GETSEL, 0, 0);
294  enable = (HIWORD(enable) == LOWORD(enable)) ? MF_GRAYED : MF_ENABLED;
295  EnableMenuItem(menu, CMD_CUT, enable);
296  EnableMenuItem(menu, CMD_COPY, enable);
297  EnableMenuItem(menu, CMD_DELETE, enable);
298 
302 }
NOTEPAD_GLOBALS Globals
Definition: main.c:29
BOOL WINAPI DrawMenuBar(_In_ HWND)
BOOL WINAPI IsClipboardFormatAvailable(_In_ UINT)
#define MF_BYCOMMAND
Definition: winuser.h:202
#define CMD_WRAP
Definition: notepad_res.h:57
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define CMD_DELETE
Definition: resources.h:18
#define EM_GETSEL
Definition: winuser.h:1958
#define CMD_STATUSBAR
Definition: notepad_res.h:60
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
BOOL bShowStatusBar
Definition: main.h:70
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:46
#define MF_ENABLED
Definition: winuser.h:128
#define CMD_CUT
Definition: notepad_res.h:45
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define CMD_SELECT_ALL
Definition: notepad_res.h:49
#define CMD_UNDO
Definition: notepad_res.h:44
#define MF_UNCHECKED
Definition: winuser.h:204
#define CMD_PASTE
Definition: notepad_res.h:47
BOOL bWrapLongLines
Definition: main.h:69
GLboolean enable
Definition: glext.h:11120
#define SendMessage
Definition: winuser.h:5709
#define EM_CANUNDO
Definition: winuser.h:1944
#define HIWORD(l)
Definition: typedefs.h:246
#define GetWindowTextLength
Definition: winuser.h:5665
#define MF_GRAYED
Definition: winuser.h:129
HWND hEdit
Definition: main.h:62
HMENU WINAPI GetMenu(_In_ HWND)
HWND hMainWnd
Definition: main.h:60
#define LOWORD(l)
Definition: pedump.c:82
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:29

◆ NOTEPAD_MenuCommand()

static int NOTEPAD_MenuCommand ( WPARAM  wParam)
static

Definition at line 59 of file main.c.

Referenced by NOTEPAD_WndProc().

60 {
61  switch (wParam)
62  {
63  case CMD_NEW: DIALOG_FileNew(); break;
64  case CMD_OPEN: DIALOG_FileOpen(); break;
65  case CMD_SAVE: DIALOG_FileSave(); break;
66  case CMD_SAVE_AS: DIALOG_FileSaveAs(); break;
67  case CMD_PRINT: DIALOG_FilePrint(); break;
68  case CMD_PAGE_SETUP: DIALOG_FilePageSetup(); break;
69  case CMD_EXIT: DIALOG_FileExit(); break;
70 
71  case CMD_UNDO: DIALOG_EditUndo(); break;
72  case CMD_CUT: DIALOG_EditCut(); break;
73  case CMD_COPY: DIALOG_EditCopy(); break;
74  case CMD_PASTE: DIALOG_EditPaste(); break;
75  case CMD_DELETE: DIALOG_EditDelete(); break;
76  case CMD_SELECT_ALL: DIALOG_EditSelectAll(); break;
77  case CMD_TIME_DATE: DIALOG_EditTimeDate(); break;
78 
79  case CMD_SEARCH: DIALOG_Search(); break;
80  case CMD_SEARCH_NEXT: DIALOG_SearchNext(); break;
81  case CMD_REPLACE: DIALOG_Replace(); break;
82  case CMD_GOTO: DIALOG_GoTo(); break;
83 
84  case CMD_WRAP: DIALOG_EditWrap(); break;
85  case CMD_FONT: DIALOG_SelectFont(); break;
86 
87  case CMD_STATUSBAR: DIALOG_ViewStatusBar(); break;
88 
91 
92  default:
93  break;
94  }
95  return 0;
96 }
VOID DIALOG_Search(VOID)
Definition: dialog.c:1069
#define CMD_HELP_CONTENTS
Definition: notepad_res.h:63
#define CMD_WRAP
Definition: notepad_res.h:57
VOID DIALOG_FileExit(VOID)
Definition: dialog.c:772
VOID DIALOG_EditSelectAll(VOID)
Definition: dialog.c:802
#define CMD_EXIT
Definition: resources.h:17
#define CMD_SEARCH
Definition: notepad_res.h:52
VOID DIALOG_EditCopy(VOID)
Definition: dialog.c:787
#define CMD_GOTO
Definition: notepad_res.h:55
#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:40
#define CMD_STATUSBAR
Definition: notepad_res.h:60
VOID DIALOG_EditDelete(VOID)
Definition: dialog.c:797
VOID DIALOG_FilePageSetup(void)
Definition: dialog.c:1209
#define CMD_OPEN
Definition: resources.h:15
#define CMD_REPLACE
Definition: notepad_res.h:54
VOID DIALOG_SelectFont(VOID)
Definition: dialog.c:1019
VOID DIALOG_GoTo(VOID)
Definition: dialog.c:1123
VOID DIALOG_SearchNext(VOID)
Definition: dialog.c:1074
#define CMD_SAVE
Definition: notepad_res.h:38
#define CMD_COPY
Definition: notepad_res.h:46
VOID DIALOG_EditPaste(VOID)
Definition: dialog.c:792
VOID DIALOG_FileOpen(VOID)
Definition: dialog.c:409
#define CMD_CUT
Definition: notepad_res.h:45
VOID DIALOG_FilePrint(VOID)
Definition: dialog.c:557
#define CMD_PAGE_SETUP
Definition: notepad_res.h:41
#define CMD_SELECT_ALL
Definition: notepad_res.h:49
#define CMD_UNDO
Definition: notepad_res.h:44
#define CMD_PASTE
Definition: notepad_res.h:47
#define CMD_SEARCH_NEXT
Definition: notepad_res.h:53
VOID DIALOG_EditUndo(VOID)
Definition: dialog.c:777
VOID DIALOG_Replace(VOID)
Definition: dialog.c:1082
VOID DIALOG_EditCut(VOID)
Definition: dialog.c:782
BOOL DIALOG_FileSaveAs(VOID)
Definition: dialog.c:510
#define CMD_HELP_ABOUT_NOTEPAD
Definition: notepad_res.h:64
VOID DIALOG_HelpAboutNotepad(VOID)
Definition: dialog.c:1191
VOID DIALOG_FileNew(VOID)
Definition: dialog.c:398
#define CMD_TIME_DATE
Definition: notepad_res.h:50
VOID DIALOG_EditWrap(VOID)
Definition: dialog.c:1003
VOID DIALOG_HelpContents(VOID)
Definition: dialog.c:1186
VOID DIALOG_EditTimeDate(VOID)
Definition: dialog.c:807
VOID DIALOG_ViewStatusBar(VOID)
Definition: dialog.c:1179
#define CMD_NEW
Definition: notepad_res.h:36
BOOL DIALOG_FileSave(VOID)
Definition: dialog.c:438
#define CMD_FONT
Definition: notepad_res.h:58

◆ NOTEPAD_ReplaceAll()

static VOID NOTEPAD_ReplaceAll ( FINDREPLACE pFindReplace)
static

Definition at line 228 of file main.c.

Referenced by NOTEPAD_WndProc().

229 {
230  BOOL bShowAlert = TRUE;
231 
233 
234  while (NOTEPAD_FindNext(pFindReplace, TRUE, bShowAlert))
235  {
236  bShowAlert = FALSE;
237  }
238 }
#define TRUE
Definition: types.h:120
NOTEPAD_GLOBALS Globals
Definition: main.c:29
BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bShowAlert)
Definition: main.c:138
unsigned int BOOL
Definition: ntddk_ex.h:94
#define EM_SETSEL
Definition: winuser.h:1979
#define SendMessage
Definition: winuser.h:5709
HWND hEdit
Definition: main.h:62

◆ NOTEPAD_WndProc()

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

Definition at line 341 of file main.c.

Referenced by _tWinMain().

342 {
343  switch (msg)
344  {
345 
346  case WM_CREATE:
347  Globals.hMenu = GetMenu(hWnd);
348 
349  // For now, the "Help" dialog is disabled due to the lack of HTML Help support
351  break;
352 
353  case WM_COMMAND:
356  if ((HIWORD(wParam) == EN_CHANGE))
359  break;
360 
361  case WM_DESTROYCLIPBOARD:
362  /*MessageBox(Globals.hMainWnd, "Empty clipboard", "Debug", MB_ICONEXCLAMATION);*/
363  break;
364 
365  case WM_CLOSE:
366  if (DoCloseFile()) {
367  if (Globals.hFont)
369  if (Globals.hDevMode)
371  if (Globals.hDevNames)
373  DestroyWindow(hWnd);
374  }
375  break;
376 
377  case WM_QUERYENDSESSION:
378  if (DoCloseFile()) {
379  return 1;
380  }
381  break;
382 
383  case WM_DESTROY:
386  PostQuitMessage(0);
387  break;
388 
389  case WM_SIZE:
390  {
392  {
393  RECT rcStatusBar;
394  HDWP hdwp;
395 
396  if (!GetWindowRect(Globals.hStatusBar, &rcStatusBar))
397  break;
398 
399  hdwp = BeginDeferWindowPos(2);
400  if (hdwp == NULL)
401  break;
402 
403  hdwp = DeferWindowPos(hdwp,
404  Globals.hEdit,
405  NULL,
406  0,
407  0,
408  LOWORD(lParam),
409  HIWORD(lParam) - (rcStatusBar.bottom - rcStatusBar.top),
411 
412  if (hdwp == NULL)
413  break;
414 
415  hdwp = DeferWindowPos(hdwp,
417  NULL,
418  0,
419  0,
420  LOWORD(lParam),
421  LOWORD(wParam),
422  SWP_NOZORDER);
423 
424  if (hdwp != NULL)
425  EndDeferWindowPos(hdwp);
426  }
427  else
429  NULL,
430  0,
431  0,
432  LOWORD(lParam),
433  HIWORD(lParam),
435 
436  break;
437  }
438 
439  /* The entire client area is covered by edit control and by
440  * the status bar. So there is no need to erase main background.
441  * This resolves the horrible flicker effect during windows resizes. */
442  case WM_ERASEBKGND:
443  return 1;
444 
445  case WM_SETFOCUS:
447  break;
448 
449  case WM_DROPFILES:
450  {
451  TCHAR szFileName[MAX_PATH];
452  HDROP hDrop = (HDROP) wParam;
453 
454  DragQueryFile(hDrop, 0, szFileName, ARRAY_SIZE(szFileName));
455  DragFinish(hDrop);
456  DoOpenFile(szFileName);
457  break;
458  }
459  case WM_CHAR:
460  case WM_INITMENUPOPUP:
462  break;
463  default:
464  if (msg == aFINDMSGSTRING)
465  {
466  FINDREPLACE *pFindReplace = (FINDREPLACE *) lParam;
468 
469  if (pFindReplace->Flags & FR_FINDNEXT)
470  NOTEPAD_FindNext(pFindReplace, FALSE, TRUE);
471  else if (pFindReplace->Flags & FR_REPLACE)
472  NOTEPAD_FindNext(pFindReplace, TRUE, TRUE);
473  else if (pFindReplace->Flags & FR_REPLACEALL)
474  NOTEPAD_ReplaceAll(pFindReplace);
475  else if (pFindReplace->Flags & FR_DIALOGTERM)
477  break;
478  }
479 
480  return DefWindowProc(hWnd, msg, wParam, lParam);
481  }
482  return 0;
483 }
#define FR_FINDNEXT
Definition: commdlg.h:131
#define CMD_HELP_CONTENTS
Definition: notepad_res.h:63
HDWP WINAPI BeginDeferWindowPos(_In_ int)
#define TRUE
Definition: types.h:120
NOTEPAD_GLOBALS Globals
Definition: main.c:29
#define MF_BYCOMMAND
Definition: winuser.h:202
#define WM_CHAR
Definition: winuser.h:1693
#define WM_INITMENUPOPUP
Definition: winuser.h:1722
#define WM_QUERYENDSESSION
Definition: winuser.h:1604
LONG top
Definition: windef.h:297
HGLOBAL hDevNames
Definition: main.h:67
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HWND WINAPI SetFocus(_In_opt_ HWND)
WNDPROC EditProc
Definition: main.h:85
HGLOBAL hDevMode
Definition: main.h:66
#define SWP_NOZORDER
Definition: winuser.h:1232
BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bShowAlert)
Definition: main.c:138
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:65
static VOID DoOpenFile(PINFO pInfo)
Definition: connectdialog.c:34
DWORD Flags
Definition: commdlg.h:306
static VOID NOTEPAD_ReplaceAll(FINDREPLACE *pFindReplace)
Definition: main.c:228
BOOL WINAPI EndDeferWindowPos(_In_ HDWP)
BOOL DoCloseFile(VOID)
Definition: dialog.c:313
#define WM_DROPFILES
Definition: winuser.h:1801
BOOL bShowStatusBar
Definition: main.h:70
UINT msg
Definition: msvc.h:92
smooth NULL
Definition: ftsmooth.c:416
static int NOTEPAD_MenuCommand(WPARAM wParam)
Definition: main.c:59
HFONT hFont
Definition: main.h:64
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
char TCHAR
Definition: xmlstorage.h:189
HWND hStatusBar
Definition: main.h:63
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:1593
#define WM_CLOSE
Definition: winuser.h:1603
#define MAX_PATH
Definition: compat.h:26
VOID DIALOG_StatusBarUpdateCaretPos(VOID)
Definition: dialog.c:1165
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define FR_REPLACE
Definition: commdlg.h:142
#define WM_COMMAND
Definition: winuser.h:1716
#define EN_HSCROLL
Definition: winuser.h:1985
#define GWLP_WNDPROC
Definition: treelist.c:66
#define EN_VSCROLL
Definition: winuser.h:1990
BOOL bWrapLongLines
Definition: main.h:69
#define ARRAY_SIZE(a)
Definition: main.h:24
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define DragQueryFile
Definition: shellapi.h:672
VOID NOTEPAD_EnableSearchMenu()
Definition: main.c:32
void WINAPI DragFinish(HDROP h)
Definition: shellole.c:543
#define WM_DESTROYCLIPBOARD
Definition: winuser.h:1829
#define WM_CREATE
Definition: winuser.h:1590
#define HIWORD(l)
Definition: typedefs.h:246
void NOTEPAD_SaveSettingsToRegistry(void)
Definition: settings.c:227
LONG bottom
Definition: windef.h:299
#define SWP_NOMOVE
Definition: winuser.h:1229
static ATOM aFINDMSGSTRING
Definition: main.c:30
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:1607
#define WM_SETFOCUS
Definition: winuser.h:1595
#define MF_GRAYED
Definition: winuser.h:129
HWND hEdit
Definition: main.h:62
static VOID NOTEPAD_InitMenuPopup(HMENU menu, LPARAM index)
Definition: main.c:276
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:245
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
FINDREPLACE find
Definition: main.h:84
#define EN_CHANGE
Definition: winuser.h:1983

◆ SetFileName()

VOID SetFileName ( LPCTSTR  szFileName)

Definition at line 46 of file main.c.

47 {
49  Globals.szFileTitle[0] = 0;
51 }
NOTEPAD_GLOBALS Globals
Definition: main.c:29
TCHAR szFileName[MAX_PATH]
Definition: main.h:73
#define GetFileTitle
Definition: commdlg.h:664
#define StringCchCopy
Definition: strsafe.h:139
#define ARRAY_SIZE(a)
Definition: main.h:24
TCHAR szFileTitle[MAX_PATH]
Definition: main.h:74

Variable Documentation

◆ aFINDMSGSTRING

ATOM aFINDMSGSTRING
static

Definition at line 30 of file main.c.

Referenced by _tWinMain(), and NOTEPAD_WndProc().

◆ Globals

NOTEPAD_GLOBALS Globals

Definition at line 29 of file main.c.