News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

DrawText/DrawTextEx weird behavior if called in WM_PAINT

Started by 2B||!2B, August 05, 2023, 04:32:30 AM

Previous topic - Next topic

Greenhorn

Quote from: 2B||!2B on August 05, 2023, 09:42:41 AMHere is how I called it
invoke ExtTextOut,hdc,0,0,ETO_OPAQUE,addr ps.rcPaint,chr$("This is a sample text"),22,0
I tried with ETO_CLIPPED. Couldn't reproduce the issue that DrawText has so my guess is that their implementation is different under the hood.

That's because you set for x and y the values 0,0. These values are relative to the HDC.
If you would set x = ps.rcPaint.left and y = ps.rcPaint.top the text would be drawn as in DrawText.

Internally DrawText calls ExtTextOut exactly like this, with x and y inside the defined rectangle.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

2B||!2B

Thanks Greenhorn,
It makes more sense now but also brings little more confusion as to what is the role of x/y in the lprect parameter of this function? Are they not used as they are specified explicitly?

Greenhorn

Quote from: 2B||!2B on August 06, 2023, 03:02:08 AMThanks Greenhorn,
It makes more sense now but also brings little more confusion as to what is the role of x/y in the lprect parameter of this function? Are they not used as they are specified explicitly?

https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-exttextoutw
[in] lprect
A pointer to an optional RECT structure that specifies the dimensions, in logical coordinates, of a rectangle that is used for clipping, opaquing, or both.
-----------------

With ETO_CLIPPED the text would not exceed the rectangle, same as DrawText without DT_NOCLIP.
However, this assumes that x and y is within the rectangle defined by lprect. And on the very first call of your WM_PAINT ps.rcPaint is 0, 0, clientWidth, clientHeight.
But I confirm, this is a little bit confusing since the documentation is here not clear enough on the first glance.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

2B||!2B

Thanks, Greenhorn.
Appreciate your time looking into this issue. :smiley:

jj2007

Quote from: 2B||!2B on August 05, 2023, 11:44:08 AM
Quote from: jj2007 on August 05, 2023, 09:53:46 AMWhile your remarks about the two RECTs are correct, it is very unlikely that DrawText and ExtTextOut behave differently. Post complete code with both of them, otherwise this thread remains pretty useless.


.elseif EAX == WM_PAINT
invoke BeginPaint,hWin,addr ps

MOV hdc,EAX
invoke DrawText,hdc,chr$("This is a sample text"),22,addr ps.rcPaint,DT_LEFT
;invoke ExtTextOut,hdc,0,0,ETO_CLIPPED,addr ps.rcPaint,chr$("This is a sample text"),22,0


invoke EndPaint,hWin,addr ps
return 0

That doesn't look like "complete code" :rolleyes:

I refuse to stare at little snippets. You claim that DrawText behaves differently from ExtTextOut, you post a complete application that allows to verify your claim.