Sign in to follow this  
Followers 0
jpam

SetTextAlign

10 posts in this topic

anyone knows why SetTextAlign (gdi32.dll) is not working ?

can only refresh with a repaint

am i missing something ? :whistle:

DllCall("gdi32.dll", "int", "SetTextColor", "hwnd", $hDC, "int", 0xffffff)

DllCall("gdi32.dll", "int", "SetBkMode", "hwnd", $hDC, "int", 1)

DllCall("gdi32.dll", "int", "SetBkColor", "hwnd", $hDC, "int", 0)

DllCall("gdi32.dll", "int", "SetTextAlign", "hwnd", $hDC, "int", "TA_LEFT|TA_TOP|TA_UPDATECP")

$text = "Hello"

$len = StringLen($text)

DllCall("gdi32.dll", "int", "TextOut", "hwnd", $hDC, "int", 300, "int", 10, "str", $text, "int", $len)

thanks in advange

jpam

Share this post


Link to post
Share on other sites



GDI.Dll does not work with autoit as far as I can tell

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

GDI.Dll does not work with autoit as far as I can tell

You obviously speak of something you know nothing about. I've got a ton of GDI32.dll calls in Auto3Lib and they work just fine. Edited by PaulIA

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

anyone knows why SetTextAlign (gdi32.dll) is not working ?

can only refresh with a repaint

am i missing something ? :whistle:

DllCall("gdi32.dll", "int", "SetTextColor", "hwnd", $hDC, "int", 0xffffff)

DllCall("gdi32.dll", "int", "SetBkMode", "hwnd", $hDC, "int", 1)

DllCall("gdi32.dll", "int", "SetBkColor", "hwnd", $hDC, "int", 0)

DllCall("gdi32.dll", "int", "SetTextAlign", "hwnd", $hDC, "int", "TA_LEFT|TA_TOP|TA_UPDATECP")

$text = "Hello"

$len = StringLen($text)

DllCall("gdi32.dll", "int", "TextOut", "hwnd", $hDC, "int", 300, "int", 10, "str", $text, "int", $len)

thanks in advange

jpam

You are passing a string to the API instead of an int. This:

DllCall("gdi32.dll", "int", "SetTextAlign", "hwnd", $hDC, "int", "TA_LEFT|TA_TOP|TA_UPDATECP")oÝ÷ Ù(hºWe¢,¢g­)à)¶¬jëh×6DllCall("gdi32.dll", "int", "SetTextAlign", "hwnd", $hDC, "int", BitOR($TA_LEFT, $TA_TOP, $TA_UPDATECP))

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

You are passing a string to the API instead of an int. This:

DllCall("gdi32.dll", "int", "SetTextAlign", "hwnd", $hDC, "int", "TA_LEFT|TA_TOP|TA_UPDATECP")oÝ÷ Ù(hºWe¢,¢g­)à)¶¬jëh×6DllCall("gdi32.dll", "int", "SetTextAlign", "hwnd", $hDC, "int", BitOR($TA_LEFT, $TA_TOP, $TA_UPDATECP))
no, that's not working either

problem is that the text is not updating but overwrite the old text

Share this post


Link to post
Share on other sites

no, that's not working either

problem is that the text is not updating but overwrite the old text

This probably should go in the support forum. Why don't you post a working snippet of code that shows what you're trying to do and we'll go from there. I think you may have a misunderstanding of how TextOut works, but I can't tell from the few lines of code that you posted.

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This probably should go in the support forum. Why don't you post a working snippet of code that shows what you're trying to do and we'll go from there. I think you may have a misunderstanding of how TextOut works, but I can't tell from the few lines of code that you posted.

simple test code;

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
HotKeySet("{Esc}","_exit")

$TA_LEFT     = "TA_UPDATECP"
$TA_TOP      = "TA_TOP"
$TA_UPDATECP = "TA_UPDATECP"

$GUI = GUICreate("TextOut",200,100,-1,-1)
GUISetBkColor(0xff0000,$GUI)
GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")
GUISetState()

$WIN_GETHANDLE = WinGetHandle("TextOut","")
$RAW_HDC = DllCall("user32.dll","ptr","GetDC","hwnd",$WIN_GETHANDLE)
Global $hDC     = "0x" & Hex($RAW_HDC[0])

DllCall("gdi32.dll", "int", "SetTextColor", "hwnd", $hDC, "int", 0xffffff)
DllCall("gdi32.dll", "int", "SetBkMode", "hwnd", $hDC, "int", "TRANSPARENT")
DllCall("gdi32.dll", "int", "SetBkColor", "hwnd", $hDC, "int", 0)
;DllCall("gdi32.dll", "int", "SetTextAlign", "hwnd", $hDC, "int", "TA_UPDATECP")
DllCall("gdi32.dll", "int", "SetTextAlign", "hwnd", $hDC, "int", BitOR($TA_LEFT, $TA_TOP, $TA_UPDATECP))
While 1
    For $i = 1 to 100
        $text = $i&"XZ368QS&"&$i
        $len = StringLen($text)
        DllCall("gdi32.dll", "int", "TextOutA", "hwnd", $hDC, "int", 10, "int", 30, "str", $text, "int", $len)
    Sleep(20)
    Next
    Sleep(20)
WEnd

Func _exit()
    Exit
EndFunc
Edited by jpam

Share this post


Link to post
Share on other sites

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

As I suspected, you misunderstand a couple of basic concepts about Windows API calls. First, you insist on passing a string where the parameter calls for an integer value. Second, you assume that by using TextOut, that the GUI will automatically repaint itself and it doesn't. The GDI draw commands simple draw text to a DC. They are not responsible for invalidating the DC so that it is "clean". Below is your code as it should be written:

#include <GUIConstants.au3>

; SetTextAlign Constants
Global Const $TA_NOUPDATECP     = 0
Global Const $TA_LEFT           = 0
Global Const $TA_TOP            = 0
Global Const $TA_UPDATECP       = 1
Global Const $TA_RIGHT          = 2
Global Const $TA_CENTER         = 6
Global Const $TA_BOTTOM         = 8
Global Const $TA_BASELINE       = 24

; SetBkMode Constants
Global Const $TRANSPARENT       = 1
Global Const $OPAQUE            = 2

; Global variables
Global $hGUI, $hDC, $iIndex, $tRect, $sText, $iLen

HotKeySet("{Esc}", "DoExit")

; Create GUI
$hGUI = GUICreate("TextOut", 200, 100)
GUISetBkColor(0xFF0000, $hGUI)
GUISetState()

; Get the DC of the GUI
$hDC = DllCall("User32.dll", "hwnd", "GetDC", "hwnd", $hGUI)
$hDC = $hDC[0]

; Alter GUI background, color and text alignment
DllCall("GDI32.dll", "int", "SetTextColor", "hwnd", $hDC, "int", 0xFFFFFF    )
DllCall("GDI32.dll", "int", "SetBkMode"   , "hwnd", $hDC, "int", $TRANSPARENT)
DllCall("GDI32.dll", "int", "SetBkColor"  , "hwnd", $hDC, "int", 0x000000    )
DllCall("GDI32.dll", "int", "SetTextAlign", "hwnd", $hDC, "int", 0           )

; Loop until user exits
while 1
  ; Invalidate DC so it is clean
  $tRect = DllStructCreate("int;int;int;int")
  DllStructSetData($tRect, 1,   0)
  DllStructSetData($tRect, 2,  30)
  DllStructSetData($tRect, 3, 200)
  DllStructSetData($tRect, 4,  60)
  DllCall("User32.dll", "int", "InvalidateRect", "hwnd", $hGUI, "ptr", DllStructGetPtr($tRect), "int", True)
  ; Write next round of text
  $sText = $iIndex & "XZ368QS&" & $iIndex
  $iLen  = StringLen($sText)
  DllCall("GDI32.dll" , "int", "TextOut", "hwnd", $hDC, "int", 10, "int", 30, "str", $sText, "int", $iLen)
  $iIndex += 1
  if $iIndex > 100 then $iIndex = 0
  Sleep(250)
wend

Func DoExit()
  Exit
EndFunc
Edited by PaulIA

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

that's working fine !

diden't no to use a rectangle for the text !

thanks for the learning lesson PaulIA

Kind Regards

jpam

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0