Jump to content

_GDIPlus_GraphicsMeasureString and _GDIPlus_RectFCreate


 Share

Recommended Posts

Hello,

I´m trying to align the output Letters in the middle of the window, but I don´t know how to handle!

Could anyone post me an example or explain how to use it??

I even tried some with _WinAPI_GetTextExtentPoint32 but I don´t get it even..please help!

#include <File.au3>
#include <Array.au3>
#include <RegFunc.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <UpDownConstants.au3>
#include <EditConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
;Data
$dString = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z'
$aString = StringSplit($dString, ',')
Local $data[2][$aString[0] + 1]
For $i = 1 To $aString[0]
$data[0][$i] = $aString[$i]
$data[1][$i] = $i
Next
$data[0][0] = (UBound($data, 2) - 1)
;_ArrayDisplay($data, -1, -1, 1)
$cDataCount = 1 ;Letter Stellenzähler
$capi = 0 ;Gross- und Kleinschreibung
$FontList = _FileListToArray(@WindowsDir & '\Fonts', '*.ttf', 1);Schriftarten aus Windows Fonts Ordner holen
If @error = 1 Then
MsgBox(0, "", "No Folders Found.")
cleanup()
Exit
EndIf
If @error = 4 Then
MsgBox(0, "", "No Files Found.")
cleanup()
Exit
EndIf
$var = _GetRegValues('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts');Schriftartennamen aus Windows Registry holen
Dim $aItems[($FontList[0] + 1)]
$x = 1
Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo
;Arrays anzeigen
;_ArrayDisplay($FontList, "$FileList")
;~ _ArrayDisplay($var)
;~ $abby = _ArrayToString($var, ',')
;~ For $i = 0 To UBound($var)

;~ MsgBox(0, '', $abby)

;GUI erstellen
$msg = GUICreate("Installierte Schriftarten", 400, 500)
$listview = GUICtrlCreateListView("Nr.|Datei|Name", 10, 10, 380, 150, $LVS_SINGLESEL)
$button = GUICtrlCreateButton("OK", 20, 170, 70, 20)
$gWin = GUICtrlCreateGraphic(20, 200, 100, 100)
$iLetter = GUICtrlCreateInput("a", 100, 170, 20, 20, $ES_CENTER)
GUICtrlCreateLabel('Schriftgrösse: ', 140, 170, 65, 20)
$SchriftG = GUICtrlCreateInput('12', 210, 170, 36, 20)
$updwnSGR = GUICtrlCreateUpdown($SchriftG)
$gross = GUICtrlCreateButton('', 121, 170, 10, 10)
$klein = GUICtrlCreateButton('', 121, 180, 10, 10)
$bUp = GUICtrlCreateButton('Up', 121, 200, 24, 50)
$bDown = GUICtrlCreateButton('Dwn', 121, 250, 24, 50)
GUICtrlSetBkColor($gWin, 0xffffff)
GUICtrlSetBkColor($klein, 0x00ff00)
GUICtrlSetBkColor($gross, 0x8B0000)
GUICtrlSetColor($gWin, 0)
GUICtrlSetLimit($iLetter, 1)
GUICtrlSetLimit($listview, 1)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUICtrlSetOnEvent($button, "button")
GUICtrlSetOnEvent($bUp, "UP")
GUICtrlSetOnEvent($bDown, "DOWN")
GUICtrlSetOnEvent($gross, "gross")
GUICtrlSetOnEvent($klein, "klein")
GUICtrlSetOnEvent($updwnSGR, "SchriftGR")
_GUICtrlListView_SetSelectionMark($listview, 1)
$sTrim = _GUICtrlListView_GetSelectionMark($listview)
;GUI Liste schreiben
For $a = 1 To UBound($var)
If StringRight($var[$a - 1][2], 3) = 'ttf' Then
  $aItems[$x] = GUICtrlCreateListViewItem($x & '|' & $var[$a - 1][2] & '|' & $var[$a - 1][0], $listview)
  GUICtrlSetOnEvent($aItems[$x], "HandleClicks")
  $x = $x + 1
EndIf
Next

Drawing()

;GUI loop
While 1
$rAktList = GUICtrlRead($listview)
WEnd
;Funktionen
;SpecialEvents
Func SpecialEvents()
Select
  Case @GUI_CtrlId = $GUI_EVENT_CLOSE
   cleanup()
   Exit
EndSelect
EndFunc   ;==>SpecialEvents
;HandleClicks
Func HandleClicks()
$aktSel = GUICtrlRead(GUICtrlRead($listview))
$aList = StringSplit($aktSel, '|')
$sTrim = StringTrimRight($aList[3], 11)
Drawing()
EndFunc   ;==>HandleClicks
;button()
Func button()
$rInput = GUICtrlRead($iLetter)
MsgBox(0, 'Schriftart', GUICtrlRead(GUICtrlRead($listview)), 2)
Drawing()
EndFunc   ;==>button
;UP()
Func UP()
If $cDataCount < $aString[0] Then
  $cDataCount = $cDataCount + 1
EndIf
If $capi = 0 Then
  $new = StringLower($aString[$cDataCount])
Else
  $new = StringUpper($aString[$cDataCount])
EndIf
GUICtrlSetData($iLetter, $new)
Drawing()
EndFunc   ;==>UP
;DOWN()
Func DOWN()
If $cDataCount >= 2 Then
  $cDataCount = $cDataCount - 1
EndIf
If $capi = 1 Then
  gross()
EndIf
If $capi = 0 Then
  $new = StringLower($aString[$cDataCount])
Else
  $new = StringUpper($aString[$cDataCount])
EndIf
GUICtrlSetData($iLetter, $new)
Drawing()
EndFunc   ;==>DOWN
Func gross()
$capi = 1
$rInput = GUICtrlRead($iLetter)
$new = StringUpper($rInput)
GUICtrlSetData($iLetter, $new)
GUICtrlSetBkColor($gross, 0x00ff00)
GUICtrlSetBkColor($klein, 0x8B0000)
Drawing()
EndFunc   ;==>gross
Func klein()
$capi = 0
$rInput = GUICtrlRead($iLetter)
$new = StringLower($rInput)
GUICtrlSetData($iLetter, $new)
GUICtrlSetBkColor($klein, 0x00ff00)
GUICtrlSetBkColor($gross, 0x8B0000)
Drawing()
EndFunc   ;==>klein
Func SchriftGR()
$sgr = GUICtrlRead($SchriftG)
If $sgr <= 2 Then
  GUICtrlSetData($SchriftG, 2)
EndIf
If $sgr >= 80 Then
  GUICtrlSetData($SchriftG, 80)
EndIf
Drawing()
EndFunc   ;==>SchriftGR
Func Drawing()
GUICtrlSetColor($gWin, 0)
$rInput = GUICtrlRead($iLetter)
$sgr = GUICtrlRead($SchriftG)
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($msg)
$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
$hFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hFormat, 1)
$hFamily = _GDIPlus_FontFamilyCreate($sTrim)
$hFont = _GDIPlus_FontCreate($hFamily, $sgr, 0, 2)
$tLayout = _GDIPlus_RectFCreate(0, 50 - ($sgr / 2), 100, 100)
$aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $rInput, $hFont, $tLayout, $hFormat)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $rInput, $hFont, $aInfo[0], $hFormat, $hBrush)
$foo = _WinAPI_GetTextExtentPoint32($gWin, $rInput)
$x = DllStructGetData($foo,"X")
$y = DllStructGetData($foo,"Y")
ConsoleWrite($x & @TAB & $y & $aInfo[0] & @CRLF)
EndFunc   ;==>Drawing
; Clean up resources
Func cleanup()
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
EndFunc   ;==>cleanup
;Ende
cleanup()
Exit
Link to comment
Share on other sites

Morrison,

As I dont have file RegFile.au3 I couldnt test all your code, but commenting that out that code and changing the font family to 'arial', everything seemed to work fine. The letters landed right in middle of the window. :) Also you should add a sleep() to your main loop else cpu usage is way to high..

#include <File.au3>
#include <Array.au3>
;~ #include <RegFunc.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <UpDownConstants.au3>
#include <EditConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
;Data
$dString = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z'
$aString = StringSplit($dString, ',')
Local $data[2][$aString[0] + 1]
For $i = 1 To $aString[0]
     $data[0][$i] = $aString[$i]
     $data[1][$i] = $i
Next
$data[0][0] = (UBound($data, 2) - 1)
;_ArrayDisplay($data, -1, -1, 1)
$cDataCount = 1 ;Letter Stellenzähler
$capi = 0 ;Gross- und Kleinschreibung
$FontList = _FileListToArray(@WindowsDir & 'Fonts', '*.ttf', 1);Schriftarten aus Windows Fonts Ordner holen
If @error = 1 Then
     MsgBox(0, "", "No Folders Found.")
     cleanup()
     Exit
EndIf
If @error = 4 Then
     MsgBox(0, "", "No Files Found.")
     cleanup()
     Exit
EndIf
;~ $var = _GetRegValues('HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionFonts');Schriftartennamen aus Windows Registry holen
Dim $aItems[($FontList[0] + 1)]
$x = 1
Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo
;Arrays anzeigen
;_ArrayDisplay($FontList, "$FileList")
;~ _ArrayDisplay($var)
;~ $abby = _ArrayToString($var, ',')
;~ For $i = 0 To UBound($var)
;~ MsgBox(0, '', $abby)
;GUI erstellen
$msg = GUICreate("Installierte Schriftarten", 400, 500)
$listview = GUICtrlCreateListView("Nr.|Datei|Name", 10, 10, 380, 150, $LVS_SINGLESEL)
$button = GUICtrlCreateButton("OK", 20, 170, 70, 20)
$gWin = GUICtrlCreateGraphic(20, 200, 100, 100)
$iLetter = GUICtrlCreateInput("a", 100, 170, 20, 20, $ES_CENTER)
GUICtrlCreateLabel('Schriftgrösse: ', 140, 170, 65, 20)
$SchriftG = GUICtrlCreateInput('12', 210, 170, 36, 20)
$updwnSGR = GUICtrlCreateUpdown($SchriftG)
$gross = GUICtrlCreateButton('', 121, 170, 10, 10)
$klein = GUICtrlCreateButton('', 121, 180, 10, 10)
$bUp = GUICtrlCreateButton('Up', 121, 200, 24, 50)
$bDown = GUICtrlCreateButton('Dwn', 121, 250, 24, 50)
GUICtrlSetBkColor($gWin, 0xffffff)
GUICtrlSetBkColor($klein, 0x00ff00)
GUICtrlSetBkColor($gross, 0x8B0000)
GUICtrlSetColor($gWin, 0)
GUICtrlSetLimit($iLetter, 1)
GUICtrlSetLimit($listview, 1)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUICtrlSetOnEvent($button, "button")
GUICtrlSetOnEvent($bUp, "UP")
GUICtrlSetOnEvent($bDown, "DOWN")
GUICtrlSetOnEvent($gross, "gross")
GUICtrlSetOnEvent($klein, "klein")
GUICtrlSetOnEvent($updwnSGR, "SchriftGR")
_GUICtrlListView_SetSelectionMark($listview, 1)
$sTrim = _GUICtrlListView_GetSelectionMark($listview)
;GUI Liste schreiben
;~ For $a = 1 To UBound($var)
;~    If StringRight($var[$a - 1][2], 3) = 'ttf' Then
;~         $aItems[$x] = GUICtrlCreateListViewItem($x & '|' & $var[$a - 1][2] & '|' & $var[$a - 1][0], $listview)
;~         GUICtrlSetOnEvent($aItems[$x], "HandleClicks")
;~         $x = $x + 1
;~    EndIf
;~ Next
Drawing()
;GUI loop
While 1
     $rAktList = GUICtrlRead($listview)
     Sleep(100)
WEnd
;Funktionen
;SpecialEvents
Func SpecialEvents()
     Select
          Case @GUI_CtrlId = $GUI_EVENT_CLOSE
               cleanup()
               Exit
     EndSelect
EndFunc   ;==>SpecialEvents
;HandleClicks
Func HandleClicks()
     $aktSel = GUICtrlRead(GUICtrlRead($listview))
     $aList = StringSplit($aktSel, '|')
     $sTrim = StringTrimRight($aList[3], 11)
     Drawing()
EndFunc   ;==>HandleClicks
;button()
Func button()
     $rInput = GUICtrlRead($iLetter)
     MsgBox(0, 'Schriftart', GUICtrlRead(GUICtrlRead($listview)), 2)
     Drawing()
EndFunc   ;==>button
;UP()
Func UP()
     If $cDataCount < $aString[0] Then
          $cDataCount = $cDataCount + 1
     EndIf
     If $capi = 0 Then
          $new = StringLower($aString[$cDataCount])
     Else
          $new = StringUpper($aString[$cDataCount])
     EndIf
     GUICtrlSetData($iLetter, $new)
     Drawing()
EndFunc   ;==>UP
;DOWN()
Func DOWN()
     If $cDataCount >= 2 Then
          $cDataCount = $cDataCount - 1
     EndIf
     If $capi = 1 Then
          gross()
     EndIf
     If $capi = 0 Then
          $new = StringLower($aString[$cDataCount])
     Else
          $new = StringUpper($aString[$cDataCount])
     EndIf
     GUICtrlSetData($iLetter, $new)
     Drawing()
EndFunc   ;==>DOWN
Func gross()
     $capi = 1
     $rInput = GUICtrlRead($iLetter)
     $new = StringUpper($rInput)
     GUICtrlSetData($iLetter, $new)
     GUICtrlSetBkColor($gross, 0x00ff00)
     GUICtrlSetBkColor($klein, 0x8B0000)
     Drawing()
EndFunc   ;==>gross
Func klein()
     $capi = 0
     $rInput = GUICtrlRead($iLetter)
     $new = StringLower($rInput)
     GUICtrlSetData($iLetter, $new)
     GUICtrlSetBkColor($klein, 0x00ff00)
     GUICtrlSetBkColor($gross, 0x8B0000)
     Drawing()
EndFunc   ;==>klein
Func SchriftGR()
     $sgr = GUICtrlRead($SchriftG)
     If $sgr <= 2 Then
          GUICtrlSetData($SchriftG, 2)
     EndIf
     If $sgr >= 80 Then
          GUICtrlSetData($SchriftG, 80)
     EndIf
     Drawing()
EndFunc   ;==>SchriftGR
Func Drawing()
     GUICtrlSetColor($gWin, 0)
     $rInput = GUICtrlRead($iLetter)
     $sgr = GUICtrlRead($SchriftG)
     _GDIPlus_Startup()
     $hGraphic = _GDIPlus_GraphicsCreateFromHWND($msg)
     $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
     $hFormat = _GDIPlus_StringFormatCreate()
     _GDIPlus_StringFormatSetAlign($hFormat, 1)
     $hFamily = _GDIPlus_FontFamilyCreate('arial')
     $hFont = _GDIPlus_FontCreate($hFamily, $sgr, 0, 2)
     $tLayout = _GDIPlus_RectFCreate(0, 50 - ($sgr / 2), 100, 100)
     $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $rInput, $hFont, $tLayout, $hFormat)
     _GDIPlus_GraphicsDrawStringEx($hGraphic, $rInput, $hFont, $aInfo[0], $hFormat, $hBrush)
     $foo = _WinAPI_GetTextExtentPoint32($gWin, $rInput)
     $x = DllStructGetData($foo, "X")
     $y = DllStructGetData($foo, "Y")
     ConsoleWrite($x & @TAB & $y & $aInfo[0] & @CRLF)
EndFunc   ;==>Drawing
; Clean up resources
Func cleanup()
     _GDIPlus_FontDispose($hFont)
     _GDIPlus_FontFamilyDispose($hFamily)
     _GDIPlus_StringFormatDispose($hFormat)
     _GDIPlus_BrushDispose($hBrush)
     _GDIPlus_GraphicsDispose($hGraphic)
     _GDIPlus_Shutdown()
EndFunc   ;==>cleanup
;Ende
cleanup()
Exit
Link to comment
Share on other sites

Hi!

Now I´ve got a code wich needs to be integrated to this GUI!

The left window shall display UpperCase letters the right the LowerCase ones.

GUI:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:UsersIBMDesktopAU3_OCR_newForm1.kxf
$Form1_1 = GUICreate("Form1", 587, 245, 215, 153)
$MenuItem2 = GUICtrlCreateMenu("&MenuItem2")
$MenuItem4 = GUICtrlCreateMenuItem("MenuItem4", $MenuItem2)
$MenuItem3 = GUICtrlCreateMenuItem("MenuItem3", $MenuItem2)
$MenuItem1 = GUICtrlCreateMenu("M&enuItem1")
$MenuItem5 = GUICtrlCreateMenuItem("MenuItem5", $MenuItem1)
$ListView1 = GUICtrlCreateListView("", 280, 11, 290, 155, -1, BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE,$LVS_EX_FULLROWSELECT))
$Edit1 = GUICtrlCreateEdit("", 16, 66, 100, 100, $ES_WANTRETURN)
GUICtrlSetData(-1, "Edit1")
$Edit2 = GUICtrlCreateEdit("", 166, 66, 100, 100, $ES_WANTRETURN)
GUICtrlSetData(-1, "Edit1")
$Button1 = GUICtrlCreateButton("Up", 123, 66, 35, 50, -1, $WS_EX_CLIENTEDGE)
$Button2 = GUICtrlCreateButton("Dwn", 123, 116, 35, 50, -1, $WS_EX_CLIENTEDGE)
$Button3 = GUICtrlCreateButton("Start", 26, 186, 80, 25, -1, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Button4 = GUICtrlCreateButton("Abbruch", 176, 186, 80, 25, -1, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Progress1 = GUICtrlCreateProgress(21, 171, 240, 10, -1, $WS_EX_STATICEDGE)
$Button5 = GUICtrlCreateButton("current dir", 61, 11, 160, 20)
$Combo1 = GUICtrlCreateCombo("", 41, 36, 200, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Button6 = GUICtrlCreateButton("Alle Daten", 330, 176, 190, 25)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd

script:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Global $hGui = GUICreate("Test", 320, 240)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
_GDIPlus_Startup()
Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics(320, 240, $hGraphics)
Global $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)
Global $hPen = _GDIPlus_PenCreate(0xFF00FF00)
Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUIRegisterMsg($WM_ERASEBKGND, "WM_PAINT")
GUISetState()
_GDIPlus_GraphicsDrawLine($hGfxBuffer, 160, 0, 160, 240, $hPen)
_Zentriere("Test", 160, 120)
_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)

While Sleep(100)
WEnd

Func _Zentriere($sString, $iX, $iY, $fSize = 70, $sFont = "Arial")
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
    Local $hPath = $aResult[2]
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    Local $tBounds = _GDIPlus_RectFCreate(0, 0, 0, 0)
    DllCall($ghGDIPDll, "uint", "GdipAddPathString", "hwnd", $hPath, "wstr", $sString, "int", -1, "hwnd", $hFamily, "int", 0, "float", $fSize, "ptr", DllStructGetPtr($tLayout), "hwnd", $hFormat)
    DllCall($ghGDIPDll, "uint", "GdipGetPathWorldBounds", "hwnd", $hPath, "ptr", DllStructGetPtr($tBounds), "hwnd", 0, "hwnd", 0)
    Local $fRectX = DllStructGetData($tBounds, "X")
    Local $fRectY = DllStructGetData($tBounds, "Y")
    Local $fRectW = DllStructGetData($tBounds, "Width")
    Local $fRectH = DllStructGetData($tBounds, "Height")
    Local $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($hMatrix, -$fRectX - $fRectW / 2 + $iX, -$fRectY - $fRectH / 2 + $iY)
    DllCall($ghGDIPDll, "uint", "GdipTransformPath", "hwnd", $hPath, "hwnd", $hMatrix)
    _GDIPlus_MatrixDispose($hMatrix)
    DllCall($ghGDIPDll, "uint", "GdipFillPath", "hwnd", $hGfxBuffer, "hwnd", $hBrush, "hwnd", $hPath)
    DllCall($ghGDIPDll, "int", "GdipDrawRectangle", "handle", $hGfxBuffer, "handle", $hPen, "float", $iX - $fRectW / 2, "float", $iY - $fRectH / 2, "float", $fRectW, "float", $fRectH)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath)
EndFunc   ;==>_Zentriere

Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT

Func _Exit()
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit
Link to comment
Share on other sites

Before I jump on this one, what was wrong in the original post? Never got any feedback..

Link to comment
Share on other sites

Oh I don't really care about that. To be honest I didnt feel I gave you any suggestions. I stopped working on it when I couldn't figure out what the problem was. :)

