See attached image. The text is aligned to the top, with large padding at the bottom.
Code: Select all
Gui, Font, S20
Gui, Add, Edit, x10 y10 w200 h60 -Multi, Data
Gui, Show, w220 h80, Gui Test
Code: Select all
Gui, Font, S20
Gui, Add, Edit, x10 y10 w200 h60 -Multi, Data
Gui, Show, w220 h80, Gui Test
Code: Select all
; ===================================================================================
; NAME .........: NEW INTERFACE
; DESCRIPTION ..: INTERFACE USING A BACKGROUND IMAGE.
; AHK VERSION ..: AHK_L 1.1.16.04 (UNICODE 32-BIT) - SEPTEMBER 16, 2014
; PLATFORM .....: WINDOWS 7 PROFESSIONAL SP1 32-BIT
; LANGUAGE .....: ENGLISH (EN-US)
; ===================================================================================
; GLOBAL ============================================================================
#SingleInstance Force ; ALLOWS ONLY ONE RUNNING INSTANCE OF SCRIPT.
#Persistent ; KEEPS SCRIPT PERMANENTLY RUNNING UNTIL TERMINATED.
#NoEnv ; AVOIDS CHECKING EMPTY VARIABLES TO SEE IF THEY ARE ENVIRONMENT VARIABLES.
#Warn ; ENABLES WARNINGS TO ASSIST WITH DETECTING COMMON ERRORS.
SendMode Input ; RECOMMENDED FOR NEW SCRIPTS DUE TO ITS SUPERIOR SPEED AND RELIABILITY.
SetWorkingDir %A_ScriptDir% ; ENSURES A CONSISTENT STARTING DIRECTORY.
SetBatchLines, -1 ; RUNS SCRIPT AT MAXIMUM SPEED. NEVER SLEEPS.
;#NoTrayIcon ; DISABLES THE SHOWING OF A TRAY ICON.
;Menu, Tray, Icon, Shell32.dll, 174 ; REPLACES THE DEFAULT TRAY ICON.
Gui, Add, Picture, x0 y0 w600 h600, Form.png ; Background Image
Gui, Add, Edit, x0 y0 w0 h0 -E0x200 +ReadOnly, Focus ; Initial Focus
Gui, Font, S18 C666666 ; Set Font Options
Gui, Add, Edit, x32 y132 w119 h35 -Multi -E0x200 +Limit5 +BackgroundTrans, 20.00
Gui, Font ; Reset Font Options
Gui, Add, Edit, x32 y216 w536 h231 -E0x200 +BackgroundTrans, Data
Gui, Show, w600 h600, New Interface
Return ; END AUTOMATIC EXECUTION
; LABELS ============================================================================
MenuHandler:
Return
GuiClose:
ExitApp
Return
Code: Select all
#NoEnv
Gui, Font, S20
Gui, Add, Edit, x10 y10 w200 h60 Center +hwndHEDIT -VScroll +Limit5 -E0x200, Data
Edit_VCENTER(HEDIT)
Gui, Show, w220 h80, Gui Test
Return
GuiClose:
ExitApp
Edit_VCENTER(HEDIT) {
; 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, 0x00B2, 0, &RC, , ahk_id %HEDIT%
RCHeight := NumGet(RC, 12, "Int") - NumGet(RC, 4, "Int")
DY := (CLHeight - RCHeight) // 2
NumPut(NumGet(RC, 4, "Int") + DY, RC, 4, "Int")
NumPut(NumGet(RC, 12, "Int") + DY, RC, 12, "Int")
SendMessage, 0x00B3, 0, &RC, , ahk_id %HEDIT%
}
Code: Select all
; http://www.autohotkey.com/board/topic/80698-margin-for-edit/?p=512948
tp := 6 ; the amount of top padding in pixels.
string = This is some text ; <-- write to the text box here
Gui, Add, Edit, -0x200000 hwndEdit vEdit, % string "`n`n"
GuiControl,, Edit, % RegExReplace( string, "`n" )
Gui, Show, x10 y10, gui
;; Undocumented Constants:
; EM_GETRECT = 0xB2
; EM_SETRECT = 0xB3
VarSetCapacity( R, 16, 0 ) ; varset for Rect Struct
SendMessage, 0xB2,, % &R,, ahk_id %Edit%
x1:=NumGet( &R+0 ), y1:=NumGet( &R+4 )
x2:=NumGet( &R+8 ), y2:=NumGet( &R+12 )
NumPut( (x1-1), &R, 0 ), NumPut( (y1+tp), &R, 4 )
NumPut( (x2+1), &R, 8 ), NumPut( (y2+y1+1), &R, 12 ) ; <-- compensation for upper padding
SendMessage, 0xB3, 0x0, % &R,, ahk_id %Edit%
Return
GuiClose:
ExitApp
http://cboard.cprogramming.com/windows-programming/86087-vertically-centering-text-single-line-edit-static-control.html#post615130 wrote:1. Get the height of the text in the edit box.
2. Get the height of the edit box using GetClientRect.
3. Do the calculation to calculate the postion of centered text:
top = (client_height - font_height) / 2
4. Use this value in a call to EM_SETRECT.
Code: Select all
Gui, Font, S20
tp := 15 ; the amount of top padding in pixels.
Gui, Add, Edit, -VScroll -E0x200 hwndEdit w200 h60 Center, Data
Gui, Show, x10 y10, gui
VarSetCapacity( R, 16, 0 ) ; varset for Rect Struct
SendMessage, 0xB2,, % &R,, ahk_id %Edit%
x1:=NumGet( &R+0 ), y1:=NumGet( &R+4 )
x2:=NumGet( &R+8 ), y2:=NumGet( &R+12 )
NumPut( (x1-1), &R, 0 ), NumPut( (y1+tp), &R, 4 )
NumPut( (x2+1), &R, 8 ), NumPut( (y2+y1+1), &R, 12 ) ; <-- compensation for upper padding
SendMessage, 0xB3, 0x0, % &R,, ahk_id %Edit%
Return
GuiClose:
ExitApp
Code: Select all
#NoEnv
Gui, Font, S20
Gui, Add, Edit, -VScroll -E0x200 hwndEdit w200 h60 Center, Data
Gui, Show, , gui
Edit_VCENTER(Edit)
Return
GuiClose:
ExitApp
Edit_VCENTER(HEDIT) {
; 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, 0x00B2, 0, &RC, , ahk_id %HEDIT%
RCHeight := NumGet(RC, 12, "Int") - NumGet(RC, 4, "Int")
DY := (CLHeight - RCHeight) // 2
NumPut(NumGet(RC, 4, "Int") + DY, RC, 4, "Int")
NumPut(NumGet(RC, 12, "Int") + DY, RC, 12, "Int")
SendMessage, 0x00B3, 0, &RC, , ahk_id %HEDIT%
}
On my computer, the text displayed at top-center ...Then I tried to change the font name Gui, Font, S20, Consolas, then it works!! My OS is Chinese language, and the default font is simsun, a Chinese font. I also tried other Chinese fonts, none of them works.just me wrote:Code: Select all
#NoEnv Gui, Font, S20 Gui, Add, Edit, -VScroll -E0x200 hwndEdit w200 h60 Center, Data Gui, Show, , gui Edit_VCENTER(Edit) Return GuiClose: ExitApp Edit_VCENTER(HEDIT) { ; 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, 0x00B2, 0, &RC, , ahk_id %HEDIT% RCHeight := NumGet(RC, 12, "Int") - NumGet(RC, 4, "Int") DY := (CLHeight - RCHeight) // 2 NumPut(NumGet(RC, 4, "Int") + DY, RC, 4, "Int") NumPut(NumGet(RC, 12, "Int") + DY, RC, 12, "Int") SendMessage, 0x00B3, 0, &RC, , ahk_id %HEDIT% }
Code: Select all
#NoEnv
; String := "Ütag"
; String := "Ütag`nÖtag"
String := "Ütag`nÖtag`nÄtag"
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%
}
Users browsing this forum: Bing [Bot], Chunjee, exjnbtech49, Google [Bot], j4byers and 208 guests