#NoEnv String := "你好`n世界" Gui, Font, S20 Gui, Add, Edit, -VScroll -E0x200 hwndHEdit1 w200 r3 Center, %String% Gui, Add, Edit, -VScroll -E0x200 hwndHEdit2 w200 r3 Center, %String% Gui, Show, , Gui Edit_VCENTER(HEdit2) Return GuiClose: ExitApp 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% }
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)