Anyway are you only trying to use that GUI because Koda generated it that way? If so I want to point out that Koda will generate OnEvent mode code for you. Heres the same GUI in OnEvent mode:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
Global $hGui = GUICreate("Form1", 588, 246, 249, 222)
Global $MenuItem2 = GUICtrlCreateMenu("&MenuItem2")
GUICtrlSetOnEvent(-1, "MenuItem2Click")
Global $MenuItem4 = GUICtrlCreateMenuItem("MenuItem4"&@TAB&"", $MenuItem2)
Global $MenuItem3 = GUICtrlCreateMenuItem("MenuItem3", $MenuItem2)
Global $MenuItem1 = GUICtrlCreateMenu("M&enuItem1")
GUICtrlSetOnEvent(-1, "MenuItem1Click")
Global $MenuItem5 = GUICtrlCreateMenuItem("MenuItem5", $MenuItem1)
GUISetOnEvent($GUI_EVENT_CLOSE, "hGuiClose")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "hGuiMinimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "hGuiMaximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "hGuiRestore")
Global $ListView1 = GUICtrlCreateListView("", 280, 11, 290, 155, -1, BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE,$LVS_EX_FULLROWSELECT))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSetOnEvent(-1, "ListView1Click")
Global $Edit1 = GUICtrlCreateEdit("", 16, 66, 100, 100)
GUICtrlSetData(-1, "Edit1")
GUICtrlSetOnEvent(-1, "Edit1Change")
Global $Edit2 = GUICtrlCreateEdit("", 166, 66, 100, 100)
GUICtrlSetData(-1, "Edit1")
GUICtrlSetOnEvent(-1, "Edit2Change")
Global $Button1 = GUICtrlCreateButton("Up", 123, 66, 35, 50, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetOnEvent(-1, "Button1Click")
Global $Button2 = GUICtrlCreateButton("Dwn", 123, 116, 35, 50, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetOnEvent(-1, "Button2Click")
Global $Button3 = GUICtrlCreateButton("Start", 26, 186, 80, 25, -1, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Button3Click")
Global $Button4 = GUICtrlCreateButton("Abbruch", 176, 186, 80, 25, -1, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Button4Click")
Global $Progress1 = GUICtrlCreateProgress(21, 171, 240, 10, -1, $WS_EX_STATICEDGE)
Global $Button5 = GUICtrlCreateButton("current dir", 61, 11, 160, 20)
GUICtrlSetOnEvent(-1, "Button5Click")
Global $Combo1 = GUICtrlCreateCombo("", 41, 36, 200, 25)
GUICtrlSetOnEvent(-1, "Combo1Change")
Global $Button6 = GUICtrlCreateButton("Alle Daten", 330, 176, 190, 25)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Button6Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
     Sleep(100)
WEnd

Func Button1Click()
EndFunc
Func Button2Click()
EndFunc
Func Button3Click()
EndFunc
Func Button4Click()
EndFunc
Func Button5Click()
EndFunc
Func Button6Click()
EndFunc
Func Combo1Change()
EndFunc
Func Edit1Change()
EndFunc
Func Edit2Change()
EndFunc
Func hGuiMaximize()
EndFunc
Func hGuiMinimize()
EndFunc
Func hGuiRestore()
EndFunc
Func ListView1Click()
EndFunc
Func MenuItem1Click()
EndFunc
Func MenuItem2Click()
EndFunc
Func hGuiClose()
Exit
EndFunc

If not here's a attempt, but all of the coordinates are wrong. You should be able to make those adjustments as I feel its just using messageloop mode that confusing you. The listview box was just a reference right? (because I think you know you can't put a gdi bitmap in a listview)

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#region ### START Koda GUI section ### Form=C:UsersIBMDesktopAU3_OCR_newForm1.kxf
$hGui = GUICreate("Form1", 587, 245, 215, 153)
$MenuItem2 = GUICtrlCreateMenu("&MenuItem2")
$MenuItem4 = GUICtrlCreateMenuItem("MenuItem4", $MenuItem2)
$MenuItem3 = GUICtrlCreateMenuItem("MenuItem3", $MenuItem2)
$MenuItem1 = GUICtrlCreateMenu("M&enuItem1")
$MenuItem5 = GUICtrlCreateMenuItem("MenuItem5", $MenuItem1)
;$ListView1 = GUICtrlCreateListView('', 280, 11, 290, 155, -1, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE, $LVS_EX_FULLROWSELECT))
$Edit1 = GUICtrlCreateEdit("", 16, 66, 100, 100, $ES_WANTRETURN)
GUICtrlSetData(-1, "Edit1")
$Edit2 = GUICtrlCreateEdit("", 166, 66, 100, 100, $ES_WANTRETURN)
GUICtrlSetData(-1, "Edit1")
$Button1 = GUICtrlCreateButton("Up", 123, 66, 35, 50, -1, $WS_EX_CLIENTEDGE)
$Button2 = GUICtrlCreateButton("Dwn", 123, 116, 35, 50, -1, $WS_EX_CLIENTEDGE)
$Button3 = GUICtrlCreateButton("Start", 26, 186, 80, 25, -1, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Button4 = GUICtrlCreateButton("Abbruch", 176, 186, 80, 25, -1, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Progress1 = GUICtrlCreateProgress(21, 171, 240, 10, -1, $WS_EX_STATICEDGE)
$Button5 = GUICtrlCreateButton("current dir", 61, 11, 160, 20)
$Combo1 = GUICtrlCreateCombo("", 41, 36, 200, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$Button6 = GUICtrlCreateButton("Alle Daten", 330, 176, 190, 25)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
_GDIPlus_Startup()
Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics(320, 240, $hGraphics)
Global $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)
Global $hPen = _GDIPlus_PenCreate(0xFF00FF00)
Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUIRegisterMsg($WM_ERASEBKGND, "WM_PAINT")
_GDIPlus_GraphicsDrawLine($hGfxBuffer, 160, 0, 160, 240, $hPen)
_Zentriere("Test", 160, 120)
_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 280, 11)
While 1
     $nMsg = GUIGetMsg()
     Switch $nMsg
          Case $GUI_EVENT_CLOSE
               _GDIPlus_PenDispose($hPen)
               _GDIPlus_BrushDispose($hBrush)
               _GDIPlus_GraphicsDispose($hGfxBuffer)
               _GDIPlus_BitmapDispose($hBmpBuffer)
               _GDIPlus_GraphicsDispose($hGraphics)
               _GDIPlus_Shutdown()
               Exit
             case $Button1
                ;your code
             case $Button2
                ;your code
     EndSwitch
WEnd

Func _Zentriere($sString, $iX, $iY, $fSize = 70, $sFont = "Arial")
     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
     Local $hPath = $aResult[2]
     Local $hFormat = _GDIPlus_StringFormatCreate()
     Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
     Local $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
     Local $tBounds = _GDIPlus_RectFCreate(0, 0, 0, 0)
     DllCall($ghGDIPDll, "uint", "GdipAddPathString", "hwnd", $hPath, "wstr", $sString, "int", -1, "hwnd", $hFamily, "int", 0, "float", $fSize, "ptr", DllStructGetPtr($tLayout), "hwnd", $hFormat)
     DllCall($ghGDIPDll, "uint", "GdipGetPathWorldBounds", "hwnd", $hPath, "ptr", DllStructGetPtr($tBounds), "hwnd", 0, "hwnd", 0)
     Local $fRectX = DllStructGetData($tBounds, "X")
     Local $fRectY = DllStructGetData($tBounds, "Y")
     Local $fRectW = DllStructGetData($tBounds, "Width")
     Local $fRectH = DllStructGetData($tBounds, "Height")
     Local $hMatrix = _GDIPlus_MatrixCreate()
     _GDIPlus_MatrixTranslate($hMatrix, -$fRectX - $fRectW / 2 + $iX, -$fRectY - $fRectH / 2 + $iY)
     DllCall($ghGDIPDll, "uint", "GdipTransformPath", "hwnd", $hPath, "hwnd", $hMatrix)
     _GDIPlus_MatrixDispose($hMatrix)
     DllCall($ghGDIPDll, "uint", "GdipFillPath", "hwnd", $hGfxBuffer, "hwnd", $hBrush, "hwnd", $hPath)
     DllCall($ghGDIPDll, "int", "GdipDrawRectangle", "handle", $hGfxBuffer, "handle", $hPen, "float", $iX - $fRectW / 2, "float", $iY - $fRectH / 2, "float", $fRectW, "float", $fRectH)
     _GDIPlus_FontFamilyDispose($hFamily)
     _GDIPlus_StringFormatDispose($hFormat)
     DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath)
EndFunc   ;==>_Zentriere

Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
     _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
     Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT

edit: forgot to comment out your listview..

Edited by Beege
Link to comment
Share on other sites

mpf, no! :)

I wanted to have the letter "A" in the left CtrlEdit and "a" in the right by using the _Zentriere() func!

The Test Pic was included in the script. I just don´t know how to translate it in what I want.

In the Listview I want to list installed Fonts. With "Up & "Down" I want to change the Letters.

And by clicking on an listview Item I wanna change the Font-Type.

Sry for my bad english, long time outta school, huh.

RegFunc.au3:

;========================================================================================
; Function Name:   _GetRegSubKeys($HKEY)
; Description:   Ermittelt die Unterschlüssel für den übergebenen Schlüssel
; Parameter(s):    $HKEY   der Registryschlüssel
; Return Value(s): Erfolg  Array mit den Unterschlüsseln
;                 Fehler  Leerstring (keine Unterschlüssel vorhanden oder Schlüssel existiert nicht)
; Author(s):       BugFix (bugfix@autoit.de)
;========================================================================================
Func _GetRegSubKeys($HKEY)
If StringInStr($HKEY, '') Then
  If StringRight($HKEY, 1) = '' Then
   $HKEY = StringTrimRight($HKEY, 1)
   Local $strKeyPath = ''
  Else
   Local $strKeyPath = StringRight($HKEY, StringLen($HKEY)-StringInStr($HKEY, '') )
   $HKEY = StringLeft($HKEY, StringInStr($HKEY, '')-1)
  EndIf
Else
  Local $strKeyPath = ''
EndIf
Select
  Case $HKEY = "HKEY_LOCAL_MACHINE" Or $HKEY = "HKLM"
   $HKEY = 0x80000002
  Case $HKEY = "HKEY_USERS" Or $HKEY = "HKU"
   $HKEY = 0x80000003
  Case $HKEY = "HKEY_CURRENT_USER" Or $HKEY = "HKCU"
   $HKEY = 0x80000001
  Case $HKEY = "HKEY_CLASSES_ROOT" Or $HKEY = "HKCR"
   $HKEY = 0x80000000
  Case $HKEY = "HKEY_CURRENT_CONFIG" Or $HKEY = "HKCC"
   $HKEY = 0x80000005
EndSelect
Local $arrSubKeys = '', $subkey
Local $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!.rootdefault:StdRegProv")
$oReg.EnumKey ($HKEY, $strKeyPath, $arrSubKeys)
Return $arrSubKeys
EndFunc  ;==>_GetRegSubKeys
;========================================================================================
; Function Name:   _GetRegRights($HKEY)
; Description:   Ermittelt die Rechte des Abfragenden für den übergebenen Schlüssel
; Parameter(s):    $HKEY   der zu prüfende Registryschlüssel
; Return Value(s): String mit Auflistung der Rechte:
;                 Q  Key Query Value
;                 S  Key Set Value
;                 C  Key Create Sub Key
;                 D  Delete
; Author(s):       BugFix (bugfix@autoit.de)
;========================================================================================
Func _GetRegRights($HKEY)
Local $bHasAccessRight, $sRights = ''
If StringInStr($HKEY, '') Then
  If StringRight($HKEY, 1) = '' Then
   $HKEY = StringTrimRight($HKEY, 1)
   Local $strKeyPath = ''
  Else
   Local $strKeyPath = StringRight($HKEY, StringLen($HKEY)-StringInStr($HKEY, '') )
   $HKEY = StringLeft($HKEY, StringInStr($HKEY, '')-1)
  EndIf
Else
  Local $strKeyPath = ''
EndIf
Select
  Case $HKEY = "HKEY_LOCAL_MACHINE" Or $HKEY = "HKLM"
   $HKEY = 0x80000002
  Case $HKEY = "HKEY_USERS" Or $HKEY = "HKU"
   $HKEY = 0x80000003
  Case $HKEY = "HKEY_CURRENT_USER" Or $HKEY = "HKCU"
   $HKEY = 0x80000001
  Case $HKEY = "HKEY_CLASSES_ROOT" Or $HKEY = "HKCR"
   $HKEY = 0x80000000
  Case $HKEY = "HKEY_CURRENT_CONFIG" Or $HKEY = "HKCC"
   $HKEY = 0x80000005
EndSelect
Local $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!.rootdefault:StdRegProv")
$oReg.CheckAccess($HKEY, $strKeyPath, 0x0001, $bHasAccessRight)
If $bHasAccessRight = True Then $sRights &= 'Q'
$oReg.CheckAccess($HKEY, $strKeyPath, 0x0002, $bHasAccessRight)
If $bHasAccessRight = True Then $sRights &= 'S'
$oReg.CheckAccess($HKEY, $strKeyPath, 0x0004, $bHasAccessRight)
If $bHasAccessRight = True Then $sRights &= 'C'
$oReg.CheckAccess($HKEY, $strKeyPath, 0x00010000, $bHasAccessRight)
If $bHasAccessRight = True Then $sRights &= 'D'
Return $sRights
EndFunc  ;==>_GetRegRights
;========================================================================================
; Function Name:    _GetRegValues($HKEY)
; Description:   Ermittelt alle Namen, Typen und Werte in einem gegebenen Schlüssel
; Parameter(s):    $HKEY   der Registryschlüssel
; Return Value(s): Erfolg  Array[i][0] = Name
;                         Array[i][1] = Typ
;                         Array[i][2] = Wert
;                 Fehler  Leerstring (Schlüssel existiert nicht oder ist ohne Einträge)
; Author(s):       BugFix (bugfix@autoit.de)
;========================================================================================
Func _GetRegValues($HKEY)
Local $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
If StringInStr($HKEY, '') Then
  If StringRight($HKEY, 1) = '' Then
   $HKEY = StringTrimRight($HKEY, 1)
   Local $strKeyPath = ''
  Else
   Local $strKeyPath = StringRight($HKEY, StringLen($HKEY)-StringInStr($HKEY, '') )
   $HKEY = StringLeft($HKEY, StringInStr($HKEY, '')-1)
  EndIf
Else
  Local $strKeyPath = ''
EndIf
Select
  Case $HKEY = "HKEY_LOCAL_MACHINE" Or $HKEY = "HKLM"
   $HKEY = 0x80000002
  Case $HKEY = "HKEY_USERS" Or $HKEY = "HKU"
   $HKEY = 0x80000003
  Case $HKEY = "HKEY_CURRENT_USER" Or $HKEY = "HKCU"
   $HKEY = 0x80000001
  Case $HKEY = "HKEY_CLASSES_ROOT" Or $HKEY = "HKCR"
   $HKEY = 0x80000000
  Case $HKEY = "HKEY_CURRENT_CONFIG" Or $HKEY = "HKCC"
   $HKEY = 0x80000005
EndSelect
Local $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!.rootdefault:StdRegProv")
Local $arrValueNames, $arrValueTypes, $strValue
$oReg.EnumValues($HKEY, $strKeyPath, $arrValueNames, $arrValueTypes)
$OEvent = ObjEvent($oReg, "EnumValues")
If Not IsArray($arrValueNames) Then Return ''
Local $arOut[UBound($arrValueNames)][3]
For $i = 0 To UBound($arrValueNames) -1
  $arOut[$i][0] = $arrValueNames[$i]
  Switch $arrValueTypes[$i]
   Case 1
    $arOut[$i][1] = 'REG_SZ'
    $oReg.GetStringValue($HKEY, $strKeyPath, $arrValueNames[$i], $strValue)
   Case 2
    $arOut[$i][1] = 'REG_EXPAND_SZ'
    $oReg.GetExpandedStringValue($HKEY, $strKeyPath, $arrValueNames[$i], $strValue)
   Case 3
    $arOut[$i][1] = 'REG_BINARY'
    $oReg.GetBinaryValue($HKEY, $strKeyPath, $arrValueNames[$i], $strValue)
   Case 4
    $arOut[$i][1] = 'REG_DWORD'
    $oReg.GetStringValue($HKEY, $strKeyPath, $arrValueNames[$i], $strValue)
   Case 7
    $arOut[$i][1] = 'REG_MULTI_SZ'
    $oReg.GetMultiStringValue($HKEY, $strKeyPath, $arrValueNames[$i], $strValue)
  EndSwitch
  $arOut[$i][2] = $strValue
Next
Return $arOut
EndFunc  ;==>_GetRegValues
Func MyErrFunc()
   Return
Endfunc
Edited by Morrison
Link to comment
Share on other sites

Hi again,

now I tried to calc new the "$tagRect"!! But it´s still not in the middle!?!

And it takes too much time to create new "$tagRect", who knows a better way??

#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <Fontconstants.au3>
#include <GDIPlus.au3>
#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListviewConstants.au3>
#include <ProgressConstants.au3>
#include <RegFunc.au3>
#include <StaticConstants.au3>
#include <UpDownConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Opt("PixelCoordMode", 0)
;Data
$dString = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,ä,ö,ü'
$aString = StringSplit($dString, ',')
Local $data[3][$aString[0] + 1]
Local $rLinks, $rRechts, $rOben, $rUnten, $rWidth, $rHeight
For $i = 1 To $aString[0]
$data[0][$i] = $i
$data[1][$i] = StringUpper($aString[$i])
$data[2][$i] = StringLower($aString[$i])
Next
$cDataCount = 1 ;Letter Stellenzähler
$data[0][0] = (UBound($data, 2) - 1)
;Fonts
$FontList = _FileListToArray(@WindowsDir & 'Fonts', '*.ttf', 1);Schriftarten aus Windows Fonts Ordner holen
$var = _GetRegValues('HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionFonts');Schriftartennamen aus Windows Registry holen
Dim $aItems[($FontList[0] + 1)]
$x = 1
#region ### START Koda GUI section ### Form=C:UsersIBMDesktopAU3_OCR_newForm1.kxf
$msg = GUICreate("Form1", 620, 245, 215, 124)
$Datei = GUICtrlCreateMenu("&Datei")
$MenuItem1 = GUICtrlCreateMenuItem("Optionen" & @TAB & "", $Datei)
$MenuItem2 = GUICtrlCreateMenuItem("Exit" & @TAB & "", $Datei)
$Hilfe = GUICtrlCreateMenu("&Hilfe")
$listview = GUICtrlCreateListView("Nr.|Datei|Name", 277, 12, 335, 170)
$gWin1 = GUICtrlCreateGraphic(11, 66, 100, 100, $SS_WHITERECT)
$gWin2 = GUICtrlCreateGraphic(171, 66, 100, 100, $SS_WHITERECT)
$SchriftG = GUICtrlCreateInput('32', 123, 106, 35, 20)
$updwnSGR = GUICtrlCreateUpdown($SchriftG)
$bUp = GUICtrlCreateButton("Up", 123, 66, 35, 35, -1, $WS_EX_CLIENTEDGE)
$bDown = GUICtrlCreateButton("Dwn", 123, 131, 35, 35, -1, $WS_EX_CLIENTEDGE)
$bStart = GUICtrlCreateButton("Start", 26, 190, 80, 25, -1, $WS_EX_STATICEDGE)
$bAbbruch = GUICtrlCreateButton("Abbruch", 176, 190, 80, 25, -1, $WS_EX_STATICEDGE)
$bDaten = GUICtrlCreateButton("Alle Daten", 352, 188, 190, 30)
$Progress1 = GUICtrlCreateProgress(21, 172, 240, 10, -1, $WS_EX_STATICEDGE)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
_GUICtrlListView_SetColumnWidth($listview, 0, 28)
_GUICtrlListView_SetColumnWidth($listview, 1, 40)
_GUICtrlListView_SetColumnWidth($listview, 2, 180)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUICtrlSetOnEvent($bStart, "button")
GUICtrlSetOnEvent($bUp, "UP")
GUICtrlSetOnEvent($bDown, "DOWN")
GUICtrlSetOnEvent($listview, "HandleClicks")
GUICtrlSetOnEvent($updwnSGR, "SchriftGR")
;GUI Liste schreiben
For $a = 1 To UBound($var)
If StringRight($var[$a - 1][2], 3) = 'ttf' Then
  If StringInStr($var[$a - 1][0], 'Bold', 1) = False And StringInStr($var[$a - 1][0], 'Italic', 1) = False _
    And StringInStr($var[$a - 1][0], 'MT Extra', 1) = False Then
   $nName = StringReplace($var[$a - 1][0], '(TrueType)', '', 1)
   $aItems[$x] = GUICtrlCreateListViewItem($x & '|' & $var[$a - 1][2] & '|' & $nName, $listview)
   GUICtrlSetOnEvent($aItems[$x], "HandleClicks")
   $x = $x + 1
  EndIf
EndIf
Next
_GUICtrlListView_SetSelectionMark($listview, 0)
$sTrim = _GUICtrlListView_GetSelectionMark($listview)
_GUICtrlListView_ClickItem($listview, 0, "left", False, 1)
While 1
$rAktList = GUICtrlRead($listview)
$sgr = GUICtrlRead($SchriftG)
WEnd
;Funktionen
;SpecialEvents
Func SpecialEvents()
Select
  Case @GUI_CtrlId = $GUI_EVENT_CLOSE
   cleanup()
   Exit
EndSelect
EndFunc   ;==>SpecialEvents
;HandleClicks
Func HandleClicks()
$aktSel = GUICtrlRead(GUICtrlRead($listview))
$aList = StringSplit($aktSel, '|')
$sTrim = StringTrimRight($aList[3], 1)
;_ArrayDisplay($aList)
Drawing()
EndFunc   ;==>HandleClicks
;button()
Func button()
;$rInput1 = GUICtrlRead($iLetter)
MsgBox(0, 'Schriftart', GUICtrlRead(GUICtrlRead($listview)), 2)
Drawing()
EndFunc   ;==>button
;UP()
Func UP()
If $cDataCount < $aString[0] Then
  $cDataCount = $cDataCount + 1
EndIf
Drawing()
EndFunc   ;==>UP
;DOWN()
Func DOWN()
If $cDataCount >= 2 Then
  $cDataCount = $cDataCount - 1
EndIf
Drawing()
EndFunc   ;==>DOWN
Func SchriftGR()
$sgr = GUICtrlRead($SchriftG)
If $sgr <= 8 Then
  GUICtrlSetData($SchriftG, 8)
EndIf
If $sgr >= 99 Then
  GUICtrlSetData($SchriftG, 99)
EndIf
Drawing()
EndFunc   ;==>SchriftGR
Func Drawing()
Local $iRectWidth, $iRectHeight, $aCtrlPos1
GUICtrlSetColor($gWin1, 0)
GUICtrlSetColor($gWin2, 0)
$rInput = $aString[$cDataCount]
$rInput1 = StringUpper($rInput)
$rInput2 = StringLower($rInput)
$sgr = GUICtrlRead($SchriftG)
; Größe des Graphic-Controls ermitteln (Noch 100x100, aber wer weiß, wann sich das ändert)
$aCtrlPos1 = ControlGetPos($msg, '', $gWin1)
$aCtrlPos2 = ControlGetPos($msg, '', $gWin2)
$iRectWidth = $aCtrlPos1[2]
$iRectHeight = $aCtrlPos1[3]
; DC vom Graphics-Control holen
$hDC1 = _WinAPI_GetDC(GUICtrlGetHandle($gWin1))
$hDC2 = _WinAPI_GetDC(GUICtrlGetHandle($gWin2))
; Font erstellen
;$iDeviceCapY = _WinAPI_GetDeviceCaps($hDC1, $__WINAPICONSTANT_LOGPIXELSX)
;MsgBox(0, '', $iDeviceCapY)
$hFont = _WinAPI_CreateFont($sgr, 0, 0, 0, $FW_NORMAL, False, False, False _
   , $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, $sTrim)
; Font mit DC verbinden
_WinAPI_SelectObject($hDC1, $hFont)
_WinAPI_SelectObject($hDC2, $hFont)
;Font zeichnen
$tPoint1 = _WinAPI_GetTextExtentPoint32($hDC1, $rInput1)
$tPoint2 = _WinAPI_GetTextExtentPoint32($hDC2, $rInput2)
$tRect = DllStructCreate($tagRECT)
;~  $tRect1 = _WinAPI_DrawText($hDC1, $rInput1, $tRect, $DT_CALCRECT)
;~  $tRect2 = _WinAPI_DrawText($hDC1, $rInput1, $tRect, $DT_CALCRECT)
DllStructSetData($tRect, 'left', ($iRectWidth / 2) - (DllStructGetData($tPoint1, 'x') / 2))
DllStructSetData($tRect, 'top', ($iRectHeight / 2) - (DllStructGetData($tPoint1, 'y') / 2))
DllStructSetData($tRect, 'right', DllStructGetData($tRect, 'left') + DllStructGetData($tPoint1, 'x'))
DllStructSetData($tRect, 'bottom', DllStructGetData($tRect, 'top') + DllStructGetData($tPoint1, 'y'))
; Text auf Graphics-Control zeichnen
_WinAPI_DrawText($hDC1, $rInput1, $tRect, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))
_WinAPI_DrawText($hDC2, $rInput2, $tRect, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))
GetRect($gWin1)
;~  MsgBox(0, '', 'Links: ' & $rLinks & @CRLF & 'Rechts: ' & $rRechts & @CRLF & 'Oben: ' & $rOben & @CRLF & 'Unten: ' & $rUnten _
;~   & @CRLF & 'Breite: ' & $rWidth & @CRLF & 'Höhe: ' & $rHeight)
;~
$tRect1 = DllStructCreate($tagRECT)
DllStructSetData($tRect1, 'left', 50 - ($rWidth / 2))
DllStructSetData($tRect1, 'top', 50 - ($rHeight / 2))
DllStructSetData($tRect1, 'right', 50 + ($rWidth / 2))
DllStructSetData($tRect1, 'bottom', 50 + ($rHeight / 2))
GUICtrlSetColor($gWin1, 0)
_WinAPI_DrawText($hDC1, $rInput1, $tRect1, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))
GetRect($gWin2)
;~  MsgBox(0, '', 'Links: ' & $rLinks & @CRLF & 'Rechts: ' & $rRechts & @CRLF & 'Oben: ' & $rOben & @CRLF & 'Unten: ' & $rUnten _
;~   & @CRLF & 'Breite: ' & $rWidth & @CRLF & 'Höhe: ' & $rHeight)
$tRect2 = DllStructCreate($tagRECT)
DllStructSetData($tRect2, 'left', 50 - ($rWidth / 2))
DllStructSetData($tRect2, 'top', 50 - ($rHeight / 2))
DllStructSetData($tRect2, 'right', 50 + ($rWidth / 2))
DllStructSetData($tRect2, 'bottom', 50 + ($rHeight / 2))
GUICtrlSetColor($gWin2, 0)
_WinAPI_DrawText($hDC2, $rInput2, $tRect2, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))

