Skip to content

Instantly share code, notes, and snippets.

@tmplinshi
Created May 14, 2015 07:48
Show Gist options
  • Select an option

  • Save tmplinshi/f6002b214ee284897303 to your computer and use it in GitHub Desktop.

Select an option

Save tmplinshi/f6002b214ee284897303 to your computer and use it in GitHub Desktop.
; by just me, http://ahkscript.org/boards/viewtopic.php?f=5&t=4673#p44099
Edit_VCENTER(HEDIT) { ; The Edit control must have the ES_MULTILINE style (0x0004 \ +Multi)!
; EM_GETRECT := 0x00B2 <- msdn.microsoft.com/en-us/library/bb761596(v=vs.85).aspx
; EM_SETRECT := 0x00B3 <- msdn.microsoft.com/en-us/library/bb761657(v=vs.85).aspx
VarSetCapacity(RC, 16, 0)
DllCall("User32.dll\GetClientRect", "Ptr", HEDIT, "Ptr", &RC)
CLHeight := NumGet(RC, 12, "Int")
SendMessage, 0x0031, 0, 0, , ahk_id %HEDIT% ; WM_GETFONT
HFONT := ErrorLevel
HDC := DllCall("GetDC", "Ptr", HEDIT, "UPtr")
DllCall("SelectObject", "Ptr", HDC, "Ptr", HFONT)
VarSetCapacity(RC, 16, 0)
DTH := DllCall("DrawText", "Ptr", HDC, "Str", "W", "Int", 1, "Ptr", &RC, "UInt", 0x2400)
DllCall("ReleaseDC", "Ptr", HEDIT, "Ptr", HDC)
SendMessage, 0x00BA, 0, 0, , ahk_id %HEDIT% ; EM_GETLINECOUNT
TXHeight := DTH * ErrorLevel
If (TXHeight > CLHeight)
Return False
VarSetCapacity(RC, 16, 0)
SendMessage, 0x00B2, 0, &RC, , ahk_id %HEDIT%
DY := (CLHeight - TXHeight) // 2
NumPut(DY, RC, 4, "Int")
NumPut(TXHeight + DY, RC, 12, "Int")
SendMessage, 0x00B3, 0, &RC, , ahk_id %HEDIT%
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment