teadrinker пишет:Спасибо! В итоге вот такое получилось:
Спасибо аналогично, немного изменений и примеров:
1. Замена GetTextExtentPoint32 на DrawText
String =
(
Многострочный
текст
Hello, World!
AHK forever!
)
if pResult := GetTextSize(String, "Arial", "s24 italic")
{
w := NumGet(pResult+8)
h := NumGet(pResult+12)
MsgBox, % "Ширина " . w . "`nВысота " . h
}
Return
GetTextSize(String, FontName, Options)
{
static SIZE
coding := A_IsUnicode ? "W" : "A"
LOGPIXELSY := 90
FW_NORMAL := 400, FW_BOLD := 700
DEFAULT_CHARSET := 1
DEFAULT_QUALITY := OUT_DEFAULT_PRECIS := CLIP_DEFAULT_PRECIS := 0
if !RegExMatch(Options, "i).*s(\d+).*", Found)
{
MsgBox, Не задан размер шрифта!
Return
}
s := Found1
if !InStr(Options, "bold")
{
if !RegExMatch(Options, "i).*w(\d+).*", Found)
w := FW_NORMAL
Else
w := Found1
}
Else
w := FW_BOLD
if w not Between 1 and 1000
{
MsgBox, Неверно задан параметр w.`nДолжен быть в пределах от 1 до 1000
Return
}
italic := InStr(Options, "italic") > 0
underline := InStr(Options, "underline") > 0
strike := InStr(Options, "strike") > 0
hDC := DllCall("GetDC", UInt, 0)
nHeight := -DllCall("MulDiv", Int, s
, Int, DllCall("GetDeviceCaps", UInt, hDC, Int, LOGPIXELSY), Int, 72)
hFont := DllCall("CreateFont" . coding
, Int, nHeight, Int, 0
, Int, 0, Int, 0, Int, w
, UInt, italic, UInt, underline, UInt, strike
, UInt, DEFAULT_CHARSET, UInt, OUT_DEFAULT_PRECIS
, UInt, CLIP_DEFAULT_PRECIS, UInt, DEFAULT_QUALITY
, UInt, 0, Str, FontName)
hPrevObj := DllCall("SelectObject", UInt, hDC, UInt, hFont)
VarSetCapacity(Buf, 40)
DllCall("GetTextFace" . coding, UInt, hDC, Int, 40, Str, Buf)
if (Buf != FontName)
{
FreeMemory(hPrevObj, hDC, hFont)
MsgBox, Указанный шрифт не поддерживается системой!
Return
}
VarSetCapacity(TextRect,16,0)
DllCall("DrawText" . coding, UInt, hDC, Str, String, Int, StrLen(String), Ptr, &TextRect, UInt, DT_CALCRECT:=0x400)
FreeMemory(hPrevObj, hDC, hFont)
Return &TextRect
}
FreeMemory(hPrevObj, hDC, hFont)
{
DllCall("SelectObject", UInt, hDC, UInt, hPrevObj)
DllCall("ReleaseDC", UInt, 0, UInt, hDC)
DllCall("DeleteObject", UInt, hFont)
}
2. ToolTip и WM_SETFONT пример 1
Text =
(
Многострочный
текст
Hello,World!
AHK forever!
)
ToolTip,% Text
WinGet,httip,ID,% Text
; WinSet, Style,+0x40000,ahk_id %httip% ; добавим рамку изменения размера
if hFont:=CreateToolTipFont("Times New Roman","s20 bold italic")
SendMessage,0x30,hFont,1,,ahk_id %httip%
Return
Esc::
GuiClose:
DllCall("DeleteObject", UInt, hFont)
ExitApp
/*
WM_SETFONT = 0x30
WM_GETFONT = 0x31
*/
CreateToolTipFont(FontName,Options)
{
coding := A_IsUnicode ? "W" : "A"
LOGPIXELSY := 90
FW_NORMAL := 400, FW_BOLD := 700
DEFAULT_CHARSET := 1
DEFAULT_QUALITY := OUT_DEFAULT_PRECIS := CLIP_DEFAULT_PRECIS := 0
if !RegExMatch(Options, "i).*s(\d+).*", Found)
{
MsgBox, Не задан размер шрифта!
Return
}
s := Found1
if !InStr(Options, "bold")
{
if !RegExMatch(Options, "i).*w(\d+).*", Found)
w := FW_NORMAL
Else
w := Found1
}
Else
w := FW_BOLD
if w not Between 1 and 1000
{
MsgBox, Неверно задан параметр w.`nДолжен быть в пределах от 1 до 1000
Return
}
italic := InStr(Options, "italic") > 0
underline := InStr(Options, "underline") > 0
strike := InStr(Options, "strike") > 0
hDC := DllCall("GetDC", UInt, 0)
nHeight := -DllCall("MulDiv", Int, s, Int, DllCall("GetDeviceCaps", UInt, hDC, Int, LOGPIXELSY), Int, 72)
hFont := DllCall("CreateFont" . coding
, Int, nHeight, Int, 0
, Int, 0, Int, 0, Int, w
, UInt, italic, UInt, underline, UInt, strike
, UInt, DEFAULT_CHARSET, UInt, OUT_DEFAULT_PRECIS
, UInt, CLIP_DEFAULT_PRECIS, UInt, DEFAULT_QUALITY
, UInt, 0, Str, FontName)
hPrevObj := DllCall("SelectObject", UInt, hDC, UInt, hFont)
VarSetCapacity(Buf, 40)
DllCall("GetTextFace" . coding, UInt, hDC, Int, 40, Str, Buf)
DllCall("SelectObject", UInt, hDC, UInt, hPrevObj)
DllCall("ReleaseDC", UInt, 0, UInt, hDC)
if (Buf != FontName)
{
MsgBox, Указанный шрифт не поддерживается системой!
DllCall("DeleteObject", UInt, hFont)
Return
}
Return hFont
}
3. ToolTip и WM_SETFONT пример 2
Text =
(
Многострочный
текст
Hello,World!
AHK forever!
)
Gui, Font, s20 bold italic, Times New Roman
Gui, Add,Text, HwndhStatic,% Text
SendMessage,0x31,,,,ahk_id %hStatic%
hFont:=ErrorLevel
ToolTip, % Text
WinGet,httip,ID,% Text
; WinSet, Style,+0x40000,ahk_id %httip% ; добавим рамку изменения размера
SendMessage,0x30,hFont,1,,ahk_id %httip%
Return
Esc::
GuiClose:
ExitApp
4.
string:="меняем размер контрола Static (Text) и наблюдаем за поведением текста"
Gui, + Lastfound +Resize -Caption
hgui:=WinExist()
Gui, Margin,0,0
Gui, Color, 0xFFFFE1
Gui, Font, s20 italic, Times New Roman
Gui, Add, Text, vText1 hwndhStatic, % string
Gui, Show
OnMessage(0x05,"WndProc")
OnMessage(0x47,"WndProc")
Return
WndProc(wParam,lParam,Msg,hWnd)
{
global hgui,hStatic,hFont,wx,wy,ww,wh
if (Msg=0x05)
{
hrgn:=DllCall("CreateRoundRectRgn","int",2,"int",2,"int",ww-1,"int",wh-1,"int",20,"int",20)
DllCall("SetWindowRgn","uint",hgui,"uint",hrgn,"int",1)
}
else if (Msg=0x47)
{
wx:=NumGet(lParam+8),wy:=NumGet(lParam+12)
ww:=NumGet(lParam+16),wh:=NumGet(lParam+20)
; ToolTip, % "ww " . ww . "wh " . wh
; GuiControl, Move, Text1, % "w" . ww-6 . " h" . wh-6
DllCall("SetWindowPos","uint",hStatic,"uint",0,"int",0,"int",0,"int",ww-6,"int",wh-6,"uint",0x2|0x4|0x10|0x40)
DllCall("InvalidateRect","uint",hStatic,"uint",0,"int",1)
}
}
Esc::
GuiClose:
ExitApp
/*
WM_WINDOWPOSCHANGED = 0x47
WM_SIZE = 0x05
SWP_NOSIZE 0x0001
SWP_NOMOVE 0x0002
SWP_NOZORDER 0x0004
SWP_NOREDRAW 0x0008
SWP_NOACTIVATE 0x0010
SWP_FRAMECHANGED 0x0020 /* The frame changed: send WM_NCCALCSIZE */
SWP_SHOWWINDOW 0x0040
SWP_HIDEWINDOW 0x0080
SWP_NOCOPYBITS 0x0100
SWP_NOOWNERZORDER 0x0200 /* Don't do owner Z ordering */
SWP_NOSENDCHANGING 0x0400 /* Don't send WM_WINDOWPOSCHANGING */
HWND_TOP ((HWND)0)
HWND_BOTTOM ((HWND)1)
HWND_TOPMOST ((HWND)-1)
HWND_NOTOPMOST ((HWND)-2)
*/