; DC wieder freigeben, Font löschen & von Strukturen reservierten Speicher freigeben.
_WinAPI_ReleaseDC(GUICtrlGetHandle($gWin1), $hDC1)
_WinAPI_ReleaseDC(GUICtrlGetHandle($gWin2), $hDC2)
_WinAPI_DeleteObject($hFont)
$tPoint1 = 0
$tPoint2 = 0
$tRect1 = 0
$tRect2 = 0
EndFunc   ;==>Drawing
Func GetRect($gWin)
;reelle Größe des Fonts messen
Local $aCoords[100][100]
For $iX = 0 To 99
  For $iY = 0 To 99
   $iPixelColor = PixelGetColor($iX, $iY, GUICtrlGetHandle($gWin))
   If Dec($iPixelColor) < Dec('999999') Then
    $rLinks = 100 - $iX
    ExitLoop
   EndIf
  Next
Next
For $iY = 0 To 99
  For $iX = 0 To 99
   $iPixelColor = PixelGetColor($iX, $iY, GUICtrlGetHandle($gWin))
   If Dec($iPixelColor) < Dec('999999') Then
    $rUnten = 100 - $iY
    ExitLoop
   EndIf
  Next
Next
For $iX = 99 To 0 Step -1
  For $iY = 99 To 0 Step -1
   $iPixelColor = PixelGetColor($iX, $iY, GUICtrlGetHandle($gWin))
   If Dec($iPixelColor) < Dec('999999') Then
    $rRechts = $iX
    ExitLoop
   EndIf
  Next
