ReactOS  0.4.12-dev-43-g63b00d8
crichedit.h
Go to the documentation of this file.
1 #pragma once
2 #include <rosctrls.h>
3 
4 class CRichEdit :
5  public CWindow
6 {
8 
9  VOID GenericInsertText(LPCWSTR lpszText, SIZE_T InsertedTextLen, DWORD dwEffects)
10  {
12  SIZE_T Len = GetTextLen();
13 
14  if (InsertedTextLen)
15  {
16  /* Insert new text */
17  SetText.flags = ST_SELECTION;
18  SetText.codepage = 1200;
19 
20  SendMessageW(EM_SETTEXTEX, (WPARAM) &SetText, (LPARAM) lpszText);
21 
22  if ((dwEffects == CFM_LINK) && !PathIsURLW(lpszText))
23  {
24  // if text is not an URL, no styling is used
25  SetRangeFormatting(Len, Len + InsertedTextLen, 0);
26  }
27  else
28  {
29  SetRangeFormatting(Len, Len + InsertedTextLen, dwEffects);
30  }
31  }
32  }
33 
34 public:
35  CRichEdit() : CWindow(), m_LoadedLibrary(NULL) {}
36 
38  {
39  CHARFORMAT2W CharFormat;
40 
41  SendMessageW(EM_SETSEL, Start, End);
42 
43  ZeroMemory(&CharFormat, sizeof(CharFormat));
44 
45  CharFormat.cbSize = sizeof(CharFormat);
46  CharFormat.dwMask = dwEffects;
47  CharFormat.dwEffects = dwEffects;
48 
50 
51  SendMessageW(EM_SETSEL, End, End + 1);
52  }
53 
55  {
56  GETTEXTLENGTHEX TxtLenStruct;
57 
58  TxtLenStruct.flags = GTL_NUMCHARS;
59  TxtLenStruct.codepage = 1200;
60 
61  return (LONG) SendMessageW(EM_GETTEXTLENGTHEX, (WPARAM) &TxtLenStruct, 0);
62  }
63 
64  /*
65  * Insert text (without cleaning old text)
66  * Supported effects:
67  * - CFM_BOLD
68  * - CFM_ITALIC
69  * - CFM_UNDERLINE
70  * - CFM_LINK
71  */
72  VOID InsertText(LPCWSTR lpszText, DWORD dwEffects)
73  {
74  GenericInsertText(lpszText, wcslen(lpszText), dwEffects);
75  }
76 
78  {
79  GenericInsertText(szText.GetString(), szText.GetLength(), dwEffects);
80  }
81  /*
82  * Clear old text and add new
83  */
84  VOID SetText(LPCWSTR lpszText, DWORD dwEffects)
85  {
86  SetWindowTextW(L"");
87  InsertText(lpszText, dwEffects);
88  }
89 
90  VOID SetText(const ATL::CStringW& szText, DWORD dwEffects)
91  {
92  SetText(szText.GetString(), dwEffects);
93  }
94 
96  {
97  m_LoadedLibrary = LoadLibraryW(L"riched20.dll");
98 
99  m_hWnd = CreateWindowExW(0,
100  L"RichEdit20W",
101  NULL,
104  205, 28, 465, 100,
105  hwndParent,
106  NULL,
108  NULL);
109 
110  if (m_hWnd)
111  {
116  }
117 
118  return m_hWnd;
119  }
120 
121  virtual VOID OnLink(ENLINK *Link)
122  {
123  }
124 
126  {
127  if (m_LoadedLibrary)
128  {
129  FreeLibrary(m_LoadedLibrary);
130  }
131  }
132 
133 };
HGDIOBJ WINAPI GetStockObject(_In_ int)
int GetLength() const
Definition: atlsimpstr.h:356
HINSTANCE GetModuleInstance()
Definition: atlcore.h:198
VOID InsertText(const ATL::CStringW &szText, DWORD dwEffects)
Definition: crichedit.h:77
#define TRUE
Definition: types.h:120
VOID SetText(const ATL::CStringW &szText, DWORD dwEffects)
Definition: crichedit.h:90
~CRichEdit()
Definition: crichedit.h:125
#define SB_VERT
Definition: winuser.h:553
#define ENM_MOUSEEVENTS
Definition: richedit.h:476
#define ES_MULTILINE
Definition: pedump.c:667
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define ZeroMemory
Definition: winbase.h:1635
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
#define ES_READONLY
Definition: pedump.c:675
#define WS_CHILD
Definition: pedump.c:617
static int Link(const char **args)
Definition: vfdcmd.c:2414
DWORD WINAPI GetSysColor(_In_ int)
BOOL WINAPI PathIsURLW(LPCWSTR lpstrPath)
Definition: url.c:2432
UINT_PTR WPARAM
Definition: windef.h:207
VOID SetRangeFormatting(SIZE_T Start, SIZE_T End, DWORD dwEffects)
Definition: crichedit.h:37
#define ENM_LINK
Definition: richedit.h:485
DWORD flags
Definition: richedit.h:1065
static const WCHAR szText[]
Definition: dialog.c:139
long LONG
Definition: pedump.c:60
LONG_PTR LPARAM
Definition: windef.h:208
#define EM_SETCHARFORMAT
Definition: richedit.h:101
#define LoadLibraryW(x)
Definition: compat.h:404
smooth NULL
Definition: ftsmooth.c:416
DWORD dwEffects
Definition: richedit.h:307
static HWND hwndParent
Definition: cryptui.c:300
#define EM_SETBKGNDCOLOR
Definition: richedit.h:100
#define EM_SETEVENTMASK
Definition: richedit.h:102
CRichEdit()
Definition: crichedit.h:35
#define FreeLibrary(x)
Definition: compat.h:405
PCXSTR GetString() const
Definition: atlsimpstr.h:361
#define EM_SETSEL
Definition: winuser.h:1979
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
Definition: partlist.h:32
#define DEFAULT_GUI_FONT
Definition: wingdi.h:907
static const WCHAR L[]
Definition: oid.c:1087
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define COLOR_BTNFACE
Definition: winuser.h:918
#define EM_SETTEXTEX
Definition: richedit.h:131
VOID InsertText(LPCWSTR lpszText, DWORD dwEffects)
Definition: crichedit.h:72
HWND Create(HWND hwndParent)
Definition: crichedit.h:95
#define CFM_LINK
Definition: richedit.h:337
#define ST_SELECTION
Definition: richedit.h:1072
ULONG_PTR SIZE_T
Definition: typedefs.h:78
LONG GetTextLen()
Definition: crichedit.h:54
#define SCF_WORD
Definition: richedit.h:236
#define GTL_NUMCHARS
Definition: richedit.h:1058
virtual VOID OnLink(ENLINK *Link)
Definition: crichedit.h:121
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define EM_SHOWSCROLLBAR
Definition: richedit.h:130
UINT codepage
Definition: richedit.h:1066
DWORD dwMask
Definition: richedit.h:306
#define WM_SETFONT
Definition: winuser.h:1632
HMODULE m_LoadedLibrary
Definition: crichedit.h:7
#define SCF_SELECTION
Definition: richedit.h:235
CAtlBaseModule _AtlBaseModule
Definition: atlbase.cpp:26
#define EM_GETTEXTLENGTHEX
Definition: richedit.h:129
VOID GenericInsertText(LPCWSTR lpszText, SIZE_T InsertedTextLen, DWORD dwEffects)
Definition: crichedit.h:9
#define ES_LEFT
Definition: pedump.c:664
#define WS_VISIBLE
Definition: pedump.c:620
VOID SetText(LPCWSTR lpszText, DWORD dwEffects)
Definition: crichedit.h:84
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)