
guiguy
Members-
Posts
13 -
Joined
-
Last visited
Everything posted by guiguy
-
Ahhh, you are indeed wise Melba23. Thank you for revealing the secret of _WinAPI_GetSystemMetrics I was playing around with different styles because I wanted a nice looking decoration around the input control. $WS_SIZEBOX looked really good to me, but of course it lets the user resize the control. $WS_EX_OVERLAPPEDWINDOW is a reasonable alternative. Your script does give suitably sized controls as I see it. Thank you for your input and help.
-
Sure thing Melba23. Here is an example that shows the issue. NOTE: This requires the StringSize UDF in the run directory !! It displays a sequence of windows: 1. This shows an input control sized exactly to the text height and width, with no up/down control attached. You can see there is effectively no input area. Press Continue. 2. This window shows an input control sized to the text height but with an additional margin added to the width. Again the input area is clipped. Press Continue. 3. This window shows an input control sized with an additional margin added to both the width and height. Now the input area is usable. Press Continue. 4. This shows an input control with an up/down control attached. It is sized with the same additional margins as the previous window. The input area is clipped by the up/down control. Press Continue. 5. This shows an input control with the up/down control attached. The width margin has been increased and now the input area is fully functional. Press Exit #comments-start ########################################################### # Example of Input Control clipping the input area ########################################################### #comments-end #include "StringSize.au3" #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Const $Root_Width = 500 Const $Root_Height = 300 Const $Font_Size = 12 Const $Font_Weight = 400 Const $Font_Attr = 0 Const $Font_Name = "Arial" Const $FONT_QUAL_CLEARTYPE = 5 Const $Input_Left = 200 Const $Input_Top = 150 Const $Input_Style = $WS_SIZEBOX Const $Input_Ex_Style = $WS_EX_OVERLAPPEDWINDOW Const $Btn_Width = 100 Const $Btn_Left = Int(($Root_Width - $Btn_Width) / 2) Const $Btn_Hght = 50 Const $Btn_Top = $Root_Height - $Btn_Hght - 10 Const $InputText = "99" Const $AppTitle = "Example of Input Control clipping" Global $Waiting = true Global $Input_HNDL Global $Up_Dn_HNDL #comments-start #---------------------------------------------------------- # Main Routine #---------------------------------------------------------- #comments-end ; Create a root window $Root_HNDL = GUICreate($AppTitle, _ $Root_Width, $Root_Height, -1, -1, -1, -1) CheckForError($Root_HNDL, "Error creating the root GUI window") ; Set the font $Rtn = GUISetFont($Font_Size, $Font_Weight, $Font_Attr, _ $Font_Name, $Root_HNDL, $FONT_QUAL_CLEARTYPE) CheckForError($Rtn, "Error setting the root GUI font attributes") ; Calculate the size of the text string Local $tSize = _StringSize($InputText, $Font_Size, $Font_Weight, $Font_Attr, $Font_Name) CheckForError($tSize, "StringSize error "& String(@error)) Global $Font_Height = $tSize[1] Global $Str_Width = $tSize[2] ; Display the text size $Info_HNDL = GUICtrlCreateLabel( _ "Text =[" & $InputText & "], height = " & String($Font_Height) & _ ", width = " & String($Str_Width), 20, 20, 400, 60) CheckForError($Info_HNDL, "Error creating the root GUI label") ; Add a label to the root window $Label_HNDL = GUICtrlCreateLabel("Root Label", 20, 60, 400, 60) CheckForError($Label_HNDL, "Error creating the root GUI label") ; Add a button to the root window Global $Pause_HNDL = GUICtrlCreateButton("Pause", $Btn_Left, $Btn_Top, _ $Btn_Width, $Btn_Hght) CheckForError($Pause_HNDL, "Error creating the button") ; Add the button callback $Rtn = GUICtrlSetOnEvent($Pause_HNDL, "ProcessButton") CheckForError($Rtn, "Error setting the button callback") ; System events callback $Rtn = GUISetOnEvent($GUI_EVENT_CLOSE, "ProcessSysEvent", $Root_HNDL) CheckForError($Rtn, "Error setting the system event callback") ; Show first example $heightMargin = 0 $widthMargin = 0 $upDown = False $title = "Input Control with no Up/Down and no margins" $Rtn = MakeGUI($heightMargin, $widthMargin, $upDown, $title) Pause("Continue") ; Show second example $heightMargin = 0 $widthMargin = 20 $upDown = False $title = "Input Control with no Up/Down and height margin = " & _ String($heightMargin) & _ ", width margin = " & String($widthMargin) $Rtn = MakeGUI($heightMargin, $widthMargin, $upDown, $title) Pause("Continue") ; Show third example $heightMargin = 20 $widthMargin = 20 $upDown = False $title = "Input Control with no Up/Down and height margin = " & _ String($heightMargin) & _ ", width margin = " & String($widthMargin) $Rtn = MakeGUI($heightMargin, $widthMargin, $upDown, $title) Pause("Continue") ; Show fourth example $heightMargin = 20 $widthMargin = 20 $upDown = True $title = "Input Control with Up/Down and height margin = " & _ String($heightMargin) & _ ", width margin = " & String($widthMargin) $Rtn = MakeGUI($heightMargin, $widthMargin, $upDown, $title) Pause("Continue") ; Show fifth example $heightMargin = 20 $widthMargin = 45 $upDown = True $title = "Input Control with Up/Down and height margin = " & _ String($heightMargin) & _ ", width margin = " & String($widthMargin) $Rtn = MakeGUI($heightMargin, $widthMargin, $upDown, $title) Pause("Exit") #comments-start #---------------------------------------------------------- # Func MakeGUI #---------------------------------------------------------- # Makes an Input Control #---------------------------------------------------------- #comments-end Func MakeGUI($Hmargin, $Wmargin, $UpDnFlag, $msg) ; Set the label text $Rtn = GUICtrlSetData($Label_HNDL, $msg) CheckForError($Rtn, "Error setting the root GUI label") ; Add the input control to the root window $Input_HNDL = GUICtrlCreateInput($InputText, $Input_Left, _ $Input_Top, $Str_Width + $Wmargin, _ $Font_Height + $Hmargin, $Input_Style, $Input_Ex_Style) CheckForError($Input_HNDL, "Error creating the hours input GUI") ; Add the Up/Down Control if requested if ($UpDnFlag = true) then $Up_Dn_HNDL = GUICtrlCreateUpdown($Input_HNDL) CheckForError($Up_Dn_HNDL, "Error creating the up/down control") else $Up_Dn_HNDL = 0 endif ; Display the GUI $Rtn = GUISetState(@SW_SHOW, $Root_HNDL) CheckForError($Rtn, "Error showing the GUI") EndFunc ;MakeGUI #comments-start #---------------------------------------------------------- # Func ProcessButton #---------------------------------------------------------- # Called when the button is pressed #---------------------------------------------------------- #comments-end Func ProcessButton() ; Flag we are done waitng $Waiting = false EndFunc #comments-start #---------------------------------------------------------- # Func ProcessSysEvent #---------------------------------------------------------- # Processes a click on the root GUI button. #---------------------------------------------------------- #comments-end Func ProcessSysEvent() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE $Waiting = false Exit 0 Case Else ; Null EndSelect endFunc ; ProcessSysEvent #comments-start #---------------------------------------------------------- # Func Pause #---------------------------------------------------------- # Exits application with a message and an exit return code #---------------------------------------------------------- #comments-end Func Pause($Pmsg) ; Set the button label $Rtn = GUICtrlSetData($Pause_HNDL, $Pmsg) CheckForError($Rtn, "Error setting the button label") ; Now wait for the button to be pressed AutoItSetOption("GUIOnEventMode", 1) ; Enable event mode CheckSysError(@error, "Error enabling event mode") $Waiting = true while ($Waiting = true) sleep(100) Wend AutoItSetOption("GUIOnEventMode", 0) ; Disable event mode CheckSysError(@error, "Error disabling event mode") ; Hide the GUI $Rtn = GUISetState(@SW_HIDE, $Root_HNDL) CheckForError($Rtn, "Error showing the GUI") ; Tear down the Input Control GUI $Rtn = GUICtrlDelete($Input_HNDL) CheckForError($Rtn, "Error deleting the input control") if ($Up_Dn_HNDL <> 0) then $Rtn = GUICtrlDelete($Up_Dn_HNDL) CheckForError($Rtn, "Error deleting the up/down control") Endif EndFunc ;Pause #comments-start #---------------------------------------------------------- # Func Abort #---------------------------------------------------------- # Exits application with a message and an exit return code #---------------------------------------------------------- #comments-end Func Abort($Msg = "Aborting...", $Rtn = -1) Const $MSGBOX_STOPSIGN = 0x10 MsgBox(BitOR(0, $MSGBOX_STOPSIGN), $AppTitle, _ $Msg & ", aborting...") Exit $Rtn EndFunc #comments-start #---------------------------------------------------------- # Func CheckForError #---------------------------------------------------------- # Tests the provided return code for error, and aborts with # a message if there is one. # Error => code is zero #---------------------------------------------------------- #comments-end Func CheckForError($code, $msg) if $code = 0 then Abort($msg) endif EndFunc ;CheckForError #comments-start #---------------------------------------------------------- # Func CheckSysError #---------------------------------------------------------- # Tests the provided return code for system error, and # aborts with a message if there is one. # Error => code is non-zero #---------------------------------------------------------- #comments-end Func CheckSysError($code, $msg) if $code <> 0 then Abort($msg) endif EndFunc ; CheckSysError The margins above had to be determined by trial and error. They vary depending on the combination of style and extended style used in the GUICtrlCreateInput call. I don't think you need to change the StringSize algorithm, I just need to know by how much the input area width and height is reduced. I hate having to determine these by trial and error. Thanks for your interest in this issue.
-
mLipok - Thanks for the information. This tells me how to write an app so the GUI will scale properly across different displays. Great stuff! BrewManNH - Thanks for the pointer to Melba23's StringSize UDF. This gave me the clue to what I was looking for. StringSize gives me numbers similar to my own calculations, still leaving me with a mystery. I am using the numbers to size an Input Control (GUICtrlCreateInput) with an associated Up/Down control (GUICtrlCreateUpdown). It looks like the Input Control reduces the actual input area by an unknown margin. The Up/Down control reduces the input area width by an additional amount. I had not expected this. Shouldn't something like this be mentioned in the help files? I am distressed at having to resort to trial and error to find the proper sizes for GUI elements. I'm a newbie, so maybe I'm overlooking something? Thanks again to mLipok and BrewManNH for their responses.
-
Wow - thanks mLipok. That's a lot to digest but I'll be sure to go through it.
-
I am struggling to figure out how to size a window to a particular text font so it will scale correctly across differing displays. What are the units for the window width and height used by GUICreate? are they pixels? For example, I want to size the height of a window for a 12 point font. Function _WinAPI_TwipsPerPixelX() tells me my display has 15 twips per pixel. (A twip is 1/1440 of and inch and is also 1/20 of a point) So 12 points X 20 twips/point X 1/15 pixels/twip = 16 pixels If I create a window 16 (pixels) high the text is chopped off. I actually have to use a height of 40 to get decent looking text. Using function _WinAPI_GetTextMetrics() I find the height of the 12 point font is 12, it has an ascender height of 9 and a descender height of 3. Assuming those units are all in points summing up gives 23 points. 23 points X 20 twips/point X 1/15 pixels/twip = 30.67 pixels. If I create a window 31 high the text is still chopped off - it needs a height of 40. What is going on here?
-
Yes, that's what I have been doing, it just takes too long Too bad there isn't a shortcut key for the "Mark as Read" link - that would make it faster.
-
Is there a way to quickly select a group of topics in a forum and mark them as read? I don't want to mark the whole forum as read. Previewing each topic and selecting "Mark as read" takes too long.
-
Problem with _WinAPI_GetTextMetrics
guiguy replied to guiguy's topic in AutoIt General Help and Support
Thank you UEZ! I suspected there was a required sequence I wasn't following. Its difficult to glean this info from the help pages. Sorry if I seemed impatient. I wasn't - just frustrated. Thanks again for your help. -
Problem with _WinAPI_GetTextMetrics
guiguy replied to guiguy's topic in AutoIt General Help and Support
Huh. 39 views, no responses. I know I'm new to these forums, but can't somebody help? I didn't think this was a hard problem. I'm frustrated -
How can i separate koda and custom gui on my script...
guiguy replied to Aktonius's topic in AutoIt GUI Help and Support
This is a problem I have seen with just about every GUI builder I have used. Even commercial ones costing big $$$. Here's the cycle: 1) Build a graphic layout using the GUI editor 2) Autogenerate the code for the graphics 3) Add (manually) the custom code required to make the GUI work 4) Recognize the need to update the graphic layout 5) Revise the graphics layout using the GUI editor 6) Autogenerate the code for the revised graphics 7) Get frustrated because the autogeneration messed up the existing code and you have to manually add in the previous custom code in addition to the new custom code. Isn't there some way to design a GUI builder to make revisions of autogenerated code easier? Maybe some comment keywords that tell the GUI builder "don't touch this section of code" And some keyword(s) that mean "don't change this control id / variable name / function name / etc" For small projects its not a big deal to fix things up manually when revisions are made, but for a large system with 52 different screens and thousands of lines of callback code it's a real killer. I'm just saying... -
I did an experiment (my company is using the Lotus Notes version 8.5 mailer) sending email to myself. If I copy/paste the corrupted link into a message, and then another copy which I manually corrected, the corrupted one still comes through corrupted and the corrected one comes through correct. But the bizarre thing is, if I use the "Copy into new message" feature, the corrupted links show up correctly (in the edit mode, before emailing)! And they show up correct after emailing. Weird. I think BrewManNH is correct, special characters should be quoted (&) in the URL.
-
I am having a problem using _WinAPI_GetTextMetrics with AutoIt version 3.3.8.1 The function seems to give the same values for text with different font sizes. In particular elements "tmHeight" and "tmMaxCharWidth". The following script will show the problem. It should first be run with font size 8.5 enabled and font size 20 commented out, then again with font size 20 enabled. Values "tmHeight" and "tmMaxCharWidth" are the same for both fonts! Why is that? (Or what am I doing wrong?) #cs # Example showing difficulty with _WinAPI_GetTextMetrics #ce Const $GUI_Font_Size = 8.5 ;Run script first using this ;Const $GUI_Font_Size = 20 ;Run script again using this #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> Const $GUI_Width = 600 Const $GUI_Height = 200 Const $GUI_Left = -1 ; Centered Const $GUI_Top = 100 Const $GUI_Style = $WS_BORDER Const $GUI_Parent = -1 Const $Lbl_Txt = "Any text string - gjpqy at font size " & _ String($GUI_Font_Size) Const $AppTitle = "Get font info" Const $MSGBOX_STOPSIGN = 0x10 ;Screen pixel scaling in twips per pixel (twip = 1/1440 inch = 1/20 point) Global $Dsply_X_Scale = _WinAPI_TwipsPerPixelX() Global $Dsply_Y_Scale = _WinAPI_TwipsPerPixelY() #cs #================ # Main Routine #================ #ce ; Create the GUI window Local $GUI_HNDL = GUICreate($AppTitle, $GUI_Width, $GUI_Height, _ $GUI_Left, $GUI_Top, $GUI_Style, $GUI_Parent) CheckForError($GUI_HNDL, "Error creating the GUI window") ; Set the font size Local $Rtn = GUISetFont($GUI_Font_Size, 400, 0, "", $GUI_HNDL, 5) CheckForError($Rtn, "Error setting the font attributes") ; Add the label Local $Lbl_CID = GUICtrlCreateLabel($Lbl_Txt, -1, _ -1, ($GUI_Width - 50), ($GUI_Height - 50), $SS_CENTER) CheckForError($Lbl_CID, "Error creating the alert label") ; Display the GUI $Rtn = GUISetState(@SW_SHOW,$GUI_HNDL) CheckForError($Rtn, "Error showing the GUI") ; Get the font info - allocate the info struct Local $Metrics = DllStructCreate($tagTEXTMETRIC) CheckSysError(@error, "Error [" & String(@error) & _ "] creating struct $tagTEXTMETRIC") ;Get the decive context Local $hDC = _WinAPI_GetDC($GUI_HNDL) CheckForError($hDC, "Error getting device context") ; Get the metrics $Metrics = _WinAPI_GetTextMetrics($hDC) CheckSysError(@error, "Error getting text metric structure") ; Free the device context $Rtn = _WinAPI_ReleaseDC($GUI_HNDL, $hDC) CheckForError($Rtn, "Error releasing device context") ; Pull out the desired information Local $FontHeight = DllStructGetData($Metrics, "tmHeight") CheckSysError(@error, "Struct error [" & String(@error) & _ "] getting tmHeight") Local $FontMaxCharWidth = DllStructGetData($Metrics, "tmMaxCharWidth") CheckSysError(@error, "Struct error [" & String(@error) & _ "] getting tmMaxCharWidth") Local $tmAscent = DllStructGetData($Metrics, "tmAscent") CheckSysError(@error, "Struct error [" & String(@error) & _ "] getting tmAscent") Local $tmDescent = DllStructGetData($Metrics, "tmDescent") CheckSysError(@error, "Struct error [" & String(@error) & _ "] getting tmDescent") $Metrics = 0 ;Free the struct memory MsgBox(0, $AppTitle, _ "tmHeight = " & String($FontHeight) & @CRLF & _ "tmMaxCharWidth = " & String($FontMaxCharWidth) & @CRLF & _ "tmAscent = " & String($tmAscent) & @CRLF & _ "tmDescent = " & String($tmDescent) & @CRLF & _ "Vert res = " & String(@DesktopHeight) & @CRLF & _ "Horz res = " & String(@DesktopWidth) & @CRLF & _ "Dsply Y twips per pixel = " & String($Dsply_Y_Scale) & @CRLF & _ "Dsply X twips per pixel = " & String($Dsply_X_Scale)) #cs #-------------- # Func Abort #-------------- #ce Func Abort($Msg = "Aborting...", $Rtn = -1) MsgBox(Bitor(0, $MSGBOX_STOPSIGN), $AppTitle, _ $Msg & ", aborting...") Exit $Rtn EndFunc #cs #---------------------------------------------------------- # Func CheckForError #---------------------------------------------------------- # Tests the provided return code for error, and aborts with # a message if there is one. # Error => code is zero #---------------------------------------------------------- #ce Func CheckForError($code, $msg) if $code = 0 then Abort($msg) endif EndFunc ;CheckForError #cs #---------------------------------------------------------- # Func CheckSysError #---------------------------------------------------------- # Tests the provided return code for system error, and # aborts with a message if there is one. # Error => code is non-zero #---------------------------------------------------------- #ce Func CheckSysError($code, $msg) if $code <> 0 then Abort($msg) endif EndFunc ; CheckSysError
-
I had the same problem. Found the fix by trial and error. We are using the Lotus Notes emailer. How did the links get corrupted???