Next
For $iY = 99 To 0 Step -1
  For $iX = 99 To 0 Step -1
   $iPixelColor = PixelGetColor($iX, $iY, GUICtrlGetHandle($gWin))
   If Dec($iPixelColor) < Dec('999999') Then
    $rOben = $iY
    ExitLoop
   EndIf
  Next
Next
$rWidth = 100 - ($rRechts + $rLinks)
$rHeight = 100 - ($rOben + $rUnten)
Return
EndFunc   ;==>GetRect
Func cleanup()
;~ _GDIPlus_FontDispose($hFont)
;~ _GDIPlus_FontFamilyDispose($hFamily)
;~ _GDIPlus_StringFormatDispose($hFormat)
;~ _GDIPlus_BrushDispose($hBrush)
;~ _GDIPlus_GraphicsDispose($hGraphic)
;~ _GDIPlus_Shutdown()
EndFunc   ;==>cleanup
;Ende
cleanup()
Exit
Link to comment
Share on other sites

Hi again,

now I tried to calc new the "$tagRect"!! But it´s still not in the middle!?!

Its weird. its fine the first time it gets drawn, but then gets messed up after that. I don't get it... Ill keep looking. :)

Posted Image

And it takes too much time to create new "$tagRect", who knows a better way??

$tagRect is fine. Your GetRect() is whats so slow. I have no idea what your trying to do there but if I comment that out it at least starts becoming responsive. You need to have sleep() in your loops. Its way to hard on you cpu without.

#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <Fontconstants.au3>
#include <GDIPlus.au3>
#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListviewConstants.au3>
#include <ProgressConstants.au3>
;~ #include <RegFunc.au3>
#include <StaticConstants.au3>
#include <UpDownConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Opt("PixelCoordMode", 0)
;Data
$dString = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,ä,ö,ü'
$aString = StringSplit($dString, ',')
Local $data[3][$aString[0] + 1]
Local $rLinks, $rRechts, $rOben, $rUnten, $rWidth, $rHeight
For $i = 1 To $aString[0]
$data[0][$i] = $i
$data[1][$i] = StringUpper($aString[$i])
$data[2][$i] = StringLower($aString[$i])
Next
$cDataCount = 1 ;Letter Stellenzähler
$data[0][0] = (UBound($data, 2) - 1)
;Fonts
$FontList = _FileListToArray(@WindowsDir & 'Fonts', '*.ttf', 1);Schriftarten aus Windows Fonts Ordner holen
$var = _GetRegValues('HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionFonts');Schriftartennamen aus Windows Registry holen
Dim $aItems[($FontList[0] + 1)]
$x = 1
#region ### START Koda GUI section ### Form=C:UsersIBMDesktopAU3_OCR_newForm1.kxf
$msg = GUICreate("Form1", 620, 245, 215, 124)
$Datei = GUICtrlCreateMenu("&Datei")
$MenuItem1 = GUICtrlCreateMenuItem("Optionen" & @TAB & "", $Datei)
$MenuItem2 = GUICtrlCreateMenuItem("Exit" & @TAB & "", $Datei)
$Hilfe = GUICtrlCreateMenu("&Hilfe")
$listview = GUICtrlCreateListView("Nr.|Datei|Name", 277, 12, 335, 170)
$gWin1 = GUICtrlCreateGraphic(11, 66, 100, 100, $SS_WHITERECT)
$gWin2 = GUICtrlCreateGraphic(171, 66, 100, 100, $SS_WHITERECT)
$SchriftG = GUICtrlCreateInput('32', 123, 106, 35, 20)
$updwnSGR = GUICtrlCreateUpdown($SchriftG)
$bUp = GUICtrlCreateButton("Up", 123, 66, 35, 35, -1, $WS_EX_CLIENTEDGE)
$bDown = GUICtrlCreateButton("Dwn", 123, 131, 35, 35, -1, $WS_EX_CLIENTEDGE)
$bStart = GUICtrlCreateButton("Start", 26, 190, 80, 25, -1, $WS_EX_STATICEDGE)
$bAbbruch = GUICtrlCreateButton("Abbruch", 176, 190, 80, 25, -1, $WS_EX_STATICEDGE)
$bDaten = GUICtrlCreateButton("Alle Daten", 352, 188, 190, 30)
$Progress1 = GUICtrlCreateProgress(21, 172, 240, 10, -1, $WS_EX_STATICEDGE)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
_GUICtrlListView_SetColumnWidth($listview, 0, 28)
_GUICtrlListView_SetColumnWidth($listview, 1, 40)
_GUICtrlListView_SetColumnWidth($listview, 2, 180)
GUISetOnEvent($GUI_EVENT_CLOSE, 'SpecialEvents')
GUICtrlSetOnEvent($bStart, "button")
GUICtrlSetOnEvent($bUp, "UP")
GUICtrlSetOnEvent($bDown, "DOWN")
GUICtrlSetOnEvent($listview, "HandleClicks")
GUICtrlSetOnEvent($updwnSGR, "SchriftGR")
;GUI Liste schreiben
For $a = 1 To UBound($var)
If StringRight($var[$a - 1][2], 3) = 'ttf' Then
  If StringInStr($var[$a - 1][0], 'Bold', 1) = False And StringInStr($var[$a - 1][0], 'Italic', 1) = False _
    And StringInStr($var[$a - 1][0], 'MT Extra', 1) = False Then
   $nName = StringReplace($var[$a - 1][0], '(TrueType)', '', 1)
   $aItems[$x] = GUICtrlCreateListViewItem($x & '|' & $var[$a - 1][2] & '|' & $nName, $listview)
   GUICtrlSetOnEvent($aItems[$x], "HandleClicks")
   $x = $x + 1
  EndIf
EndIf
Next
_GUICtrlListView_SetSelectionMark($listview, 0)
$sTrim = _GUICtrlListView_GetSelectionMark($listview)
;~ _GUICtrlListView_ClickItem($listview, 0, "left", False, 1)
While 1
$rAktList = GUICtrlRead($listview)
$sgr = GUICtrlRead($SchriftG)
Sleep(100)
WEnd
;Funktionen
;SpecialEvents
Func SpecialEvents()
Select
  Case @GUI_CtrlId = $GUI_EVENT_CLOSE
   cleanup()
   _GDIPlus_Shutdown()
   Exit
EndSelect
EndFunc   ;==>SpecialEvents
Func HandleClicks()
$aktSel = GUICtrlRead(GUICtrlRead($listview))
$aList = StringSplit($aktSel, '|')
$sTrim = StringTrimRight($aList[3], 1)
;_ArrayDisplay($aList)
Drawing()
EndFunc   ;==>HandleClicks
Func button()
;$rInput1 = GUICtrlRead($iLetter)
MsgBox(0, 'Schriftart', GUICtrlRead(GUICtrlRead($listview)), 2)
Drawing()
EndFunc   ;==>button
Func UP()
If $cDataCount < $aString[0] Then
  $cDataCount = $cDataCount + 1
EndIf
Drawing()
EndFunc   ;==>UP
Func DOWN()
If $cDataCount >= 2 Then
  $cDataCount = $cDataCount - 1
EndIf
Drawing()
EndFunc   ;==>DOWN
Func SchriftGR()
$sgr = GUICtrlRead($SchriftG)
If $sgr <= 8 Then
  GUICtrlSetData($SchriftG, 8)
EndIf
If $sgr >= 99 Then
  GUICtrlSetData($SchriftG, 99)
EndIf
Drawing()
EndFunc   ;==>SchriftGR
Func Drawing()
Local $iRectWidth, $iRectHeight, $aCtrlPos1
GUICtrlSetColor($gWin1, 0)
GUICtrlSetColor($gWin2, 0)
$rInput = $aString[$cDataCount]
$rInput1 = StringUpper($rInput)
$rInput2 = StringLower($rInput)
$sgr = GUICtrlRead($SchriftG)
; Größe des Graphic-Controls ermitteln (Noch 100x100, aber wer weiß, wann sich das ändert)
$aCtrlPos1 = ControlGetPos($msg, '', $gWin1)
$aCtrlPos2 = ControlGetPos($msg, '', $gWin2)
$iRectWidth = $aCtrlPos1[2]
$iRectHeight = $aCtrlPos1[3]
; DC vom Graphics-Control holen
$hDC1 = _WinAPI_GetDC(GUICtrlGetHandle($gWin1))
$hDC2 = _WinAPI_GetDC(GUICtrlGetHandle($gWin2))
; Font erstellen
;$iDeviceCapY = _WinAPI_GetDeviceCaps($hDC1, $__WINAPICONSTANT_LOGPIXELSX)
;MsgBox(0, '', $iDeviceCapY)
$hFont = _WinAPI_CreateFont($sgr, 0, 0, 0, $FW_NORMAL, False, False, False _
   , $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, $sTrim)
; Font mit DC verbinden
_WinAPI_SelectObject($hDC1, $hFont)
_WinAPI_SelectObject($hDC2, $hFont)
;Font zeichnen
$tPoint1 = _WinAPI_GetTextExtentPoint32($hDC1, $rInput1)
$tPoint2 = _WinAPI_GetTextExtentPoint32($hDC2, $rInput2)
$tRect = DllStructCreate($tagRECT)
;~  $tRect1 = _WinAPI_DrawText($hDC1, $rInput1, $tRect, $DT_CALCRECT)
;~  $tRect2 = _WinAPI_DrawText($hDC1, $rInput1, $tRect, $DT_CALCRECT)
DllStructSetData($tRect, 'left', ($iRectWidth / 2) - (DllStructGetData($tPoint1, 'x') / 2))
DllStructSetData($tRect, 'top', ($iRectHeight / 2) - (DllStructGetData($tPoint1, 'y') / 2))
DllStructSetData($tRect, 'right', DllStructGetData($tRect, 'left') + DllStructGetData($tPoint1, 'x'))
DllStructSetData($tRect, 'bottom', DllStructGetData($tRect, 'top') + DllStructGetData($tPoint1, 'y'))
; Text auf Graphics-Control zeichnen
_WinAPI_DrawText($hDC1, $rInput1, $tRect, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))
_WinAPI_DrawText($hDC2, $rInput2, $tRect, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))
;~  GetRect($gWin1)
;~  MsgBox(0, '', 'Links: ' & $rLinks & @CRLF & 'Rechts: ' & $rRechts & @CRLF & 'Oben: ' & $rOben & @CRLF & 'Unten: ' & $rUnten _
;~   & @CRLF & 'Breite: ' & $rWidth & @CRLF & 'Höhe: ' & $rHeight)
;~
$tRect1 = DllStructCreate($tagRECT)
DllStructSetData($tRect1, 'left', 50 - ($rWidth / 2))
DllStructSetData($tRect1, 'top', 50 - ($rHeight / 2))
DllStructSetData($tRect1, 'right', 50 + ($rWidth / 2))
DllStructSetData($tRect1, 'bottom', 50 + ($rHeight / 2))
GUICtrlSetColor($gWin1, 0)
_WinAPI_DrawText($hDC1, $rInput1, $tRect1, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))
;~  GetRect($gWin2)
;~  MsgBox(0, '', 'Links: ' & $rLinks & @CRLF & 'Rechts: ' & $rRechts & @CRLF & 'Oben: ' & $rOben & @CRLF & 'Unten: ' & $rUnten _
;~   & @CRLF & 'Breite: ' & $rWidth & @CRLF & 'Höhe: ' & $rHeight)
$tRect2 = DllStructCreate($tagRECT)
DllStructSetData($tRect2, 'left', 50 - ($rWidth / 2))
DllStructSetData($tRect2, 'top', 50 - ($rHeight / 2))
DllStructSetData($tRect2, 'right', 50 + ($rWidth / 2))
DllStructSetData($tRect2, 'bottom', 50 + ($rHeight / 2))
GUICtrlSetColor($gWin2, 0)
_WinAPI_DrawText($hDC2, $rInput2, $tRect2, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))
; DC wieder freigeben, Font löschen & von Strukturen reservierten Speicher freigeben.
_WinAPI_ReleaseDC(GUICtrlGetHandle($gWin1), $hDC1)
_WinAPI_ReleaseDC(GUICtrlGetHandle($gWin2), $hDC2)
_WinAPI_DeleteObject($hFont)
$tPoint1 = 0
$tPoint2 = 0
$tRect1 = 0
$tRect2 = 0
EndFunc   ;==>Drawing
Func GetRect($gWin)
;reelle Größe des Fonts messen
Local $aCoords[100][100]
For $iX = 0 To 99
  For $iY = 0 To 99
   $iPixelColor = PixelGetColor($iX, $iY, GUICtrlGetHandle($gWin))
   If Dec($iPixelColor) < Dec('999999') Then
    $rLinks = 100 - $iX
    ExitLoop
   EndIf
  Next
Next
ConsoleWrite(@ScriptLineNumber & @LF)
For $iY = 0 To 99
  For $iX = 0 To 99
   $iPixelColor = PixelGetColor($iX, $iY, GUICtrlGetHandle($gWin))
   If Dec($iPixelColor) < Dec('999999') Then
    $rUnten = 100 - $iY
    ExitLoop
   EndIf
  Next
Next
For $iX = 99 To 0 Step -1
  For $iY = 99 To 0 Step -1
   $iPixelColor = PixelGetColor($iX, $iY, GUICtrlGetHandle($gWin))
   If Dec($iPixelColor) < Dec('999999') Then
    $rRechts = $iX
    ExitLoop
   EndIf
  Next
Next
For $iY = 99 To 0 Step -1
  For $iX = 99 To 0 Step -1
   $iPixelColor = PixelGetColor($iX, $iY, GUICtrlGetHandle($gWin))
   If Dec($iPixelColor) < Dec('999999') Then
    $rOben = $iY
    ExitLoop
   EndIf
  Next
