flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > Problem with GdipDrawString 32 bit

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 376
I write 32 bit example.
I want draw GDI Plus Font.
I create GDIplus font:
Code:
UnicodeFontName du 'times new roman',0
pFontFamily dd 0   ;GDI+ return not NULL addres
pFont          dd  0  ;GDI+ return not NULL addres

invoke GdipCreateFontFamilyFromName,UnicodeFontName, 0, pFontFamily
invoke GdipCreateFont,[pFontFamily],24,0,UnitPixel(EQU 2),pFont 
    


layoutRect dd 10.0, 10.0, 220.0, 220.0

But my window empty and i not see text on window.
I try strrr du 'Hello',0 and try strrr db 'Hello',0
But its not help to see text.
Code:
. if [msg] = WM_PAINT

invoke GdipCreateFromHWND,[msg.hwnd],Graphics
invoke GdipGraphicsClear,[Graphics],0xff00FF00 ;clear work fine and show me GDI+ work
invoke GdipSetTextRenderingHint,[Graphics], 2
invoke GdipCreateSolidFill,0xff00ffff,pBlackBrush
invoke GdipCreateStringFormat,0 , LANG_NEUTRAL,  GdiPlusStringFormat 
invoke GdipSetStringFormatAlign,[GdiPlusStringFormat],0
   invoke GdipSetStringFormatLineAlign,[GdiPlusStringFormat],0 
invoke GdipDrawString,[Graphics], strrr, -1, [pFont], layoutRect , [GdiPlusStringFormat], [pBlackBrush] 
invoke ValidateRect,[msg.hwnd],ebx
            retn   16 
.endif

    


Code:
import gdiplus,\
         GdiplusStartup,'GdiplusStartup',\
         GdipCreateFontFamilyFromName,'GdipCreateFontFamilyFromName',\
         GdipCreateBitmapFromScan0,'GdipCreateBitmapFromScan0',\
         GdipGetImageGraphicsContext,'GdipGetImageGraphicsContext',\
         GdipCreateFromHDC,'GdipCreateFromHDC',\
         GdipCreateStringFormat,'GdipCreateStringFormat',\
         GdipSetTextRenderingHint,'GdipSetTextRenderingHint',\
         GdipSetStringFormatAlign,'GdipSetStringFormatAlign',\
         GdipSetStringFormatLineAlign,'GdipSetStringFormatLineAlign',\
         GdipCreatePen2,'GdipCreatePen2',\
         GdipCreateSolidFill,'GdipCreateSolidFill',\
         GdipDrawString,'GdipDrawString',\
         GdipDeleteFontFamily,'GdipDeleteFontFamily',\
         GdipCreateFont,'GdipCreateFont',\
         GdipCreateFromHWND,'GdipCreateFromHWND',\
         GdipCreateBitmapFromStream,'GdipCreateBitmapFromStream',\
         GdipGetImageWidth,'GdipGetImageWidth',\
         GdipGetImageHeight,'GdipGetImageHeight',\
         GdipDrawImageRectRectI,'GdipDrawImageRectRectI'
    
Post 31 Jul 2018, 10:15
View user's profile Send private message Reply with quote
Mikl___



Joined: 30 Dec 2014
Posts: 85
Hi, Roman!
Code:
format PE64 GUI 6.0
entry WinMain
include 'win64a.inc'
IMAGE_BASE      equ 0x400000
struct RectF
       x rd 1     ;REAL = REAL4
       y rd 1
       awidth rd 1
       height rd 1
ends
struct GdiplusStartupInput
       GdiplusVersion           rd 1
       DebugEventCallback       rd 1
       SuppressBackgroundThread rd 1
       SuppressExternalCodecs   rd 1
ends
section '.code' code readable executable writeable
proc WinMain
local msg:MSG
        frame
        xor r8,r8;NULL
        mov edx,gdiplusStartupInput
        mov ecx,GdiplusToken
        invoke GdiplusStartup
        xor ebx,ebx
        mov ecx,FileName
        invoke LoadCursorFromFile
        mov esi,IMAGE_BASE
        mov edi,ClassName
        push rax    ;hIconSm
        push rdi    ;lpszClassName
        push rbx    ;lpszMenuName
        push COLOR_WINDOWTEXT;hbrBackground=black
        push 10003h ;hCursor
        push rax    ;hIcon  
        push rsi    ;hInstance
        push rbx    ;cbClsExtra & cbWndExtra
        push WndSDI
        push sizeof.WNDCLASSEX;cbSize & style
        invoke RegisterClassEx,esp;addr WNDCLASSEX
        push rbx
        push rsi    ;rsi=400000h
        shl esi,9   ;rsi=CW_USEDEFAULT
        push rbx
        push rbx
        push 90
        push 270
        push rsi    ;rsi=CW_USEDEFAULT
        push rsi    ;rsi=CW_USEDEFAULT
        sub rsp,20h
        xor ecx,ecx
        mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
        invoke CreateWindowEx,,edi,edi
        lea edi,[msg]
@@:     xor r9,r9
        xor r8,r8
        xor edx,edx
        invoke GetMessage,edi
        invoke DispatchMessage,edi
        jmp @b
        endf
endp
;----------------------------------------
proc WndSDI hwnd,uMsg,wParam,lParam
local Ps:PAINTSTRUCT
local hdc:QWORD
local graphics:QWORD

        mov [hwnd],rcx
        frame
        cmp edx,WM_DESTROY
        je wmDESTROY
        cmp edx,WM_CREATE
        je wmCREATE
        cmp edx,WM_PAINT
        je wmPAINT
        leave
        jmp [NtdllDefWindowProc]
wmDESTROY:invoke DeleteObject,[hCompatibleDC]
        invoke DestroyWindow, [hwnd]
        invoke GdiplusShutdown,[GdiplusToken]
        invoke DeleteObject,[hFont]
        xor ecx,ecx
        invoke RtlExitUserProcess

wmCREATE:mov ecx,logfont
        invoke CreateFontIndirect
        mov [hFont],rax
        mov edx,WM_SETFONT
        xor r9,r9;FALSE
        invoke SendMessage,[hwnd],,rax
;---------- prepare all can be possible for drawing here (WM_PAINT is faster as this)
        xor ecx,ecx;NULL
        xor edx,edx;LANG_NEUTRAL
        mov r8d,nativeFormat
        invoke GdipCreateStringFormat
        mov ecx,0FF00C832h
        mov edx,nativebrush
        invoke GdipCreateSolidFill
        jmp wmBYE

wmPAINT:lea edx,[Ps]
        invoke BeginPaint        
        mov [hdc],rax
        lea edx,[graphics]
        invoke GdipCreateFromHDC,[hdc]
        lea edx,[graphics]
        invoke GdipCreateFromHWND,[hwnd]
        mov edx,logfont
        mov r8d,gpFont
        invoke GdipCreateFontFromLogfont,[hdc]
        mov edx,wPhrase
        or r8,-1
        invoke GdipDrawString,[graphics],,,[gpFont],RectText,[nativeFormat],[nativebrush]
        invoke GdipDeleteFont,[gpFont]
        lea edx,[Ps]
        invoke EndPaint,[hwnd]
wmBYE:  endf
        leave
        retn
