Imbuter2000 Posted August 8, 2012 Posted August 8, 2012 I'ld like to easily add some arrows with different angles, sizes and colors, to a GUI. In order to do this, AutoIT comes with a beautiful fuction called _GDIPlus_ArrowCapCreate: http://www.autoitscript.com/autoit3/docs/libfunctions/_GDIPlus_ArrowCapCreate.htm Unfortunately, even the official example attached to this function has a problem: the arrows disappear if you minimize-maximize the window or anyhow cover-discover that arrows. The problem is known and someone already provided some solutions in AutoIT for drawings different than arrows: - - The problem (and solution) is also technically deeper described in this GDIPlus faq: http://www.bobpowell.net/picturebox.htm I tried to understand something to implement the solution to the example of the _GDIPlus_ArrowCapCreate documentation (see link above) but failed, I always obtain graphic corruptions after I minimize-maximize the window or anyhow cover-discover that arrows... Did anyone already succeded with arrows? is there an efficient solution? (without ending to the simple inefficient solution of cyclically/infinitely redrawing the arrows in the main loop)
PhoenixXL Posted August 8, 2012 Posted August 8, 2012 Register the GUI with $WM_PAINT notification and this is the respective Func Func WM_PAINT($hWnd,$iMsg,$wParam,$lParam) _WinAPI_RedrawWindow($hGui, 0, 0, $RDW_UPDATENOW) ;Your Code must lie in it _WinAPI_RedrawWindow($hGui, 0, 0, $RDW_VALIDATE) Return 'GUI_RUNDEFMSG' EndFunc My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.
Imbuter2000 Posted August 9, 2012 Author Posted August 9, 2012 (edited) PhoenixXL, I tried but nothing changed, the arrows still disappear. Here is my code: expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GDIPlus.au3> _Main() Func _Main() Local $hGUI, $hGraphic, $hPen, $hEndCap ; Create GUI $hGUI = GUICreate("GDI+", 400, 300) GUISetState() ; Create resources _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hPen = _GDIPlus_PenCreate(0xFF000000, 2) $hEndCap = _GDIPlus_ArrowCapCreate(3, 6) _GDIPlus_PenSetCustomEndCap($hPen, $hEndCap) GUIRegisterMsg(0x000F, "WM_PAINT") ;$WM_PAINT ; Draw arrows _GDIPlus_GraphicsDrawLine($hGraphic, 10, 120, 390, 120, $hPen) _GDIPlus_PenSetWidth($hPen, 4) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 150, 390, 150, $hPen) _GDIPlus_PenSetWidth($hPen, 6) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 180, 390, 180, $hPen) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Clean up resources _GDIPlus_ArrowCapDispose($hEndCap) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>_Main Func WM_PAINT($hGui,$iMsg,$wParam,$lParam) _WinAPI_RedrawWindow($hGui, 0, 0, $RDW_UPDATENOW) ;Your Code must lie in it _WinAPI_RedrawWindow($hGui, 0, 0, $RDW_VALIDATE) Return 'GUI_RUNDEFMSG' EndFunc Edited August 9, 2012 by Imbuter2000
UEZ Posted August 9, 2012 Posted August 9, 2012 Try this: expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GDIPlus.au3> Global $hGUI, $hGraphic, $hPen, $hEndCap _Main() Func _Main() ; Create GUI $hGUI = GUICreate("GDI+", 400, 300) GUISetState() ; Create resources _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hPen = _GDIPlus_PenCreate(0xFF000000, 2) $hEndCap = _GDIPlus_ArrowCapCreate(3, 6) _GDIPlus_PenSetCustomEndCap($hPen, $hEndCap) PAINT() GUIRegisterMsg(0x000F, "Paint") ;$WM_PAINT ; Loop until user exits Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_RESTORE PAINT() EndSwitch Until False ; Clean up resources _GDIPlus_ArrowCapDispose($hEndCap) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>_Main Func PAINT() _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 120, 390, 120, $hPen) _GDIPlus_PenSetWidth($hPen, 4) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 150, 390, 150, $hPen) _GDIPlus_PenSetWidth($hPen, 6) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 180, 390, 180, $hPen) Return 'GUI_RUNDEFMSG' EndFunc Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
PhoenixXL Posted August 9, 2012 Posted August 9, 2012 (edited) This should be the Func you missed out to place your code thereFunc WM_PAINT($hGui,$iMsg,$wParam,$lParam) _WinAPI_RedrawWindow($hGui, 0, 0, $RDW_UPDATENOW) ;Your Code must lie in it _GDIPlus_GraphicsDrawLine($hGraphic, 10, 120, 390, 120, $hPen) _GDIPlus_PenSetWidth($hPen, 4) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 150, 390, 150, $hPen) _GDIPlus_PenSetWidth($hPen, 6) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 180, 390, 180, $hPen) ;End of your code _WinAPI_RedrawWindow($hGui, 0, 0, $RDW_VALIDATE) Return 'GUI_RUNDEFMSG' EDIT: Make your vars $hGraphic, $hPen Global then it would work Regards Phoenix XL Edited August 9, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.
PhoenixXL Posted August 9, 2012 Posted August 9, 2012 (edited) This should be the codeexpandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GDIPlus.au3> Global $hGraphic, $hPen _Main() Func _Main() Local $hGUI, $hEndCap ; Create GUI $hGUI = GUICreate("GDI+", 400, 300) GUISetState() ; Create resources _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hPen = _GDIPlus_PenCreate(0xFF000000, 2) $hEndCap = _GDIPlus_ArrowCapCreate(3, 6) _GDIPlus_PenSetCustomEndCap($hPen, $hEndCap) GUIRegisterMsg(0x000F, "WM_PAINT") ;$WM_PAINT ; Draw arrows _GDIPlus_GraphicsDrawLine($hGraphic, 10, 120, 390, 120, $hPen) _GDIPlus_PenSetWidth($hPen, 4) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 150, 390, 150, $hPen) _GDIPlus_PenSetWidth($hPen, 6) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 180, 390, 180, $hPen) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Clean up resources _GDIPlus_ArrowCapDispose($hEndCap) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>_Main Func WM_PAINT($hGui,$iMsg,$wParam,$lParam) _WinAPI_RedrawWindow($hGui, 0, 0, $RDW_UPDATENOW) ;Your Code must lie in it _GDIPlus_GraphicsDrawLine($hGraphic, 10, 120, 390, 120, $hPen) _GDIPlus_PenSetWidth($hPen, 4) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 150, 390, 150, $hPen) _GDIPlus_PenSetWidth($hPen, 6) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 180, 390, 180, $hPen) ;End of your code _WinAPI_RedrawWindow($hGui, 0, 0, $RDW_VALIDATE) Return 'GUI_RUNDEFMSG' EndFunc Edited August 9, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.
Malkey Posted August 10, 2012 Posted August 10, 2012 This method works on my xp. expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GDIPlus.au3> Global $hBMPBuff, $hGraphicGUI _Main() Func _Main() Local $hGUI, $hEndCap, $hGraphic $hGUI = GUICreate("GDI+", 400, 300, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX)) GUISetState() _GDIPlus_Startup() $hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBMPBuff = _GDIPlus_BitmapCreateFromGraphics(400, 300, $hGraphicGUI) ; Create bitmap the same size as the graphics of the GUI. $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff) ; Create graphics for bitmap, $hBMPBuff. (where the graphics is like the canvas of the bitmap) $hPen = _GDIPlus_PenCreate(0xFFFF0000, 2) ; Hex colour format 0xAARRGGBB - Alpha (transparency), Red, Green, Blue. $hEndCap = _GDIPlus_ArrowCapCreate(3, 6) _GDIPlus_PenSetCustomEndCap($hPen, $hEndCap) ; Draw arrows to bitmap _GDIPlus_GraphicsDrawLine($hGraphic, 10, 120, 390, 120, $hPen) _GDIPlus_PenSetWidth($hPen, 4) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 150, 390, 150, $hPen) _GDIPlus_PenSetWidth($hPen, 6) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 180, 390, 180, $hPen) _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0) ; Draw bitmap to GUI (graphics). ; Loop until user exits GUIRegisterMsg(0x000F, "WM_PAINT") ;$WM_PAINT Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Clean up resources _GDIPlus_ArrowCapDispose($hEndCap) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose($hGraphicGUI) _WinAPI_DeleteObject($hBMPBuff) _GDIPlus_Shutdown() EndFunc ;==>_Main Func WM_PAINT($hGUI, $iMsg, $wParam, $lParam) _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0) _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE) Return 'GUI_RUNDEFMSG' EndFunc ;==>WM_PAINT
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