Next
$rWidth = 100 - ($rRechts + $rLinks)
$rHeight = 100 - ($rOben + $rUnten)
Return
EndFunc   ;==>GetRect
Func cleanup()
;~ _GDIPlus_FontDispose($hFont)
;~ _GDIPlus_FontFamilyDispose($hFamily)
;~ _GDIPlus_StringFormatDispose($hFormat)
;~ _GDIPlus_BrushDispose($hBrush)
;~ _GDIPlus_GraphicsDispose($hGraphic)
EndFunc   ;==>cleanup
;Ende

;========================================================================================
; Function Name:   _GetRegSubKeys($HKEY)
; Description:   Ermittelt die Unterschlüssel für den übergebenen Schlüssel
; Parameter(s): $HKEY   der Registryschlüssel
; Return Value(s): Erfolg  Array mit den Unterschlüsseln
;                Fehler  Leerstring (keine Unterschlüssel vorhanden oder Schlüssel existiert nicht)
; Author(s):       BugFix (bugfix@autoit.de)
;========================================================================================
Func _GetRegSubKeys($HKEY)
If StringInStr($HKEY, '') Then
  If StringRight($HKEY, 1) = '' Then
   $HKEY = StringTrimRight($HKEY, 1)
   Local $strKeyPath = ''
  Else
   Local $strKeyPath = StringRight($HKEY, StringLen($HKEY) - StringInStr($HKEY, ''))
   $HKEY = StringLeft($HKEY, StringInStr($HKEY, '') - 1)
  EndIf
Else
  Local $strKeyPath = ''
EndIf
Select
  Case $HKEY = "HKEY_LOCAL_MACHINE" Or $HKEY = "HKLM"
   $HKEY = 0x80000002
  Case $HKEY = "HKEY_USERS" Or $HKEY = "HKU"
   $HKEY = 0x80000003
  Case $HKEY = "HKEY_CURRENT_USER" Or $HKEY = "HKCU"
   $HKEY = 0x80000001
  Case $HKEY = "HKEY_CLASSES_ROOT" Or $HKEY = "HKCR"
   $HKEY = 0x80000000
  Case $HKEY = "HKEY_CURRENT_CONFIG" Or $HKEY = "HKCC"
   $HKEY = 0x80000005
EndSelect
Local $arrSubKeys = '', $subkey
Local $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!.rootdefault:StdRegProv")
$oReg.EnumKey($HKEY, $strKeyPath, $arrSubKeys)
Return $arrSubKeys
EndFunc   ;==>_GetRegSubKeys
;========================================================================================
; Function Name:   _GetRegRights($HKEY)
; Description:   Ermittelt die Rechte des Abfragenden für den übergebenen Schlüssel
; Parameter(s): $HKEY   der zu prüfende Registryschlüssel
; Return Value(s): String mit Auflistung der Rechte:
;                Q  Key Query Value
;                S  Key Set Value
;                C  Key Create Sub Key
;                D  Delete
; Author(s):       BugFix (bugfix@autoit.de)
;========================================================================================
Func _GetRegRights($HKEY)
Local $bHasAccessRight, $sRights = ''
If StringInStr($HKEY, '') Then
  If StringRight($HKEY, 1) = '' Then
   $HKEY = StringTrimRight($HKEY, 1)
   Local $strKeyPath = ''
  Else
   Local $strKeyPath = StringRight($HKEY, StringLen($HKEY) - StringInStr($HKEY, ''))
   $HKEY = StringLeft($HKEY, StringInStr($HKEY, '') - 1)
  EndIf
Else
  Local $strKeyPath = ''
EndIf
Select
  Case $HKEY = "HKEY_LOCAL_MACHINE" Or $HKEY = "HKLM"
   $HKEY = 0x80000002
  Case $HKEY = "HKEY_USERS" Or $HKEY = "HKU"
   $HKEY = 0x80000003
  Case $HKEY = "HKEY_CURRENT_USER" Or $HKEY = "HKCU"
   $HKEY = 0x80000001
  Case $HKEY = "HKEY_CLASSES_ROOT" Or $HKEY = "HKCR"
   $HKEY = 0x80000000
  Case $HKEY = "HKEY_CURRENT_CONFIG" Or $HKEY = "HKCC"
   $HKEY = 0x80000005
EndSelect
Local $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!.rootdefault:StdRegProv")
$oReg.CheckAccess($HKEY, $strKeyPath, 0x0001, $bHasAccessRight)
If $bHasAccessRight = True Then $sRights &= 'Q'
$oReg.CheckAccess($HKEY, $strKeyPath, 0x0002, $bHasAccessRight)
If $bHasAccessRight = True Then $sRights &= 'S'
$oReg.CheckAccess($HKEY, $strKeyPath, 0x0004, $bHasAccessRight)
If $bHasAccessRight = True Then $sRights &= 'C'
$oReg.CheckAccess($HKEY, $strKeyPath, 0x00010000, $bHasAccessRight)
If $bHasAccessRight = True Then $sRights &= 'D'
Return $sRights
EndFunc   ;==>_GetRegRights
;========================================================================================
; Function Name:    _GetRegValues($HKEY)
; Description:   Ermittelt alle Namen, Typen und Werte in einem gegebenen Schlüssel
; Parameter(s): $HKEY   der Registryschlüssel
; Return Value(s): Erfolg  Array[i][0] = Name
;                        Array[i][1] = Typ
;                        Array[i][2] = Wert
;                Fehler  Leerstring (Schlüssel existiert nicht oder ist ohne Einträge)
; Author(s):       BugFix (bugfix@autoit.de)
;========================================================================================
Func _GetRegValues($HKEY)
Local $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
If StringInStr($HKEY, '') Then
  If StringRight($HKEY, 1) = '' Then
   $HKEY = StringTrimRight($HKEY, 1)
   Local $strKeyPath = ''
  Else
   Local $strKeyPath = StringRight($HKEY, StringLen($HKEY) - StringInStr($HKEY, ''))
   $HKEY = StringLeft($HKEY, StringInStr($HKEY, '') - 1)
  EndIf
Else
  Local $strKeyPath = ''
EndIf
Select
  Case $HKEY = "HKEY_LOCAL_MACHINE" Or $HKEY = "HKLM"
   $HKEY = 0x80000002
  Case $HKEY = "HKEY_USERS" Or $HKEY = "HKU"
   $HKEY = 0x80000003
  Case $HKEY = "HKEY_CURRENT_USER" Or $HKEY = "HKCU"
   $HKEY = 0x80000001
  Case $HKEY = "HKEY_CLASSES_ROOT" Or $HKEY = "HKCR"
   $HKEY = 0x80000000
  Case $HKEY = "HKEY_CURRENT_CONFIG" Or $HKEY = "HKCC"
   $HKEY = 0x80000005
EndSelect
Local $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!.rootdefault:StdRegProv")
Local $arrValueNames, $arrValueTypes, $strValue
$oReg.EnumValues($HKEY, $strKeyPath, $arrValueNames, $arrValueTypes)
$OEvent = ObjEvent($oReg, "EnumValues")
If Not IsArray($arrValueNames) Then Return ''
Local $arOut[UBound($arrValueNames)][3]
For $i = 0 To UBound($arrValueNames) - 1
  $arOut[$i][0] = $arrValueNames[$i]
  Switch $arrValueTypes[$i]
   Case 1
    $arOut[$i][1] = 'REG_SZ'
    $oReg.GetStringValue($HKEY, $strKeyPath, $arrValueNames[$i], $strValue)
   Case 2
    $arOut[$i][1] = 'REG_EXPAND_SZ'
    $oReg.GetExpandedStringValue($HKEY, $strKeyPath, $arrValueNames[$i], $strValue)
   Case 3
    $arOut[$i][1] = 'REG_BINARY'
    $oReg.GetBinaryValue($HKEY, $strKeyPath, $arrValueNames[$i], $strValue)
   Case 4
    $arOut[$i][1] = 'REG_DWORD'
    $oReg.GetStringValue($HKEY, $strKeyPath, $arrValueNames[$i], $strValue)
   Case 7
    $arOut[$i][1] = 'REG_MULTI_SZ'
    $oReg.GetMultiStringValue($HKEY, $strKeyPath, $arrValueNames[$i], $strValue)
  EndSwitch
  $arOut[$i][2] = $strValue
Next
Return $arOut
EndFunc   ;==>_GetRegValues
Func MyErrFunc()
Return
EndFunc   ;==>MyErrFunc
Edited by Beege
Link to comment
Share on other sites

Why are you drawing the same letters twice? The second draw is whats out of alignment. I put a big sleep() in between so you can see it happen.

Func Drawing()
Local $iRectWidth, $iRectHeight, $aCtrlPos1
GUICtrlSetColor($gWin1, 0)
GUICtrlSetColor($gWin2, 0)
$rInput = $aString[$cDataCount]
$rInput1 = StringUpper($rInput)
$rInput2 = StringLower($rInput)
$sgr = GUICtrlRead($SchriftG)
; Größe des Graphic-Controls ermitteln (Noch 100x100, aber wer weiß, wann sich das ändert)
$aCtrlPos1 = ControlGetPos($msg, '', $gWin1)
$aCtrlPos2 = ControlGetPos($msg, '', $gWin2)
$iRectWidth = $aCtrlPos1[2]
$iRectHeight = $aCtrlPos1[3]
; DC vom Graphics-Control holen
$hDC1 = _WinAPI_GetDC(GUICtrlGetHandle($gWin1))
$hDC2 = _WinAPI_GetDC(GUICtrlGetHandle($gWin2))
; Font erstellen
;$iDeviceCapY = _WinAPI_GetDeviceCaps($hDC1, $__WINAPICONSTANT_LOGPIXELSX)
;MsgBox(0, '', $iDeviceCapY)
$hFont = _WinAPI_CreateFont($sgr, 0, 0, 0, $FW_NORMAL, False, False, False _
   , $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, $sTrim)