endp
;-----------------------------------------
;section '.data' data readable writeable
ClassName db "GDI+ рисование текста",0
FileName  db "br_Rabbit3.cur",0
gdiplusStartupInput GdiplusStartupInput 1,NULL,FALSE,FALSE
nativeFormat rq 1
hCompatibleDC rq 1
wPhrase du "hello, World!",0
nativebrush rq 1
gpFont rq 1
hFont rq 1
logfont LOGFONT 36,12,0,0,400,0,0,0,0,0,0,0,DEFAULT_PITCH or FF_SCRIPT,"Times New Roman"
RectText RectF  0.0,0.0,270.0,90.0
GdiplusToken rq 1
;-----------------------------------------------
section '.idata' import data readable writeable
  library ntdll,'ntdll.dll',\
          user,'USER32.DLL',\
          gdiplus,'gdiplus.dll',\
          gdi,'GDI32.DLL'

  import gdiplus,\
         GdipCreateFontFromLogfont,'GdipCreateFontFromLogfontA',\
         GdipCreateStringFormat,'GdipCreateStringFormat',\
         GdipCreateSolidFill,'GdipCreateSolidFill',\
         GdipCreateFromHWND,'GdipCreateFromHWND',\
         GdipCreateFromHDC,'GdipCreateFromHDC',\
         GdiplusShutdown,'GdiplusShutdown',\
         GdipDeleteFont,'GdipDeleteFont',\
         GdipDrawString,'GdipDrawString',\
         GdiplusStartup,'GdiplusStartup'

  import user,\
         LoadCursorFromFile,'LoadCursorFromFileA',\
         RegisterClassEx,'RegisterClassExA',\
         DispatchMessage,'DispatchMessageA',\
         CreateWindowEx,'CreateWindowExA',\
         DestroyWindow,'DestroyWindow',\
         SendMessage,'SendMessageA',\
         GetMessage,'GetMessageA',\
         BeginPaint,'BeginPaint',\
         EndPaint,'EndPaint'

  import gdi,\
         CreateFontIndirect,'CreateFontIndirectA',\
         DeleteObject,'DeleteObject'

  import ntdll,\
         NtdllDefWindowProc,'NtdllDefWindowProc_A',\
         RtlExitUserProcess,'RtlExitUserProcess'    


Description:
Filesize: 4.32 KB
Viewed: 172 Time(s)

1.png


Description:
Download
Filename: 05.zip
Filesize: 4.39 KB
Downloaded: 8 Time(s)

Post 31 Jul 2018, 13:10
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 376
I found in my example bug.
invoke GdipCreateFont,[pFontFamily],24,0,UnitPixel(EQU 2),pFont

Fix to(font size must be float !):
invoke GdipCreateFont,[pFontFamily],24.0,0,UnitPixel(EQU 2),pFont


And now i see my text in my window !

I'm sorry to trouble you.
Post 31 Jul 2018, 13:19
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 376
How draw russian text GdipDrawString ?
Instead of letters i see abracadabra where there should be Russian letters.
I try, but not help:

Code:
invoke GdipCreateStringFormat,0 , LANG_NEUTRAL+SUBLANG_DEFAULT,  GdiPlusStringFormat     
Post 31 Jul 2018, 13:55
View user's profile Send private message Reply with quote
Mikl___



Joined: 30 Dec 2014
Posts: 85
Roman
макрос du неправильно обрабатывает буквы кириллицы, должно быть вот так (синтаксис masm)
Code:
du      macro string
local bslash
bslash = 0
        irpc c,<string>
        if bslash eq 0
                if '&c' eq "/"
                bslash = 1
                elseif '&c'gt 127
                db ('&c'- 0B0h),4
                else
                dw '&c'
                endif
        else
           bslash = 0
           if '&c' eq "n"
           DW 0Dh,0Ah
           elseif '&c' eq "/"
           dw '/'
           elseif '&c' eq "r"
           dw 0Dh
           elseif '&c' eq "l"
           dw 0Ah
           elseif '&c' eq "s"
           dw 20h
           elseif '&c' eq "c"
           dw 3Bh
           elseif '&c' eq "t"
           dw 9
           endif
        endif
        endm
        dw 0
        endm    


Description:
Filesize: 13.92 KB
Viewed: 147 Time(s)

01.png


Post 31 Jul 2018, 14:33
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 376
Aha ! Thanks Mikl___

I fixed this !
Just write in fasm:
Code:
include "c:\fasm\include\encoding\win1251.inc"
    
Post 31 Jul 2018, 14:51
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 376
Mikl___ а нет ли у Вас masm примера GDI plus outline text ?
Что бы текст был с обводкой.
Как вот этот текст https://i.stack.imgur.com/WCAit.png
Post 31 Jul 2018, 14:53
View user's profile Send private message Reply with quote
Mikl___



Joined: 30 Dec 2014
Posts: 85
Roman,
нет, теста с обводкой нет...
Post 31 Jul 2018, 15:18
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.