Hi,
ich will eine GUI mit einem einzigen Editfeld.
Dieses soll immer so groß sein wie die GUI.
Wird beim schreiben eine neue Zeile erreicht, soll sich die GUI samt Editfeld vergrößern.
Wird eine Zeile gelöscht so soll sich alles verkleinern.
Es funktioniert eigentlich ganz gut, jedoch wie bekomme ich das Edit genau passend in die GUI?
Spoiler anzeigen
#region ;************ Includes ************
#include <Constants.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#endregion ;************ Includes ************
;allgemeine Deklarierung (Notizen)
Global $hProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
Global $hMod = _WinAPI_GetModuleHandle(0)
Global $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hProc), $hMod)
;AutoItSetOption
Opt("GUICloseOnESC", 0) ;1=ESC beendet, 0=ESC schließt nicht
Opt('GUIOnEventMode', 1)
Global $iHoehe_beginn = 200
[/autoit] [autoit][/autoit] [autoit]Global $hGui = GUICreate("Notiz", 200, $iHoehe_beginn, -1, -1, $WS_SIZEBOX, $WS_EX_TOOLWINDOW)
Global $idEdit = GUICtrlCreateEdit("", 0, 0, 200, $iHoehe_beginn, BitOR($ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
Global $hEdit = GUICtrlGetHandle($idEdit)
Global $iFontHeight = _GetFontHeight($hEdit)
Global $iEditH = $iFontHeight * 2
_CalcEditSize()
GUISetState()
[/autoit] [autoit][/autoit] [autoit]GUISetOnEvent($GUI_EVENT_CLOSE, "_beenden")
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func _GetFontHeight($hWnd)
Local $hDC = _WinAPI_GetDC($hEdit)
Local $tTEXTMETRIC = DllStructCreate($tagTEXTMETRIC)
DllCall("gdi32.dll", "bool", "GetTextMetricsW", "handle", $hDC, "ptr", DllStructGetPtr($tTEXTMETRIC))
_WinAPI_ReleaseDC($hEdit, $hDC)
Return DllStructGetData($tTEXTMETRIC, "tmAscent")
EndFunc ;==>_GetFontHeight
Func _CalcEditSize()
Local $aPos_fenster
$aPos_fenster = WinGetPos($hGui)
Local $iCnt = _GUICtrlEdit_GetLineCount($hEdit)
$iEditH = $iCnt * $iFontHeight
If $iEditH + 50 > $iHoehe_beginn Then
WinMove($hGui, "", $aPos_fenster[0], $aPos_fenster[1], $aPos_fenster[2], $iEditH + $iFontHeight + 50)
EndIf
EndFunc ;==>_CalcEditSize
Func _KeyProc($nCode, $wParam, $lParam)
Local $aPos_fenster
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
;~ Local $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
If $wParam = $WM_KEYDOWN Then
If ($iEditH + $iFontHeight * 2 + 50) > $iHoehe_beginn Then
$aPos_fenster = WinGetPos($hGui)
_WinAPI_SetWindowPos(_WinAPI_GetFocus(), 0, 0, 0, $aPos_fenster[2], $iEditH + $iFontHeight * 2, $SWP_NOZORDER)
EndIf
EndIf
_CalcEditSize()
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc ;==>_KeyProc
While 1
Sleep(10)
WEnd
Func _beenden()
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hProc)
Exit
EndFunc ;==>_beenden
EDIT: Habs ein bisschen optimiert, aber immer noch nicht gut genug ![]()