mLipok Posted April 1 Posted April 1 Wondering how to use GUICtrlCreateEdit() and: https://learn.microsoft.com/en-us/windows/win32/controls/em-setzoom https://learn.microsoft.com/en-us/windows/win32/controls/edit-control-window-extended-styles https://learn.microsoft.com/en-us/windows/win32/controls/em-getzoom In combination with MouseWheel . Has anyone tried it yet? Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
ioa747 Posted April 1 Posted April 1 (edited) I searched for it (due to your post) with _GUICtrlRichEdit_Create it works expandcollapse popup#include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> $hMainGUI = GUICreate("Rich Edit Zoom with MouseWheel", 600, 400) ; Create a Rich Edit control instead of a standard Edit ; The _GuiCtrlRichEdit_Create function returns a Handle (hWnd), not a CID $hRichEdit = _GUICtrlRichEdit_Create($hMainGUI, "Hold CTRL and scroll the Mouse Wheel to Zoom.", 10, 10, 580, 380, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUISetState(@SW_SHOW) ; Register the Mouse Wheel message GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Clean up _GUICtrlRichEdit_Destroy($hRichEdit) Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam) ;~ Local Static $iCurrentZoom = 100 Local $iCurrentZoom = GetRichEditZoom($hRichEdit) ; Check if CTRL key is pressed (VK_CONTROL = 0x11) Local $iState = _WinAPI_GetKeyState(0x11) If BitAND($iState, 0x8000) Then Local $iDelta = _WinAPI_HiWord($wParam) If $iDelta > 0x7FFF Then $iDelta -= 0x10000 If $iDelta > 0 Then $iCurrentZoom += 10 Else $iCurrentZoom -= 10 EndIf ; Constraints If $iCurrentZoom < 10 Then $iCurrentZoom = 10 If $iCurrentZoom > 500 Then $iCurrentZoom = 500 ; Apply the Zoom to Rich Edit ; In Rich Edit, EM_SETZOOM works ok _SendMessage($hRichEdit, $EM_SETZOOM, $iCurrentZoom, 100) Return 0 ; Prevent default scrolling EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_MOUSEWHEEL Func GetRichEditZoom($hWnd) ; create two structures to accept the values (32-bit integers) Local $tNumerator = DllStructCreate("int") Local $tDenominator = DllStructCreate("int") ; send the message EM_GETZOOM (0x04E1) ; wParam: Pointer to the numerator ; lParam: Pointer to the denominator _SendMessage($hWnd, 0x04E1, DllStructGetPtr($tNumerator), DllStructGetPtr($tDenominator)) ; EM_GETZOOM returns True (1) if successful and False (0) if failed. ; The values we are interested in are always inside the structures (DllStruct) Local $nNum = DllStructGetData($tNumerator, 1) Local $nDen = DllStructGetData($tDenominator, 1) ; If the values are 0, it means that no zoom is set (100%) If $nNum = 0 Or $nDen = 0 Then Return 100 ; Return the percentage (e.g. 150 for 150%) Return Int(($nNum / $nDen) * 100) EndFunc ;==>GetRichEditZoom but with GUICtrlCreateEdit, I couldn't do it and that's why I cheated expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> Global $hMainGUI = GUICreate("Edit Control Font Zoom", 600, 400) Global $idEdit = GUICtrlCreateEdit("Hold CTRL and scroll the Mouse Wheel to change Font Size." & @CRLF & @CRLF & "Current Zoom: 100%", 10, 10, 580, 380, $WS_VSCROLL + $ES_MULTILINE) GUICtrlSetFont(-1, 10) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam) Local $iState = _WinAPI_GetKeyState(0x11) ; VK_CONTROL If BitAND($iState, 0x8000) Then Local $iDelta = _WinAPI_HiWord($wParam) If $iDelta > 0x7FFF Then $iDelta -= 0x10000 If $iDelta > 0 Then EditChangeZoom($idEdit, 1) ; Zoom In Else EditChangeZoom($idEdit, -1) ; Zoom Out EndIf Return 0 EndIf Return $GUI_RUNDEFMSG EndFunc Func EditChangeZoom($idCtrl, $iDirection) ; Start with a base font size (e.g., 10 or 12) Local Static $iBaseFontSize = 10 Local Static $iCurrentScale = 100 ; Percentage If $iDirection > 0 Then $iCurrentScale += 10 Else $iCurrentScale -= 10 EndIf ; Constraints If $iCurrentScale < 50 Then $iCurrentScale = 50 If $iCurrentScale > 500 Then $iCurrentScale = 500 Local $iNewSize = ($iBaseFontSize * $iCurrentScale) / 100 ConsoleWrite("Scale: " & $iCurrentScale & "% | New Font Size: " & $iNewSize & @CRLF) GUICtrlSetFont($idCtrl, $iNewSize) EndFunc Edited April 1 by ioa747 mLipok and argumentum 1 1 I know that I know nothing
Solution MattyD Posted April 3 Solution Posted April 3 yeah it's possible - the control needs to have ES_MULTILINE, and os needs to be >= Win10 1809 expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> Global Const $ES_EX_ALLOWEOL_CR = 0x0001 Global Const $ES_EX_ALLOWEOL_LF = 0x0002 Global Const $ES_EX_ALLOWEOL_ALL = BitOR($ES_EX_ALLOWEOL_CR, $ES_EX_ALLOWEOL_LF) Global Const $ES_EX_CONVERT_EOL_ON_PASTE = 0x0004 Global Const $ES_EX_ZOOMABLE = 0x0010 Global Const $EM_SETEXTENDEDSTYLE = ($ECM_FIRST + 10) Global Const $EM_GETEXTENDEDSTYLE = ($ECM_FIRST + 11) _Example() Func _Example() Local $hGUI = GUICreate("Example", 400, 200) Local $idEdit = GUICtrlCreateEdit("Test Text", 4, 4, 392, 192) $hEdit = GUICtrlGetHandle($idEdit) ;Don't use ES_EX_ with GUICtrlCreateEdit - Values are not window extended styles! ;wparam = bits of exstyle to set. lparam = exstyle GUICtrlSendMsg($idEdit, $EM_SETEXTENDEDSTYLE, $ES_EX_ZOOMABLE, $ES_EX_ZOOMABLE) GUISetState() ;Set zoom to 200% (wparam = numerator, lparam = denominator) GUICtrlSendMsg($idEdit, $EM_SETZOOM, 2, 1) ;Get zoom. numerator & denominator are passed by ref. Local $tZoom = DllStructCreate("int iNumerator;int iDenominator") GUICtrlSendMsg($idEdit, $EM_GETZOOM, DllStructGetPtr($tZoom, "iNumerator"), DllStructGetPtr($tZoom, "iDenominator")) MsgBox(0, "Zoom", StringFormat("Zoom = %d%%\r\n", 100*($tZoom.iNumerator / $tZoom.iDenominator))) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ioa747, argumentum, WildByDesign and 1 other 4
argumentum Posted April 3 Posted April 3 ..what about a GUICtrlCreateInput() ?, well that is not possible. But we can fake it Spoiler expandcollapse popup#include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <SliderConstants.au3> #include <GuiScrollBars.au3> Global Const $ES_EX_ZOOMABLE = 0x0010 Global Const $EM_SETEXTENDEDSTYLE = ($ECM_FIRST + 10) _Example() ; in part by "Google's latest Gemini technology". Thank you google. Now, make me an expresso 😁 Func _Example() Local $iMaxChars = 150 ; 🤔 Local $hGUI = GUICreate("Example fake input", 450, 220) ; Setup Fake Input Local $idEdit = GUICtrlCreateEdit("Ctrl+MouseWheel or use Slider.", 10, 20, 430, 25, BitOR($ES_MULTILINE, $ES_AUTOHSCROLL)) GUICtrlSendMsg($idEdit, $EM_LIMITTEXT, $iMaxChars, 0) Local $hEdit = GUICtrlGetHandle($idEdit) _GUIScrollBars_ShowScrollBar($hEdit, $SB_BOTH, False) GUICtrlSendMsg($idEdit, $EM_SETEXTENDEDSTYLE, $ES_EX_ZOOMABLE, $ES_EX_ZOOMABLE) Local $idLabel = GUICtrlCreateLabel("Zoom: 100%", 10, 100, 150, 20) Local $idSlider = GUICtrlCreateSlider(10, 130, 430, 35) GUICtrlSetLimit($idSlider, 500, 10) GUICtrlSetData($idSlider, 100) ; Accelerator to skip the Enter key Local $idDummyEnter = GUICtrlCreateDummy(), $aAccelerators[1][2] = [["{ENTER}", $idDummyEnter]] GUISetAccelerators($aAccelerators) GUISetState(@SW_SHOW) Local $iActualZoom, $iSliderVal, $hTimer = 0, $iLastKnownZoom = 100 ; struct for EM_GETZOOM Local $iNum, $iDen, $tZoom = DllStructCreate("int iNum;int iDen") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch ; Small skip to keep CPU usage lower If TimerDiff($hTimer) < 20 Then ContinueLoop $hTimer = TimerInit() ; Check if the Control's zoom changed (via Mouse Wheel) GUICtrlSendMsg($idEdit, $EM_GETZOOM, DllStructGetPtr($tZoom, "iNum"), DllStructGetPtr($tZoom, "iDen")) $iNum = DllStructGetData($tZoom, "iNum") $iDen = DllStructGetData($tZoom, "iDen") ; Calculate current % (default is 0/0 if never zoomed, which means 100%) $iActualZoom = 100 If $iDen <> 0 Then $iActualZoom = Int(($iNum / $iDen) * 100) ; Sync if Mouse Wheel changed the zoom If $iActualZoom <> $iLastKnownZoom Then GUICtrlSetData($idSlider, $iActualZoom) GUICtrlSetData($idLabel, "Zoom: " & $iActualZoom & "%") $iLastKnownZoom = $iActualZoom EndIf ; Sync if Slider changed the zoom $iSliderVal = GUICtrlRead($idSlider) If $iSliderVal <> $iLastKnownZoom Then GUICtrlSendMsg($idEdit, $EM_SETZOOM, $iSliderVal, 100) GUICtrlSetData($idLabel, "Zoom: " & $iSliderVal & "%") $iLastKnownZoom = $iSliderVal EndIf WEnd EndFunc ..they don't make cafe, yet. But am sure that if I can get a USB port to boil water, I can "invent" a PC powered expresso maker and people would buy it, google would by the company or, Starbucks will to adjust to the AI era. Note to self: open a company. A bit off topic but I was curious Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Nine Posted April 3 Posted April 3 @MattyD Good catch. FWIW, your approach works also with RichEdit. It was kind of obvious, anyway no need to subclass. _Example() Func _Example() Local $hGUI = GUICreate("Example", 400, 400) Local $hREdit = _GUICtrlRichEdit_Create($hGUI, "Ctrl Wheel to Zoom", 4, 4, 392, 192) Local $idEdit = GUICtrlCreateEdit("Ctrl Wheel to Zoom", 4, 200, 392, 192) ;Don't use ES_EX_ with GUICtrlCreateEdit - Values are not window extended styles! ;wparam = bits of exstyle to set. lparam = exstyle _SendMessage($hREdit, $EM_SETEXTENDEDSTYLE, $ES_EX_ZOOMABLE) GUICtrlSendMsg($idEdit, $EM_SETEXTENDEDSTYLE, $ES_EX_ZOOMABLE, $ES_EX_ZOOMABLE) GUISetState() ;Set zoom to 200% (wparam = numerator, lparam = denominator) _SendMessage($hREdit, $EM_SETZOOM, 2, 1) GUICtrlSendMsg($idEdit, $EM_SETZOOM, 2, 1) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc mLipok, MattyD, WildByDesign and 1 other 3 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
mLipok Posted April 3 Author Posted April 3 Finall solution: #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> Global Const $ES_EX_ALLOWEOL_CR = 0x0001 Global Const $ES_EX_ALLOWEOL_LF = 0x0002 Global Const $ES_EX_ALLOWEOL_ALL = BitOR($ES_EX_ALLOWEOL_CR, $ES_EX_ALLOWEOL_LF) Global Const $ES_EX_CONVERT_EOL_ON_PASTE = 0x0004 Global Const $ES_EX_ZOOMABLE = 0x0010 Global Const $EM_SETEXTENDEDSTYLE = ($ECM_FIRST + 10) ;~ Global Const $EM_GETEXTENDEDSTYLE = ($ECM_FIRST + 11) _Example() Func _Example() GUICreate("Example", 400, 400) Local $idEdit = GUICtrlCreateEdit("Ctrl Wheel to ZoomIn / ZoomOut", 4, 4, 392, 400 - 8) ; Don't use ES_EX_ with GUICtrlCreateEdit - Values are not window extended styles! ; wparam = bits of exstyle to set. lparam = exstyle GUICtrlSendMsg($idEdit, $EM_SETEXTENDEDSTYLE, $ES_EX_ZOOMABLE, $ES_EX_ZOOMABLE) GUISetState() ;Set zoom to 200% (wparam = numerator, lparam = denominator) GUICtrlSendMsg($idEdit, $EM_SETZOOM, 2, 1) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>_Example Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
mLipok Posted April 3 Author Posted April 3 Thank you all for your commitment to solving this problem. ioa747 and argumentum 2 Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
MattyD Posted April 4 Posted April 4 This might be getting a little bit too cute but... Because there a limit on the denominator (it must be <= 64), it can complicate things somewhat if you want to zoom by a percentage. Eg. to zoom to 123% we can't send 123/100, but we can get most of the way with 79/64. We could just work in 64ths - but its probably better to express numbers like 120% as 6/5 rather than 77/64. So here's something that works with percentages, and does the conversions to fractions for us. expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> Global Const $ES_EX_ALLOWEOL_CR = 0x0001 Global Const $ES_EX_ALLOWEOL_LF = 0x0002 Global Const $ES_EX_ALLOWEOL_ALL = BitOR($ES_EX_ALLOWEOL_CR, $ES_EX_ALLOWEOL_LF) Global Const $ES_EX_CONVERT_EOL_ON_PASTE = 0x0004 Global Const $ES_EX_ZOOMABLE = 0x0010 Global Const $EM_SETEXTENDEDSTYLE = ($ECM_FIRST + 10) Global Const $EM_GETEXTENDEDSTYLE = ($ECM_FIRST + 11) _Example() Func _Example() Local $hGUI = GUICreate("Example", 400, 200) Local $idEdit = GUICtrlCreateEdit("Test Text", 4, 4, 392, 192) _GuiCtrlEdit_SetZoomable($idEdit) GUISetState() Local $hTimer = TimerInit() Local $iSize Do If TimerDiff($hTimer) > 1000 Then $iSize = Random() * 500 _GuiCtrlEdit_SetZoom($idEdit, $iSize) GUICtrlSetData($idEdit, StringFormat("Set: %s%%\r\nGet: %s%%", $iSize, _GuiCtrlEdit_GetZoom($idEdit))) $hTimer = TimerInit() EndIf Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc Func _GuiCtrlEdit_SetZoomable($hWnd, $bEnabled = True) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) Return _SendMessage($hWnd, $EM_SETEXTENDEDSTYLE, $ES_EX_ZOOMABLE, ($bEnabled) ? $ES_EX_ZOOMABLE : 0) EndFunc Func _GuiCtrlEdit_GetZoom($hWnd) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) Local $aCall = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $EM_GETZOOM, "int*", 0, "int*", 0) If @error Then Return SetError(@error, @extended, 0) Return 100 * ($aCall[3]/$aCall[4]) EndFunc Func _GuiCtrlEdit_SetZoom($hWnd, $fZoom) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) Local $iRet, $iNum, $iDen, $iGCD $fZoom /= 100 If $fZoom > 64 Then $fZoom = 64 ;Max possible zoom = 64/1 _GetFraction($fZoom, $iNum, $iDen) ;Might be able to be improved. Limit denominator to 64. If $iDen > 64 Then $iNum = Round(($iNum * 64) / $iDen) $iDen = 64 $iGCD = _GetCommonDenominator($iNum, $iDen) $iNum /= $iGCD $iDen /= $iGCD If $iNum < 1 Then $iNum = 1 EndIf Return _SendMessage($hWnd, $EM_SETZOOM, $iNum, $iDen) EndFunc Func _GetFraction($fValue, ByRef $iNumerator, ByRef $iDenominator) $iNumerator = Round($fValue * 100) $iDenominator = 100 Local $iCommon = _GetCommonDenominator(Round($fValue * 100), 100) $iNumerator /= $iCommon $iDenominator /= $iCommon EndFunc ;euclidean algorithm - greatest common divisor Func _GetCommonDenominator($iA, $iB) Local $iTemp While $iB $iTemp = $iB $iB = Mod($iA, $iB) $iA = $iTemp WEnd Return Abs($iA) EndFunc mLipok, argumentum and ioa747 3
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now