-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRichEditControl.cpp
More file actions
49 lines (43 loc) · 1.51 KB
/
Copy pathRichEditControl.cpp
File metadata and controls
49 lines (43 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "stdafx.h"
#include "Gr7API.h"
// Function to create a rich edit control
HWND Grass7API::RichEditControl::CreateRichEdit(HWND &hwndOwner, int x, int y, int width, int height, HINSTANCE hinst)
{
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_USEREX_CLASSES;
InitCommonControlsEx(&icex);
HWND hwndEdit = CreateWindowExW(WS_EX_CLIENTEDGE, MSFTEDIT_CLASS, L"",
WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_HSCROLL | WS_VSCROLL,
x, y, width, height,
hwndOwner, nullptr, hinst, nullptr);
CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwEffects = 0;
cf.dwMask = CFM_FACE | CFE_BOLD;
SendMessageW(hwndEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
return hwndEdit;
}
DWORD CALLBACK Grass7API::RichEditControl::EditStreamCallback(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, PLONG pcb)
{
HANDLE hFile = (HANDLE)dwCookie;
return !ReadFile(hFile, lpBuff, cb, (DWORD *)pcb, nullptr);
}
// Reads the file and puts the contents into the rich edit control
BOOL Grass7API::RichEditControl::FillRichEditFromFile(HWND &hwnd, LPCTSTR pszFile, WPARAM Type)
{
BOOL fSuccess = FALSE;
HANDLE hFile = CreateFile(pszFile, GENERIC_READ, FILE_SHARE_READ,
0, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, nullptr);
if (hFile != INVALID_HANDLE_VALUE)
{
EDITSTREAM es = { (DWORD_PTR)hFile, 0, Grass7API::RichEditControl::EditStreamCallback };
if (SendMessageW(hwnd, EM_STREAMIN, Type, (LPARAM)&es) && es.dwError == 0)
{
fSuccess = TRUE;
}
CloseHandle(hFile);
}
return fSuccess;
}