; Font mit DC verbinden
_WinAPI_SelectObject($hDC1, $hFont)
_WinAPI_SelectObject($hDC2, $hFont)
;Font zeichnen
$tPoint1 = _WinAPI_GetTextExtentPoint32($hDC1, $rInput1)
$tPoint2 = _WinAPI_GetTextExtentPoint32($hDC2, $rInput2)
;~  $gWin1 = GUICtrlCreateGraphic(11, 66, 100, 100, $SS_WHITERECT)
;~  $gWin2 = GUICtrlCreateGraphic(171, 66, 100, 100, $SS_WHITERECT)
$tRect = DllStructCreate($tagRECT)
;~  $tRect1 = _WinAPI_DrawText($hDC1, $rInput1, $tRect, $DT_CALCRECT)
;~  $tRect2 = _WinAPI_DrawText($hDC1, $rInput1, $tRect, $DT_CALCRECT)
DllStructSetData($tRect, 'left', ($iRectWidth / 2) - (DllStructGetData($tPoint1, 'x') / 2))
DllStructSetData($tRect, 'top', ($iRectHeight / 2) - (DllStructGetData($tPoint1, 'y') / 2))
DllStructSetData($tRect, 'right', DllStructGetData($tRect, 'left') + DllStructGetData($tPoint1, 'x'))
DllStructSetData($tRect, 'bottom', DllStructGetData($tRect, 'top') + DllStructGetData($tPoint1, 'y'))
; Text auf Graphics-Control zeichnen
_WinAPI_DrawText($hDC1, $rInput1, $tRect, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))
_WinAPI_DrawText($hDC2, $rInput2, $tRect, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))
;~  GetRect($gWin1)
;~  MsgBox(0, '', 'Links: ' & $rLinks & @CRLF & 'Rechts: ' & $rRechts & @CRLF & 'Oben: ' & $rOben & @CRLF & 'Unten: ' & $rUnten _
;~   & @CRLF & 'Breite: ' & $rWidth & @CRLF & 'Höhe: ' & $rHeight)
;~

Sleep(2000)


$tRect1 = DllStructCreate($tagRECT)
DllStructSetData($tRect1, 'left', 50 - ($rWidth / 2))
DllStructSetData($tRect1, 'top', 50 - ($rHeight / 2))
DllStructSetData($tRect1, 'right', 50 + ($rWidth / 2))
DllStructSetData($tRect1, 'bottom', 50 + ($rHeight / 2))
GUICtrlSetColor($gWin1, 0)
_WinAPI_DrawText($hDC1, $rInput1, $tRect1, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))
;~  GetRect($gWin2)
;~  MsgBox(0, '', 'Links: ' & $rLinks & @CRLF & 'Rechts: ' & $rRechts & @CRLF & 'Oben: ' & $rOben & @CRLF & 'Unten: ' & $rUnten _
;~   & @CRLF & 'Breite: ' & $rWidth & @CRLF & 'Höhe: ' & $rHeight)
$tRect2 = DllStructCreate($tagRECT)
DllStructSetData($tRect2, 'left', 50 - ($rWidth / 2))
DllStructSetData($tRect2, 'top', 50 - ($rHeight / 2))
DllStructSetData($tRect2, 'right', 50 + ($rWidth / 2))
DllStructSetData($tRect2, 'bottom', 50 + ($rHeight / 2))
GUICtrlSetColor($gWin2, 0)
_WinAPI_DrawText($hDC2, $rInput2, $tRect2, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))
; DC wieder freigeben, Font löschen & von Strukturen reservierten Speicher freigeben.
_WinAPI_ReleaseDC(GUICtrlGetHandle($gWin1), $hDC1)
_WinAPI_ReleaseDC(GUICtrlGetHandle($gWin2), $hDC2)
_WinAPI_DeleteObject($hFont)

EndFunc   ;==>Drawing
Link to comment
Share on other sites

..but I think all my "GetRect()" is crap, ´cause it´s not working as it should!

I agree. What is it suppose to be doing? And why were you drawing the letters twice?

But If I´d have the right "$tagRects" for everys font size ... I could save it to an .ini!

I'm not positive but screen resolution could end up playing a factor on $tagRect values. Keep that in mind before trying to save all the values if you plan to run the app on other pcs.
Link to comment
Share on other sites

Hi!

In another Forum I got posted that "GetTextMetrics" and "GetGlyphOutline" should be the key, but with that I get the letters in the exact middle but they were cut by "$tagRect"!!

Some at the right and other at the bottom. Especially at Fonts wich have "Italic" design.

.....
$tPoint1 = _WinAPI_GetTextExtentPoint32($hDC1, $rInput1)
    $tPoint2 = _WinAPI_GetTextExtentPoint32($hDC2, $rInput2)
    $aBB1 = _CharGetBlackBox($hDC1, $rInput1)
    $aBB2 = _CharGetBlackBox($hDC2, $rInput2)
    $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, 'left', ($iRectWidth / 2) - $aBB1[0] - ($aBB1[2] / 2))
    DllStructSetData($tRect, 'top', ($iRectHeight / 2) - $aBB1[1] - ($aBB1[3] / 2))
    DllStructSetData($tRect, 'right', DllStructGetData($tRect, 'left') + DllStructGetData($tPoint1, 'x'))
    DllStructSetData($tRect, 'bottom', DllStructGetData($tRect, 'top') + DllStructGetData($tPoint1, 'y'))
    _WinAPI_DrawText($hDC1, $rInput1, $tRect, BitOR($DT_VCENTER, $DT_CENTER))
    DllStructSetData($tRect, 'left', ($iRectWidth / 2) - $aBB2[0] - ($aBB2[2] / 2))
    DllStructSetData($tRect, 'top', ($iRectHeight / 2) - $aBB2[1] - ($aBB2[3] / 2))
    DllStructSetData($tRect, 'right', DllStructGetData($tRect, 'left') + DllStructGetData($tPoint2, 'x'))
    DllStructSetData($tRect, 'bottom', DllStructGetData($tRect, 'top') + DllStructGetData($tPoint2, 'y'))
    _WinAPI_DrawText($hDC2, $rInput2, $tRect, BitOR($DT_VCENTER, $DT_CENTER))
.....
Func _CharGetBlackBox($hDC, $sChar)
    Local $tTEXTMETRIC = DllStructCreate($tagTEXTMETRIC)
    DllCall("gdi32.dll", "bool", "GetTextMetricsW", "handle", $hDC, "ptr", DllStructGetPtr($tTEXTMETRIC))
    Local $tGLYPHMETRICS = DllStructCreate("UINT gmBlackBoxX; UINT gmBlackBoxY; Long OriginX; Long OriginY; SHORT gmCellIncX; SHORT gmCellIncY;")
    Local $tMatrix = DllStructCreate("SHORT[8];")
    DllStructSetData($tMatrix, 1, 1, 2)
    DllStructSetData($tMatrix, 1, 1, 8)
    DllCall('gdi32.dll', "INT", "GetGlyphOutline", "HWND", $hDC, "UINT", Asc($sChar), "UINT", "GGO_METRICS", "PTR", DllStructGetPtr($tGLYPHMETRICS), "UINT", 0, "PTR", 0, "PTR", DllStructGetPtr($tMatrix))
    Local $aReturn[4]
    $aReturn[0] = DllStructGetData($tGLYPHMETRICS, "OriginX")
    $aReturn[1] = DllStructGetData($tTEXTMETRIC, "tmAscent") - DllStructGetData($tGLYPHMETRICS, "OriginY")
    $aReturn[2] = DllStructGetData($tGLYPHMETRICS, "gmBlackBoxX")
    $aReturn[3] = DllStructGetData($tGLYPHMETRICS, "gmBlackBoxY")
    Return $aReturn
EndFunc   ;==>_CharGetBlackBox
Can´t "$tagRecht" be calculated by differ Pixel color???
Link to comment
Share on other sites

Hi!

In another Forum I got posted that "GetTextMetrics" and "GetGlyphOutline" should be the key, but with that I get the letters in the exact middle but they were cut by "$tagRect"!!

Some at the right and other at the bottom. Especially at Fonts wich have "Italic" design.

.....
$tPoint1 = _WinAPI_GetTextExtentPoint32($hDC1, $rInput1)
    $tPoint2 = _WinAPI_GetTextExtentPoint32($hDC2, $rInput2)
    $aBB1 = _CharGetBlackBox($hDC1, $rInput1)
    $aBB2 = _CharGetBlackBox($hDC2, $rInput2)
    $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, 'left', ($iRectWidth / 2) - $aBB1[0] - ($aBB1[2] / 2))
    DllStructSetData($tRect, 'top', ($iRectHeight / 2) - $aBB1[1] - ($aBB1[3] / 2))
    DllStructSetData($tRect, 'right', DllStructGetData($tRect, 'left') + DllStructGetData($tPoint1, 'x'))
    DllStructSetData($tRect, 'bottom', DllStructGetData($tRect, 'top') + DllStructGetData($tPoint1, 'y'))
    _WinAPI_DrawText($hDC1, $rInput1, $tRect, BitOR($DT_VCENTER, $DT_CENTER))
    DllStructSetData($tRect, 'left', ($iRectWidth / 2) - $aBB2[0] - ($aBB2[2] / 2))
    DllStructSetData($tRect, 'top', ($iRectHeight / 2) - $aBB2[1] - ($aBB2[3] / 2))
    DllStructSetData($tRect, 'right', DllStructGetData($tRect, 'left') + DllStructGetData($tPoint2, 'x'))
    DllStructSetData($tRect, 'bottom', DllStructGetData($tRect, 'top') + DllStructGetData($tPoint2, 'y'))
    _WinAPI_DrawText($hDC2, $rInput2, $tRect, BitOR($DT_VCENTER, $DT_CENTER))
.....
Func _CharGetBlackBox($hDC, $sChar)
    Local $tTEXTMETRIC = DllStructCreate($tagTEXTMETRIC)
    DllCall("gdi32.dll", "bool", "GetTextMetricsW", "handle", $hDC, "ptr", DllStructGetPtr($tTEXTMETRIC))
    Local $tGLYPHMETRICS = DllStructCreate("UINT gmBlackBoxX; UINT gmBlackBoxY; Long OriginX; Long OriginY; SHORT gmCellIncX; SHORT gmCellIncY;")
    Local $tMatrix = DllStructCreate("SHORT[8];")
    DllStructSetData($tMatrix, 1, 1, 2)
    DllStructSetData($tMatrix, 1, 1, 8)
    DllCall('gdi32.dll', "INT", "GetGlyphOutline", "HWND", $hDC, "UINT", Asc($sChar), "UINT", "GGO_METRICS", "PTR", DllStructGetPtr($tGLYPHMETRICS), "UINT", 0, "PTR", 0, "PTR", DllStructGetPtr($tMatrix))
    Local $aReturn[4]
    $aReturn[0] = DllStructGetData($tGLYPHMETRICS, "OriginX")
    $aReturn[1] = DllStructGetData($tTEXTMETRIC, "tmAscent") - DllStructGetData($tGLYPHMETRICS, "OriginY")
    $aReturn[2] = DllStructGetData($tGLYPHMETRICS, "gmBlackBoxX")
    $aReturn[3] = DllStructGetData($tGLYPHMETRICS, "gmBlackBoxY")
    Return $aReturn
EndFunc   ;==>_CharGetBlackBox
Can´t "$tagRecht" be calculated by differ Pixel color???

example: "vladimir.ttf" & "kunstler.ttf"
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...