Created
June 26, 2026 19:00
-
-
Save zamabuvaraeu/41c7281e0b6296eff1732c432c4f0c72 to your computer and use it in GitHub Desktop.
Русский текст в RichTextBox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define UNICODE | |
| #include Once "windows.bi" | |
| #include Once "win/richedit.bi" | |
| Type TMemStream | |
| As ZString Ptr pszData | |
| As Integer iSize | |
| As Integer iPos | |
| End Type | |
| Function editStreamCallback (piCookie As Any Ptr, pbBuff As Byte Ptr, iCb As Long, iPcb As Long Ptr) As Long | |
| Dim As TMemStream Ptr tms = Cast(TMemStream Ptr , piCookie) | |
| If tms = 0 Then Return 1 | |
| If tms->iPos >= tms->iSize Then | |
| *iPcb = 0 | |
| Return 0 | |
| Endif | |
| Dim As Integer toReadChars = iCb | |
| If tms->iPos + toReadChars > tms->iSize Then | |
| toReadChars = tms->iSize - tms->iPos | |
| Endif | |
| Dim As Integer toReadBytes = toReadChars | |
| Memcpy(pbBuff, tms->pszData + tms->iPos, toReadBytes) | |
| tms->iPos += toReadChars | |
| *iPcb = toReadBytes | |
| Return 0 | |
| End Function | |
| Sub loadRtfFromMemory(hRichEdit As HWND, pszRtfData As ZString Ptr, iRtfSize As Integer) | |
| Dim As TMemStream ms | |
| Dim As EDITSTREAM es | |
| ms.pszData = pszRtfData | |
| ms.iSize = iRtfSize | |
| es.dwCookie = Cast(DWORD_PTR , @ms) | |
| es.pfnCallback = Cast(Any Ptr , @editStreamCallback) | |
| SendMessage(hRichEdit, EM_STREAMIN, SF_RTF, Cast(lparam , @es)) | |
| If es.dwError <> 0 Then | |
| ? "EM_STREAMIN error code: "; es.dwError | |
| Else | |
| ? "Stream OK" | |
| End If | |
| End Sub | |
| LoadLibrary "RICHED20.DLL" | |
| Dim msg As MSG | |
| Dim As WNDCLASSEX wc | |
| Dim As Wstring*50 NameClass="MyClass" | |
| Dim As HINSTANCE Hinst=GetModuleHandle(0) | |
| Dim Shared As HWND hRichEdit | |
| Function wndproc(hwnd As HWND, msg As Uinteger,_ | |
| wparam As WPARAM, lparam As LPARAM) As Integer | |
| Select Case msg | |
| Case WM_DESTROY | |
| PostQuitMessage(0) | |
| Case WM_CREATE | |
| hRichEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "RICHEDIT20W", "RichEdit Control",_ | |
| WS_VISIBLE Or WS_CHILD Or WS_HSCROLL Or WS_VSCROLL Or ES_MULTILINE Or ES_AUTOHSCROLL Or ES_AUTOVSCROLL,_ | |
| 10,10,200,200, hwnd, Cast(HMENU,1), 0, 0) | |
| End Select | |
| Return DefWindowProc(hwnd,msg,wparam,lparam) | |
| End Function | |
| With wc | |
| .cbSize=Sizeof(WNDCLASSEX) | |
| .style=CS_HREDRAW Or CS_VREDRAW | |
| .lpfnWndProc=Cast(Any Ptr ,@wndproc) | |
| .hInstance=Hinst | |
| .hIcon=LoadIcon(0,IDI_WINLOGO) | |
| .hCursor=LoadCursor(0,IDC_ARROW) | |
| .hbrBackground=Cast(HBRUSH,COLOR_WINDOWFRAME) | |
| .lpszClassName=@NameClass | |
| .hIconSm=.hIcon | |
| End With | |
| If RegisterClassEx(@wc)=0 Then | |
| Print "Register error, press any key" | |
| Sleep | |
| End | |
| Endif | |
| CreateWindowEx(0,NameClass,"RichEdit",_ | |
| WS_VISIBLE Or WS_OVERLAPPEDWINDOW,100,100,240,260,0,0,Hinst,0) | |
| Dim As ZString*512 sRtf = "{\rtf1\ansi\ansicpg1251\deff0\deflang1049{\fonttbl{\f0\fswiss\fcharset204{\*\fname Arial;}Arial CYR;}}{\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\b\f0\fs20\'e6\'e8\'f0\'ed\'fb\'e9 \'f2\'e5\'ea\'f1\'f2\b0\par}" | |
| loadRtfFromMemory(hRichEdit, @sRtf, Len(sRtf)) | |
| While GetMessage(@msg,0,0,0) | |
| TranslateMessage(@msg) | |
| DispatchMessage(@msg) | |
| Wend |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment