Author Topic: Iczelion Tutorial 35: RichEdit Control: Syntax Hilighting  (Read 933 times)

nidud

  • Member
  • *****
  • Posts: 1408
    • https://github.com/nidud/asmc
Re: Iczelion Tutorial 35: RichEdit Control: Syntax Hilighting
« Reply #15 on: August 13, 2017, 01:41:42 AM »
Here's a test case using the font face from the Rich Edit handle. It's a modified version of the windows/3/test.asm file using Rich Edit version 4.1.

Code: [Select]
;
; https://msdn.microsoft.com/en-us/library/windows/desktop/dd183499(v=vs.85).aspx
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh298375(v=vs.85).aspx
;
include windows.inc

ifdef _UNICODE
MSFTEDIT_CLASS equ <L"RICHEDIT50W">
else
MSFTEDIT_CLASS equ <"RICHEDIT50W">
endif

.data
hEdit HWND ?

.code

CreateRichEdit proc hwndOwner:HWND, ; Dialog box handle.
                    x:SINT, y:SINT, ; Location.
                    w:SINT, h:SINT, ; Dimensions.
                    hinst:HINSTANCE ; Application or DLL instance.

    LoadLibrary("Msftedit.dll")
    CreateWindowEx(0, MSFTEDIT_CLASS,
        "Type here\n"
        "ñîçäàäèì äî÷åðíåå îêíî ñëàéäåðà 2",
        ES_MULTILINE or WS_VISIBLE or WS_CHILD or WS_BORDER or WS_TABSTOP,
        x, y, w, h,
        hwndOwner, NULL, hinst, NULL)
    ret

CreateRichEdit endp

WndProc proc hWnd:HWND, message:UINT, wParam:WPARAM, lParam:LPARAM

    local wmId, wmEvent
    local ps:PAINTSTRUCT
    local hdc:HDC
    local rect:RECT
    local hBrush:HBRUSH
    local hFont:HFONT

    .switch message

      .case WM_PAINT

        mov hdc,BeginPaint(hWnd, &ps)

        ; Get the font face from Rich Edit handle.

        mov hFont,SendMessage(hEdit, WM_GETFONT, 0, 0)
        SelectObject(hdc, hFont)

        ; Sets the coordinates for the rectangle in which the text is to be formatted.
        SetRect(&rect, 10,70,500,50)
        SetTextColor(hdc, RGB(255,0,0))
        DrawText(hdc, "ñîçäàäèì äî÷åðíåå îêíî ñëàéäåðà 2", -1, &rect, DT_NOCLIP)


        ; Logical units are device dependent pixels, so this will create a
        ; handle to a logical font that is 36 pixels in height.
        ; The width, when set to 20, will cause the font mapper to choose a font
        ; which, in this case, is stretched.
        ; The font face name will be Times New Roman.  This time nEscapement is
        ; at -300 tenths of a degree (-30 degrees)
        mov hFont, CreateFont(36,20,-300,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
                CLIP_DEFAULT_PRECIS,CLEARTYPE_QUALITY, VARIABLE_PITCH, "Times New Roman")
        SelectObject(hdc, hFont)

        ; Sets the coordinates for the rectangle in which the text is to be formatted.
        SetRect(&rect, 100, 200, 900, 800);
        SetTextColor(hdc, RGB(0,128,0));
        DrawText(hdc, "ñîçäàäèì äî÷åðíåå îêíî ñëàéäåðà 2", -1, &rect, DT_NOCLIP)

        ; Logical units are device dependent pixels, so this will create a handle
        ; to a logical font that is 36 pixels in height.
        ; The width, when set to 10, will cause the font mapper to choose a font
        ; which, in this case, is compressed.
        ; The font face name will be Arial. This time nEscapement is at 250
        ; tenths of a degree (25 degrees)

        mov hFont,CreateFont(36,10,250,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,
            OUT_OUTLINE_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,VARIABLE_PITCH,
            "Arial")
        SelectObject(hdc,hFont)

        ; Sets the coordinates for the rectangle in which the text is to be formatted.
        SetRect(&rect, 500, 200, 1400, 600)
        SetTextColor(hdc, RGB(0,0,255))
        DrawText(hdc, "ñîçäàäèì äî÷åðíåå îêíî ñëàéäåðà 2", -1, &rect, DT_NOCLIP)
        DeleteObject(hFont)

        EndPaint(hWnd, &ps)
        xor eax,eax
        .endc

      .case WM_DESTROY
        PostQuitMessage(0)
        xor eax,eax
        .endc
      .default
        DefWindowProc(hWnd, message, wParam, lParam)
    .endsw
    ret
WndProc endp

WinMain proc WINAPI hInstance: HINSTANCE,
     hPrevInstance: HINSTANCE,
         lpCmdLine: LPSTR,
          nShowCmd: SINT

    local wc:WNDCLASSEX
    local msg:MSG
    local hwnd:HANDLE

    mov wc.cbSize,SIZEOF WNDCLASSEX
    mov wc.style,CS_HREDRAW or CS_VREDRAW
    mov wc.lpfnWndProc,WndProc

    mov ecx,hInstance
    xor eax,eax
    mov wc.cbClsExtra,eax
    mov wc.cbWndExtra,eax
    mov wc.hInstance,ecx
    mov wc.hbrBackground,COLOR_WINDOW+1
    mov wc.lpszMenuName,eax

    lea eax,@CStr("WndClass")
    mov wc.lpszClassName,eax
    mov wc.hIcon,LoadIcon(0, IDI_APPLICATION)
    mov wc.hIconSm,eax
    mov wc.hCursor,LoadCursor(0, IDC_ARROW)

    RegisterClassEx(&wc)

    mov eax,CW_USEDEFAULT
    mov hwnd,CreateWindowEx(0, "WndClass", "Window", WS_OVERLAPPEDWINDOW,
        eax, eax, eax, eax, 0, 0, hInstance, 0)

    mov hEdit,CreateRichEdit(eax, 10, 10, 500, 50, hInstance)

    ShowWindow(hwnd, SW_SHOWNORMAL)
    UpdateWindow(hwnd)

    .while GetMessage(&msg, 0, 0, 0)
        TranslateMessage(&msg)
        DispatchMessage(&msg)
    .endw
    mov eax,msg.wParam
    ret

WinMain endp

ifdef __PE__
WinStart proc
    mov ebx,GetModuleHandle(0)
    ExitProcess(WinMain(ebx, 0, GetCommandLineA(), SW_SHOWDEFAULT))
WinStart endp
else
WinStart equ <>
endif
    end WinStart

So if you could run the exe-file Mikl__ and post the image of the window output we will at least know if it's a font problem.

HSE

  • Member
  • ****
  • Posts: 551
  • <AMD>< 7-32>
Re: Iczelion Tutorial 35: RichEdit Control: Syntax Hilighting
« Reply #16 on: August 13, 2017, 02:01:10 AM »
I noticed from using the editor that some highlighted text has a different size than the background but judging from the image attached there seems to be a font problem.
There is no problem in the original 32bit.
 
Don't confuse Notepad with Notepad++...
:biggrin: :biggrin: I totally forget "Bloc de notas", corrected now.

nidud

  • Member
  • *****
  • Posts: 1408
    • https://github.com/nidud/asmc
Re: Iczelion Tutorial 35: RichEdit Control: Syntax Hilighting
« Reply #17 on: August 13, 2017, 02:27:16 AM »
I noticed from using the editor that some highlighted text has a different size than the background..
There is no problem in the original 32bit.

Maybe it depends on the local font?

HSE

  • Member
  • ****
  • Posts: 551
  • <AMD>< 7-32>
Re: Iczelion Tutorial 35: RichEdit Control: Syntax Hilighting
« Reply #18 on: August 13, 2017, 02:53:20 AM »
Maybe it depends on the local font?

It's very easy to answer that: I don't know.  :eusa_snooty:

nidud

  • Member
  • *****
  • Posts: 1408
    • https://github.com/nidud/asmc
Re: Iczelion Tutorial 35: RichEdit Control: Syntax Hilighting
« Reply #19 on: August 13, 2017, 04:07:51 AM »
It's very easy to answer that: I don't know.  :eusa_snooty:

 :biggrin:

You could sort-of just write ;Copy & style in the editor before you took the snapshot thought. If you really wanted to know the answer that is.

HSE

  • Member
  • ****
  • Posts: 551
  • <AMD>< 7-32>
Re: Iczelion Tutorial 35: RichEdit Control: Syntax Hilighting
« Reply #20 on: August 13, 2017, 04:33:47 AM »
The ampersand make the crash jump  :t

nidud

  • Member
  • *****
  • Posts: 1408
    • https://github.com/nidud/asmc
Re: Iczelion Tutorial 35: RichEdit Control: Syntax Hilighting
« Reply #21 on: August 17, 2017, 09:34:52 AM »
The ampersand make the crash jump  :t

DrawText(hdc, txtrange.lpstrText, -1, &rect, DT_NOPREFIX)

https://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx

Quote
Example:
input string: "A&bc&&d"
normal: "Abc&d"
DT_NOPREFIX: "A&bc&&d"

HSE

  • Member
  • ****
  • Posts: 551
  • <AMD>< 7-32>
Re: Iczelion Tutorial 35: RichEdit Control: Syntax Hilighting
« Reply #22 on: August 17, 2017, 11:39:48 PM »
Impressive  :t

(Obviously not problem with EM_GETTEXTRANGE  :biggrin: :biggrin:)

Mikl__

  • Member
  • ****
  • Posts: 554
Re: Iczelion Tutorial 35: RichEdit Control: Syntax Hilighting
« Reply #23 on: August 24, 2017, 11:51:12 PM »
Thanks to all for help. I solved the problem, if anybody it's interested then see in Uncle Remus Tales
« Last Edit: August 26, 2017, 03:26:17 PM by Mikl__ »