Luigi Posted August 28, 2014 Share Posted August 28, 2014 (edited) Hi forum This script simulate a A4 page, to build a printable version's form. The form have fields statics and fields dinamic, with data from any database, this is not important. But, you can add fields, change font, change color font, color background, delete... It is based in GUICtrlControLabel and is easy move the field with mouse, they are get control from GUIGetCursorInfo. The fear starting now... I rewrite this code in GDIPlus, to not use a GUICtrlControlLabel. I want use a field, text, line drawed in GDI... Now... How detect a field designed in GDI? Whitout a native AutoIt's handle? I don't have a GuiCreateControlXXXXXX to use a GuiGetCursorinfo or similar to obtain a handle... I have only x, y, width and height... no more... I have one script it hold a field drawed with GDI and move to anywhere... My fear it is... To one, two or tree fields I thinking this alghoritm is soft, but, whit many fields? Calculate a mouse's relative position in relation to twenty, thirty fields? Check if mouse is over a GDI's box or not... Need a better idea. Someone would share with me a way/information to repositioning with mouse one of many GDI fields/box? Best regards, Detefon expandcollapse popup#include-once #include <GuiButton.au3> #include <Array.au3> #include <Misc.au3> #include <GuiScrollBars.au3> #include <GuiconstantsEx.au3> #include <WindowsConstants.au3> #include <ScrollBarConstants.au3> ;~ #include <Fred_Code.au3> ;~ #include <object_dump.au3> #cs 72 dpi (web) = 595 X 842 pixels 300 dpi (print) = 2480 X 3508 pixels (This is "A4" as I know it, i.e. "210mm X 297mm @ 300 dpi") 600 dpi (print) = 4960 X 7016 pixels html,body{ height:297mm; width:210mm; } @page { size: 21cm 29.7cm; margin: 30mm 45mm 30mm 45mm; /* change the margins as you want them to be. */ } #ce Global $oPage = ObjCreate("Scripting.Dictionary") $oPage.Add("resolution", ObjCreate("Scripting.Dictionary")) $oPage.Item("resolution").Add("200 dpi", ObjCreate("Scripting.Dictionary")) $oPage.Item("resolution").Item("200 dpi").Add("width", 1654) $oPage.Item("resolution").Item("200 dpi").Add("height", 2339) $oPage.Item("resolution").Item("200 dpi").Add("margin", ObjCreate("Scripting.Dictionary")) $oPage.Item("resolution").Item("200 dpi").Item("margin").Add("up", 18) $oPage.Item("resolution").Item("200 dpi").Item("margin").Add("bottom", 18) $oPage.Item("resolution").Item("200 dpi").Item("margin").Add("left", 18) $oPage.Item("resolution").Item("200 dpi").Item("margin").Add("right", 18) $oPage.Add("step", 22) $oPage.Add("menu", ObjCreate("Scripting.Dictionary")) $oPage.Add("dot", ObjCreate("Scripting.Dictionary")) $oPage.Add("config", ObjCreate("Scripting.Dictionary")) $oPage.Item("config").Add("font_size", 11) $oPage.Item("config").Add("font_name", "Courier New") $oPage.Item("config").Add("font_color", 0x000000) $oPage.Item("config").Add("font_weight", 100) $oPage.Item("config").Add("font_italic", 0) $oPage.Item("config").Add("font_underline", 0) $oPage.Item("config").Add("font_strike", 0) $oPage.Item("config").Add("bk_color", 0xE4E4E4) Global $oData = ObjCreate("Scripting.Dictionary") $oData.Add("color", ObjCreate("Scripting.Dictionary")) $oData.Item("color").Add("red", "vermelho") $oData.Item("color").Add("blue", "azul") $oData.Item("color").Add("black", "preto") $oData.Item("color").Add("yellow", "amarelo") $oData.Add("number", ObjCreate("Scripting.Dictionary")) $oData.Item("number").Add("one", "um") $oData.Item("number").Add("two", "dois") $oData.Item("number").Add("three", "três") Global $oFunction = ObjCreate("Scripting.Dictionary") $oFunction.Item("data").Add("hour", "@hour") OnAutoItExitRegister("_EXIT_BEFORE") Opt("GUIOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("MustDeclareVars", 1) Opt("WinWaitDelay", 25) Global Const $bDEBUG = True Global $hGui[3], $hMsg ;~ Global $hGraphic, $hPen, $hBitmap, $hBackbuffer Global $aGuiSizeMain[8] = [10, 10, 10, 10, 1675, 768, -1, -1] Global $aGuiSizeSec[8] = [10, 10, 10, 10, $oPage.Item("resolution").Item("200 dpi").Item("width"), 500, 10, 235] Global $aGraSize[4] = [10, 10, 480, 360] Global $hMenu[3] Global $iPasso = 20 Global $g_hMouseOverControl = 0 Global $g_aScrollAmounts_GuiScroll[1][3] = [[1]] $hGui[1] = GUICreate("Título", $aGuiSizeMain[4], $aGuiSizeMain[5], -1, -1, Default, $WS_EX_COMPOSITED) GUISetOnEvent($GUI_EVENT_CLOSE, "_exit") GUISetBkColor(0xD6D3CE, $hGui[1]) GUISetState(@SW_SHOWNORMAL, $hGui[1]) $hMenu[0] = GUICtrlCreateMenu("Arquivo") $hMenu[1] = GUICtrlCreateMenu("&Campos") __BuildMenu($hMenu[1], $oData) Func __BuildMenu($hMenu, $oData) Local $hMenuItem, $hMenuSubItem For $each In $oData.Keys $hMenuItem = GUICtrlCreateMenu($each, $hMenu, 1) For $each2 In $oData.Item($each) $hMenuSubItem = GUICtrlCreateMenuItem($each2, $hMenuItem) GUICtrlSetOnEvent($hMenuSubItem, "menu") Local $oo = ObjCreate("Scripting.Dictionary") $oo.Add("item", $each) $oo.Add("subitem", $each2) $oPage.Item("menu").Add($hMenuSubItem, $oo) Next Next EndFunc ;==>__BuildMenu Func menu() If $bDEBUG Then ConsoleWrite("#Func menu( $sInput=" & @GUI_CtrlId & " )" & @LF) ConsoleWrite("" & $oPage.Item("menu").Item(@GUI_CtrlId).Item("item") & "/" & $oPage.Item("menu").Item(@GUI_CtrlId).Item("subitem") & @LF) dot_add() EndFunc ;==>menu Func dot_add() Local $oo = ObjCreate("Scripting.Dictionary") $oo.Add("x", 20) $oo.Add("y", 20) $oo.Add("width", 160) $oo.Add("height", 22) $oo.Add("path", @GUI_CtrlId) $oo.Add("label", $oPage.Item("menu").Item(@GUI_CtrlId).Item("item") & "/" & $oPage.Item("menu").Item(@GUI_CtrlId).Item("subitem")) $oo.Add("style", 0) $oo.Add("font_size", $oPage.Item("config").Item("font_size")) $oo.Add("font_name", $oPage.Item("config").Item("font_name")) $oo.Add("font_color", $oPage.Item("config").Item("font_color")) $oo.Add("font_weight", $oPage.Item("config").Item("font_weight")) $oo.Add("font_italic", $oPage.Item("config").Item("font_italic")) $oo.Add("font_underline", $oPage.Item("config").Item("font_underline")) $oo.Add("font_strike", $oPage.Item("config").Item("font_strike")) $oo.Add("bk_color", $oPage.Item("config").Item("bk_color")) Local $l_hDot = GUICtrlCreateLabel($oo.Item("label"), $oo.Item("x"), $oo.Item("y"), $oo.Item("width"), $oo.Item("height")) Local $iAttribute = Number($oPage.Item("config").Item("font_italic") + $oPage.Item("config").Item("font_underline") + $oPage.Item("config").Item("font_strike")) GUICtrlSetFont($l_hDot, $oPage.Item("config").Item("font_size"), $oPage.Item("config").Item("font_weight"), $iAttribute, $oPage.Item("config").Item("font_name"), $CLEARTYPE_QUALITY) ConsoleWrite("Adicionar[ " & $l_hDot & " ]" & @LF) GUICtrlSetColor($l_hDot, $oo.Item("font_color")) GUICtrlSetBkColor($l_hDot, $oo.Item("bk_color")) Local $l_hDotContextMenu = GUICtrlCreateContextMenu($l_hDot) GUICtrlCreateMenuItem("Fonte", $l_hDotContextMenu) GUICtrlSetOnEvent(-1, "dot_font") GUICtrlCreateMenuItem("Cor de fundo", $l_hDotContextMenu) GUICtrlSetOnEvent(-1, "dot_bk_color") GUICtrlCreateMenuItem("Redimensionar", $l_hDotContextMenu) GUICtrlSetOnEvent(-1, "dot_resize") GUICtrlCreateMenuItem("", $l_hDotContextMenu) GUICtrlCreateMenuItem("Remover", $l_hDotContextMenu) GUICtrlSetOnEvent(-1, "dot_remove") GUICtrlSetState(@GUI_CtrlId, $GUI_DISABLE) $oPage.Item("dot").Add($l_hDot, $oo) EndFunc ;==>dot_add ;~ ConsoleWrite($innerHeight & @LF) $hGui[2] = GUICreate("Child", $aGuiSizeSec[4], $aGuiSizeSec[5], $aGuiSizeSec[6], $aGuiSizeSec[7], $WS_CHILD, "", $hGui[1]) Scrollbar_Create($hGui[2], $SB_VERT, $oPage.Item("resolution").Item("200 dpi").Item("height")) Scrollbar_Step($oPage.Item("step"), $hGui[2], $SB_VERT) GUISetBkColor(0xF9F9F9, $hGui[2]) GUISetState(@SW_SHOWNORMAL, $hGui[2]) GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") ;~ GUIRegisterMsg($WM_SIZE, "_WM_SIZE") GUIRegisterMsg($WM_ENTERSIZEMOVE, "_WM_ENTERSIZEMOVE") GUIRegisterMsg($WM_EXITSIZEMOVE, "_WM_EXITSIZEMOVE") Func dot_remove() If Not $g_hMouseOverControl Then Return ConsoleWrite("dot_remove[ " & $g_hMouseOverControl & " ]" & @LF) GUICtrlSetState($oPage.Item("dot").Item($g_hMouseOverControl).Item("path"), $GUI_ENABLE) GUICtrlDelete($g_hMouseOverControl) $oPage.Item("dot").Remove($g_hMouseOverControl) EndFunc ;==>dot_remove Func dot_font() If Not $g_hMouseOverControl Then Return Local $a_vFont = _ChooseFont( _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_name"), _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_size"), _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_color"), _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_weight"), _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_italic"), _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_underline"), _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_strike"), _ $hGui[2]) If Not @error Then $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_name") = $a_vFont[2] $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_size") = $a_vFont[3] $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_weight") = $a_vFont[4] $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_color") = $a_vFont[5] $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_italic") = BitAND($a_vFont[1], 2) $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_underline") = BitAND($a_vFont[1], 4) $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_strike") = BitAND($a_vFont[1], 8) Local $iAttribute = Number($oPage.Item("dot").Item($g_hMouseOverControl).Item("font_italic") + $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_underline") + $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_strike")) GUICtrlSetFont($g_hMouseOverControl, $a_vFont[3], $a_vFont[4], $iAttribute, $a_vFont[2], $CLEARTYPE_QUALITY) GUICtrlSetColor($g_hMouseOverControl, $a_vFont[7]) EndIf EndFunc ;==>dot_font Func dot_bk_color() If Not $g_hMouseOverControl Then Return Local $l_vColor = _ChooseColor( _ 2, _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("bk_color"), _ 0, _ $hGui[2] _ ) If Not @error Then GUICtrlSetBkColor($g_hMouseOverControl, $l_vColor) $oPage.Item("dot").Item($g_hMouseOverControl).Item("bk_color") = $l_vColor EndIf EndFunc ;==>dot_bk_color Func dot_resize() EndFunc ;==>dot_resize Do Scrollbar_GetPos($hGui[2], $SB_VERT) $hMsg = GUIGetCursorInfo($hGui[2]) If $hMsg[4] And Not $g_hMouseOverControl Then $g_hMouseOverControl = $hMsg[4] GUICtrlSetStyle($g_hMouseOverControl, Default, $WS_EX_STATICEDGE) ElseIf Not $hMsg[4] And $g_hMouseOverControl Then GUICtrlSetStyle($g_hMouseOverControl, Default, 0) $g_hMouseOverControl = 0 EndIf If $hMsg[2] And $hMsg[4] Then Local $oo = ObjCreate("Scripting.Dictionary") $oo.Add("x", $hMsg[0]) $oo.Add("y", $hMsg[1]) $oo.Add("handle", $hMsg[4]) Local $aSize = ControlGetPos($hGui[2], "", $hMsg[4]) $oo.Add("width", $hMsg[0] - $aSize[0]) $oo.Add("height", $hMsg[1] - $aSize[1] + $aGuiSizeSec[7]) Do $hMsg = GUIGetCursorInfo($hGui[2]) $oPage.Item("dot").Item($oo.Item("handle")).Item("x") = Int(($hMsg[0] - $oo.Item("width")) / $iPasso) * $iPasso $oPage.Item("dot").Item($oo.Item("handle")).Item("y") = Int(($hMsg[1] - $oo.Item("height")) / $iPasso) * $iPasso ControlMove($hGui[2], "", $oo.Item("handle"), $oPage.Item("dot").Item($oo.Item("handle")).Item("x"), $oPage.Item("dot").Item($oo.Item("handle")).Item("y")) Until Sleep(10) And Not $hMsg[2] EndIf Until Not Sleep(10) Func WM_MOUSEWHEEL($hWnd, $iMsg, $iwParam, $ilParam) Local $iDelta = BitShift($iwParam, 16) If $iDelta > 0 Then _SendMessage($hGui[2], $WM_VSCROLL, $SB_LINEUP) Else _SendMessage($hGui[2], $WM_VSCROLL, $SB_LINEDOWN) EndIf Return "GUI_RUNDEFMSG" EndFunc ;==>WM_MOUSEWHEEL Func _WM_ENTERSIZEMOVE() GUISetStyle(-1, $WS_EX_COMPOSITED, $hGui[1]) EndFunc ;==>_WM_ENTERSIZEMOVE Func _WM_EXITSIZEMOVE() GUISetStyle(-1, "", $hGui[1]) EndFunc ;==>_WM_EXITSIZEMOVE Func _EXIT() If $hGui[0] Then GUI_Disable() Else Exit EndIf Exit EndFunc ;==>_EXIT Func _EXIT_BEFORE($sInput = 0) If $bDEBUG Then ConsoleWrite("#Func _EXIT_BEFORE( $sInput=" & (IsDeclared("sInput") ? $sInput : "Null") & " )" & @LF) ;~ _GDIPlus_GraphicsDispose($hBackbuffer) ;~ _GDIPlus_BitmapDispose($hBitmap) ;~ _GDIPlus_PenDispose($hPen) ;~ _GDIPlus_GraphicsDispose($hGraphic) ;~ _GDIPlus_Shutdown() GUIDelete($hGui[1]) EndFunc ;==>_EXIT_BEFORE Func GUI_Enable($sTitle = "", $ll = 320, $aa = 240) $hGui[2] = GUICreate($sTitle, $ll, $aa, -1, -1, Default, Default, $hGui[1]) $hGui[0] = 1 GUISetOnEvent($GUI_EVENT_CLOSE, "_EXIT") GUISetState(@SW_DISABLE, $hGui[1]) GUISetState(@SW_SHOW, $hGui[2]) EndFunc ;==>GUI_Enable Func GUI_Disable() $hGui[0] = 0 GUISetState(@SW_ENABLE, $hGui[1]) GUISetState(@SW_SHOW, $hGui[1]) GUIDelete($hGui[2]) EndFunc ;==>GUI_Disable ;~ _GDIPlus_Startup() ;~ $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui[1]) ;~ $hBitmap = _GDIPlus_BitmapCreateFromGraphics($aGraSize[2], $aGraSize[3], $hGraphic) ;~ $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;~ $hPen = _GDIPlus_PenCreate() ;~ _GDIPlus_GraphicsClear($hBackbuffer) ;~ _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2) ;~ Global $g_aClientSize = WinGetClientSize($hGui[0]) ;~ Func _update() ;~ _GDIPlus_GraphicsClear($hBackbuffer, 0xF0FFFFFF) ;~ _box($hBackbuffer, 0, 0, 10, 10) ;~ _GDIPlus_GraphicsDrawLine($hBackbuffer, 10, 150, 390, 150, $hPen) ;~ _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, $aGraSize[0], $aGraSize[1], $aGraSize[2], $aGraSize[3]) ;~ EndFunc ;==>_update #cs @TODO dots: single, array, array segmentado alinhamento: left, right, top, botton fundo: colorido, transparente redimensionamento on the fly multi seleção de dot's bloquear/liberar dot grupo de dots macros, funções imagem: inserir, remover, editar, zoom, redimensionar relatório: salvar, carregar #ce ;~ https://www.autoitscript.com/wiki/Best_coding_practices ;~ https://www.autoitscript.com/wiki/UDF-spec ;~ #AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;~ #Tidy_Parameters=/sf #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.13.3 (beta) Author: Kip Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #cs Functions: Scrollbar_Create($hWnd, $iBar, $iMax) Scrollbar_Scroll($hWnd, $iBar, $iPos) Scrollbar_GetPos($hWnd, $iBar) Scrollbar_Step($iStep, $hWnd=0, $iBar=0) #CE Func Scrollbar_Create($hWnd, $iBar, $iMax) Local $Size = WinGetClientSize($hWnd) Switch $iBar Case $SB_HORZ $Size = $Size[0] Case $SB_VERT $Size = $Size[1] Case Else Return 0 EndSwitch ReDim $g_aScrollAmounts_GuiScroll[UBound($g_aScrollAmounts_GuiScroll) + 1][3] $g_aScrollAmounts_GuiScroll[UBound($g_aScrollAmounts_GuiScroll) - 1][0] = $hWnd $g_aScrollAmounts_GuiScroll[UBound($g_aScrollAmounts_GuiScroll) - 1][1] = $iBar $g_aScrollAmounts_GuiScroll[UBound($g_aScrollAmounts_GuiScroll) - 1][2] = $g_aScrollAmounts_GuiScroll[0][0] _GUIScrollBars_EnableScrollBar($hWnd, $iBar) _GUIScrollBars_SetScrollRange($hWnd, $iBar, 0, $iMax - 1) _GUIScrollBars_SetScrollInfoPage($hWnd, $iBar, $Size) GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL") Return $iMax EndFunc ;==>Scrollbar_Create Func Scrollbar_GetPos($hWnd, $iBar) Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $iBar) Return DllStructGetData($tSCROLLINFO, "nPos") EndFunc ;==>Scrollbar_GetPos Func Scrollbar_Scroll($hWnd, $iBar, $iPos) Local $iRound, $iCurrentPos, $tSCROLLINFO $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $iBar) $iCurrentPos = DllStructGetData($tSCROLLINFO, "nPos") DllStructSetData($tSCROLLINFO, "nPos", $iPos) DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $iBar, $tSCROLLINFO) If $iBar = $SB_VERT Then $iRound = 0 For $i = 1 To UBound($g_aScrollAmounts_GuiScroll) - 1 If $g_aScrollAmounts_GuiScroll[$i][0] = $hWnd And $g_aScrollAmounts_GuiScroll[$i][1] = $SB_VERT Then $iRound = $g_aScrollAmounts_GuiScroll[$i][2] EndIf Next If Not $iRound Then Return 0 _GUIScrollBars_ScrollWindow($hWnd, 0, Round(($iCurrentPos - $iPos) / $iRound) * $iRound) ElseIf $iBar = $SB_HORZ Then $iRound = 0 For $i = 1 To UBound($g_aScrollAmounts_GuiScroll) - 1 If $g_aScrollAmounts_GuiScroll[$i][0] = $hWnd And $g_aScrollAmounts_GuiScroll[$i][1] = $SB_HORZ Then $iRound = $g_aScrollAmounts_GuiScroll[$i][2] EndIf Next If Not $iRound Then Return 0 _GUIScrollBars_ScrollWindow($hWnd, Round(($iCurrentPos - $iPos) / $iRound) * $iRound, 0) Else Return 0 EndIf Return 1 EndFunc ;==>Scrollbar_Scroll Func Scrollbar_Step($iStep, $hWnd = 0, $iBar = 0) Local $iID If Not $hWnd Or Not $iBar Then $g_aScrollAmounts_GuiScroll[0][0] = $iStep Return 1 EndIf $iID = 0 For $i = 1 To UBound($g_aScrollAmounts_GuiScroll) - 1 If $g_aScrollAmounts_GuiScroll[$i][0] = $hWnd And $g_aScrollAmounts_GuiScroll[$i][1] = $iBar Then $iID = $i ExitLoop EndIf Next If Not $iID Then Return 0 $g_aScrollAmounts_GuiScroll[$iID][2] = $iStep Return 1 EndFunc ;==>Scrollbar_Step Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam) Local $iRound = 0 ;~ Local $index = -1, $yChar Local $yPos, $Min, $Max, $Page, $Pos, $TrackPos #forceref $Msg, $wParam, $lParam Local $nScrollCode = BitAND($wParam, 0x0000FFFF) ; Get all the vertial scroll bar information Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ) $Min = DllStructGetData($tSCROLLINFO, "nMin") $Max = DllStructGetData($tSCROLLINFO, "nMax") $Page = DllStructGetData($tSCROLLINFO, "nPage") ; Save the position for comparison later on $yPos = DllStructGetData($tSCROLLINFO, "nPos") $Pos = $yPos $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") For $i = 1 To UBound($g_aScrollAmounts_GuiScroll) - 1 If $g_aScrollAmounts_GuiScroll[$i][0] = $hWnd And $g_aScrollAmounts_GuiScroll[$i][1] = $SB_HORZ Then $iRound = $g_aScrollAmounts_GuiScroll[$i][2] EndIf Next If Not $iRound Then Return $GUI_RUNDEFMSG Switch $nScrollCode Case $SB_TOP ; user clicked the HOME keyboard key DllStructSetData($tSCROLLINFO, "nPos", $Min) Case $SB_BOTTOM ; user clicked the END keyboard key DllStructSetData($tSCROLLINFO, "nPos", $Max) Case $SB_LINEUP ; user clicked the top arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos - $iRound) Case $SB_LINEDOWN ; user clicked the bottom arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos + $iRound) Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page) Case $SB_THUMBTRACK ; user dragged the scroll box DllStructSetData($tSCROLLINFO, "nPos", Round($TrackPos / $iRound) * $iRound) EndSwitch ;~ // Set the position and then retrieve it. Due to adjustments ;~ // by Windows it may not be the same as the value set. DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) ;// If the position has changed, scroll the window and update it $Pos = DllStructGetData($tSCROLLINFO, "nPos") If Not ($Pos == $yPos) Then _GUIScrollBars_ScrollWindow($hWnd, $yPos - $Pos, 0) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_HSCROLL Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam) ;~ Local $index = -1, $yChar #forceref $Msg, $wParam, $lParam Local $iRound = 0, $yPos Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Local $Min, $Max, $Page, $Pos, $TrackPos ; Get all the vertial scroll bar information Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT) $Min = DllStructGetData($tSCROLLINFO, "nMin") $Max = DllStructGetData($tSCROLLINFO, "nMax") $Page = DllStructGetData($tSCROLLINFO, "nPage") ; Save the position for comparison later on $yPos = DllStructGetData($tSCROLLINFO, "nPos") $Pos = $yPos $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") For $i = 1 To UBound($g_aScrollAmounts_GuiScroll) - 1 If $g_aScrollAmounts_GuiScroll[$i][0] = $hWnd And $g_aScrollAmounts_GuiScroll[$i][1] = $SB_VERT Then $iRound = $g_aScrollAmounts_GuiScroll[$i][2] EndIf Next If Not $iRound Then Return $GUI_RUNDEFMSG Switch $nScrollCode Case $SB_TOP ; user clicked the HOME keyboard key DllStructSetData($tSCROLLINFO, "nPos", $Min) Case $SB_BOTTOM ; user clicked the END keyboard key DllStructSetData($tSCROLLINFO, "nPos", $Max) Case $SB_LINEUP ; user clicked the top arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos - $iRound) Case $SB_LINEDOWN ; user clicked the bottom arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos + $iRound) Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page) Case $SB_THUMBTRACK ; user dragged the scroll box DllStructSetData($tSCROLLINFO, "nPos", Round($TrackPos / $iRound) * $iRound) EndSwitch ;~ // Set the position and then retrieve it. Due to adjustments ;~ // by Windows it may not be the same as the value set. DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) ;// If the position has changed, scroll the window and update it $Pos = DllStructGetData($tSCROLLINFO, "nPos") If Not ($Pos == $yPos) Then _GUIScrollBars_ScrollWindow($hWnd, 0, $yPos - $Pos) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_VSCROLL Edited August 28, 2014 by Detefon Visit my repository Link to comment Share on other sites More sharing options...
Luigi Posted August 28, 2014 Author Share Posted August 28, 2014 (edited) I want something like this, or better than... The second GUI have a GUICtrlControlLabel above the GDIHandle. When you move a GDIBox, it moved becouse you move a GUICtrlControlLabel (it is above GDI). Is possible make something like this effect whitout GUICtrlControLabel? This is the code: expandcollapse popup;~ #AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;~ #Tidy_Parameters=/sf #AutoIt3Wrapper_UseX64=Y #include-once #include <ColorConstants.au3> #include <Array.au3> #include <Misc.au3> #include <GUIConstantsEx.au3> #include <GuiButton.au3> #include <WindowsConstants.au3> #include <GuiScrollBars.au3> #include <ScrollBarConstants.au3> #include <GDIPlus.au3> OnAutoItExitRegister("_EXIT_BEFORE") Opt("GUIOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("MustDeclareVars", 1) Opt("WinWaitDelay", 25) _GDIPlus_Startup() #Region VARIABLES Global $oPage = ObjCreate("Scripting.Dictionary") $oPage.Add("resolution", ObjCreate("Scripting.Dictionary")) $oPage.Item("resolution").Add("200 dpi", ObjCreate("Scripting.Dictionary")) $oPage.Item("resolution").Item("200 dpi").Add("width", 1654) $oPage.Item("resolution").Item("200 dpi").Add("height", 2339) $oPage.Item("resolution").Item("200 dpi").Add("margin", ObjCreate("Scripting.Dictionary")) $oPage.Item("resolution").Item("200 dpi").Item("margin").Add("up", 18) $oPage.Item("resolution").Item("200 dpi").Item("margin").Add("bottom", 18) $oPage.Item("resolution").Item("200 dpi").Item("margin").Add("left", 18) $oPage.Item("resolution").Item("200 dpi").Item("margin").Add("right", 18) $oPage.Add("step", 22) $oPage.Add("menu", ObjCreate("Scripting.Dictionary")) $oPage.Add("dot", ObjCreate("Scripting.Dictionary")) $oPage.Add("config", ObjCreate("Scripting.Dictionary")) $oPage.Item("config").Add("font_size", 11) $oPage.Item("config").Add("font_name", "Courier New") $oPage.Item("config").Add("font_color", 0xFF000000) $oPage.Item("config").Add("font_weight", 0) $oPage.Item("config").Add("font_italic", 0) $oPage.Item("config").Add("font_underline", 0) $oPage.Item("config").Add("font_strike", 0) $oPage.Item("config").Add("bk_color", 0xFFFFFF) Global $oData = ObjCreate("Scripting.Dictionary") $oData.Add("color", ObjCreate("Scripting.Dictionary")) $oData.Item("color").Add("red", "vermelho") $oData.Item("color").Add("blue", "azul") $oData.Item("color").Add("black", "preto") $oData.Item("color").Add("yellow", "amarelo") $oData.Add("number", ObjCreate("Scripting.Dictionary")) $oData.Item("number").Add("one", "um") $oData.Item("number").Add("two", "dois") $oData.Item("number").Add("three", "três") Global Const $bDEBUG = True Global $g_iGraOn = 0 Global $g_iVERTICAL = 0 Global $g_aMsg = 0 Global Enum $eHandle = 0, $eMarginLeft, $eMarginUp, $eMarginRight, $eMarginBottom, $eTitle, $eWidth, $eHeight, $eXX, $eYY, $eStyle, $eExStyle Global $g_hGraphic, $g_hPen, $g_hBitmap, $g_hBackbuffer, $g_hBrush, $g_hFont, $g_hFormat Global $g_hFamily, $tLayout Global $g_hGraphicLabel Global $g_aGUI = __GUIValues() Global $g_aGDI = __Graphic() Global Const $g_iSTEP = 80 Global Const $g_iSTEP_DOT = 5 Global $g_aScrollAmounts_GuiScroll[1][3] = [[1]] Global $hMenu[3] Global $g_hMouseOverControl = 0, $g_hMouseOverControlOld = 0 Global $hMsg #EndRegion VARIABLES $g_aGUI[0][$eHandle] = GUICreate($g_aGUI[0][$eTitle], $g_aGUI[0][$eWidth], $g_aGUI[0][$eHeight], $g_aGUI[0][$eXX], $g_aGUI[0][$eYY], $g_aGUI[0][$eStyle], $g_aGUI[0][$eExStyle]) GUISetOnEvent($GUI_EVENT_CLOSE, "_EXIT") $hMenu[0] = GUICtrlCreateMenu("Arquivo") $hMenu[1] = GUICtrlCreateMenu("&Campos") __BuildMenu($hMenu[1], $oData) Func __BuildMenu($hMenu, $oData) Local $hMenuItem, $hMenuSubItem For $each In $oData.Keys $hMenuItem = GUICtrlCreateMenu($each, $hMenu, 1) For $each2 In $oData.Item($each) $hMenuSubItem = GUICtrlCreateMenuItem($each2, $hMenuItem) GUICtrlSetOnEvent($hMenuSubItem, "menu") Local $oo = ObjCreate("Scripting.Dictionary") $oo.Add("item", $each) $oo.Add("subitem", $each2) $oPage.Item("menu").Add($hMenuSubItem, $oo) Next Next EndFunc ;==>__BuildMenu GUISetState(@SW_SHOW, $g_aGUI[0][$eHandle]) $g_aGUI[1][$eHandle] = GUICreate($g_aGUI[1][$eTitle], $g_aGUI[1][$eWidth], $g_aGUI[1][$eHeight], $g_aGUI[1][$eXX], $g_aGUI[1][$eYY], $g_aGUI[1][$eStyle], $g_aGUI[1][$eExStyle], $g_aGUI[0][$eHandle]) GUISetOnEvent($GUI_EVENT_CLOSE, "_EXIT") GUISetState(@SW_SHOW, $g_aGUI[1][$eHandle]) GUICtrlSetBkColor($g_aGUI[1][$eHandle], 0xFFFFFF) Scrollbar_Create($g_aGUI[1][$eHandle], $SB_VERT, 2339) Scrollbar_Step($g_iSTEP, $g_aGUI[1][$eHandle], $SB_VERT) $g_hGraphic = _GDIPlus_GraphicsCreateFromHWND($g_aGUI[1][$eHandle]) $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($g_aGDI[$eWidth], $g_aGDI[$eHeight], $g_hGraphic) ;~ $g_hGraphicLabel = GUICtrlCreateLabel("", $g_aGDI[$eXX], $g_aGDI[$eYY], $g_aGDI[$eWidth], $g_aGDI[$eHeight]) ;~ GUICtrlSetState($g_hGraphicLabel, $GUI_DISABLE) $g_hBackbuffer = _GDIPlus_ImageGetGraphicsContext($g_hBitmap) $g_hPen = _GDIPlus_PenCreate() $g_hBrush = _GDIPlus_BrushCreateSolid() _GDIPlus_GraphicsClear($g_hBackbuffer) _GDIPlus_GraphicsSetSmoothingMode($g_hBackbuffer, 2) $g_hFormat = _GDIPlus_StringFormatCreate() AdlibRegister("_GDIUpdate", 20) GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") GUIRegisterMsg($WM_ENTERSIZEMOVE, "_WM_ENTERSIZEMOVE") GUIRegisterMsg($WM_EXITSIZEMOVE, "_WM_EXITSIZEMOVE") While Sleep(10) ;~ $g_aMsg = GUIGetCursorInfo($g_aGUI[1][$eHandle]) ;~ Switch $g_aMsg[4] ;~ Case $g_hGraphicLabel ;~ If Not $g_iGraOn Then ;~ $g_iGraOn = True ;~ EndIf ;~ Case Else ;~ If $g_iGraOn Then ;~ $g_iGraOn = False ;~ EndIf ;~ EndSwitch Scrollbar_GetPos($g_aGUI[1][$eHandle], $SB_VERT) $hMsg = GUIGetCursorInfo($g_aGUI[1][$eHandle]) If $hMsg[4] And Not $g_hMouseOverControl Then $g_hMouseOverControl = $hMsg[4] If Not ($hMsg[4] == $g_hMouseOverControlOld) Then $g_hMouseOverControl = $hMsg[4] $g_hMouseOverControlOld = $hMsg[4] EndIf ElseIf Not $hMsg[4] And $g_hMouseOverControl Then $g_hMouseOverControl = 0 EndIf If Not ($hMsg[4] == $g_hMouseOverControlOld) Then $g_hMouseOverControl = $hMsg[4] $g_hMouseOverControlOld = $hMsg[4] EndIf If $hMsg[2] And $hMsg[4] Then Local $oo = ObjCreate("Scripting.Dictionary") $oo.Add("x", $hMsg[0]) $oo.Add("y", $hMsg[1]) $oo.Add("handle", $hMsg[4]) Local $aSize = ControlGetPos($g_aGUI[1][$eHandle], "", $hMsg[4]) $oo.Add("width", $hMsg[0] - $aSize[0]) $oo.Add("height", $hMsg[1] - $aSize[1]) Do $hMsg = GUIGetCursorInfo($g_aGUI[1][$eHandle]) $oPage.Item("dot").Item($oo.Item("handle")).Item("x") = Int(($hMsg[0] - $oo.Item("width")) / $g_iSTEP_DOT) * $g_iSTEP_DOT $oPage.Item("dot").Item($oo.Item("handle")).Item("y") = Int(($hMsg[1] - $oo.Item("height")) / $g_iSTEP_DOT) * $g_iSTEP_DOT ControlMove($g_aGUI[1][$eHandle], "", $oo.Item("handle"), $oPage.Item("dot").Item($oo.Item("handle")).Item("x"), $oPage.Item("dot").Item($oo.Item("handle")).Item("y")) Until Sleep(10) And Not $hMsg[2] EndIf WEnd Func menu() If $bDEBUG Then ConsoleWrite("#Func menu( $sInput=" & @GUI_CtrlId & " )" & @LF) ConsoleWrite("" & $oPage.Item("menu").Item(@GUI_CtrlId).Item("item") & "/" & $oPage.Item("menu").Item(@GUI_CtrlId).Item("subitem") & @LF) dot_add() EndFunc ;==>menu Func dot_add() Local $oo = ObjCreate("Scripting.Dictionary") $oo.Add("x", 20) $oo.Add("y", 20) $oo.Add("width", 160) $oo.Add("height", 22) $oo.Add("path", @GUI_CtrlId) $oo.Add("label", $oPage.Item("menu").Item(@GUI_CtrlId).Item("item") & "/" & $oPage.Item("menu").Item(@GUI_CtrlId).Item("subitem")) $oo.Add("style", 0) $oo.Add("font_size", $oPage.Item("config").Item("font_size")) $oo.Add("font_name", $oPage.Item("config").Item("font_name")) $oo.Add("font_color", $oPage.Item("config").Item("font_color")) $oo.Add("font_weight", $oPage.Item("config").Item("font_weight")) $oo.Add("font_italic", $oPage.Item("config").Item("font_italic")) $oo.Add("font_underline", $oPage.Item("config").Item("font_underline")) $oo.Add("font_strike", $oPage.Item("config").Item("font_strike")) $oo.Add("bk_color", $oPage.Item("config").Item("bk_color")) Local $l_hDot = GUICtrlCreateLabel("", $oo.Item("x"), $oo.Item("y"), $oo.Item("width"), $oo.Item("height")) Local $iAttribute = Number($oPage.Item("config").Item("font_italic") + $oPage.Item("config").Item("font_underline") + $oPage.Item("config").Item("font_strike")) ;~ GUICtrlSetFont($l_hDot, $oPage.Item("config").Item("font_size"), $oPage.Item("config").Item("font_weight"), $iAttribute, $oPage.Item("config").Item("font_name"), $CLEARTYPE_QUALITY) ConsoleWrite("Adicionar[ " & $l_hDot & " ]" & @LF) ;~ GUICtrlSetColor($l_hDot, $oo.Item("font_color")) GUICtrlSetBkColor($l_hDot, 0xFFFFFF) Local $l_hDotContextMenu = GUICtrlCreateContextMenu($l_hDot) GUICtrlCreateMenuItem("Fonte", $l_hDotContextMenu) GUICtrlSetOnEvent(-1, "dot_font") GUICtrlCreateMenuItem("Cor de fundo", $l_hDotContextMenu) GUICtrlSetOnEvent(-1, "dot_bk_color") GUICtrlCreateMenuItem("Redimensionar", $l_hDotContextMenu) GUICtrlSetOnEvent(-1, "dot_resize") GUICtrlCreateMenuItem("", $l_hDotContextMenu) GUICtrlCreateMenuItem("Remover", $l_hDotContextMenu) GUICtrlSetOnEvent(-1, "dot_remove") GUICtrlSetState(@GUI_CtrlId, $GUI_DISABLE) $oPage.Item("dot").Add($l_hDot, $oo) EndFunc ;==>dot_add Func dot_remove() If Not $g_hMouseOverControl Then Return ConsoleWrite("dot_remove[ " & $g_hMouseOverControl & " ]" & @LF) GUICtrlSetState($oPage.Item("dot").Item($g_hMouseOverControl).Item("path"), $GUI_ENABLE) GUICtrlDelete($g_hMouseOverControl) $oPage.Item("dot").Remove($g_hMouseOverControl) EndFunc ;==>dot_remove Func dot_font() If Not $g_hMouseOverControl Then Return Local $a_vFont = _ChooseFont( _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_name"), _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_size"), _ RGB_TO_BGR(ARGB_TO_RGB($oPage.Item("dot").Item($g_hMouseOverControl).Item("font_color"))), _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_weight") == 0 ? 400 : 700, _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_italic"), _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_underline"), _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_strike"), _ $g_aGUI[1][$eHandle]) If Not @error Then $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_name") = $a_vFont[2] $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_size") = Number($a_vFont[3]) $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_weight") = (Number($a_vFont[4]) == 400 ? 0 : 1) $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_color") = RGB_TO_ARGB(RGB_TO_BGR($a_vFont[5])) $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_italic") = Number(BitAND($a_vFont[1], 2)) $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_underline") = Number(BitAND($a_vFont[1], 4)) $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_strike") = Number(BitAND($a_vFont[1], 8)) Local $iAttribute = Number($oPage.Item("dot").Item($g_hMouseOverControl).Item("font_italic") + $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_underline") + $oPage.Item("dot").Item($g_hMouseOverControl).Item("font_strike")) ConsoleWrite("a[ " & $a_vFont[5] & " ]" & @LF) ConsoleWrite("b[ " & $a_vFont[6] & " ]" & @LF) ConsoleWrite("c[ " & $a_vFont[7] & " ]" & @LF) EndIf EndFunc ;==>dot_font Func dot_bk_color() If Not $g_hMouseOverControl Then Return Local $l_vColor = _ChooseColor( _ 2, _ $oPage.Item("dot").Item($g_hMouseOverControl).Item("bk_color"), _ 0, _ $g_aGUI[0][$eHandle] _ ) If Not @error Then GUICtrlSetBkColor($g_hMouseOverControl, $l_vColor) $oPage.Item("dot").Item($g_hMouseOverControl).Item("bk_color") = $l_vColor EndIf EndFunc ;==>dot_bk_color Func dot_resize() EndFunc ;==>dot_resize Func WM_MOUSEWHEEL($hWnd, $iMsg, $iwParam, $ilParam) Local $iDelta = BitShift($iwParam, 16) If $iDelta > 0 Then _SendMessage($g_aGUI[1][$eHandle], $WM_VSCROLL, $SB_LINEUP) Else _SendMessage($g_aGUI[1][$eHandle], $WM_VSCROLL, $SB_LINEDOWN) EndIf Return "GUI_RUNDEFMSG" EndFunc ;==>WM_MOUSEWHEEL Func _WM_ENTERSIZEMOVE() GUISetStyle(-1, $WS_EX_COMPOSITED, $g_aGUI[1][$eHandle]) EndFunc ;==>_WM_ENTERSIZEMOVE Func _WM_EXITSIZEMOVE() GUISetStyle(-1, "", $g_aGUI[1][$eHandle]) EndFunc ;==>_WM_EXITSIZEMOVE Func __GUIValues() Local $aMargin[4] = [10, 10, 10, 10] Local $g_aGUI[2][12] = [ _ [0, $aMargin[0], $aMargin[1], $aMargin[2], $aMargin[3], "Main", 1692, 120, 0, 0, Default, $WS_EX_COMPOSITED], _ [0, $aMargin[0], $aMargin[1], $aMargin[2], $aMargin[3], "SEC ", 1670, 500, 0, 0, $WS_POPUP, Default] _ ] $g_aGUI[0][$eXX] = Int((@DesktopWidth - $g_aGUI[0][$eWidth]) / 2) $g_aGUI[0][$eYY] = $g_aGUI[0][$eXX] $g_aGUI[1][$eXX] = Int((@DesktopWidth - $g_aGUI[0][$eWidth]) / 2) $g_aGUI[1][$eYY] = $g_aGUI[0][$eXX] + $g_aGUI[0][$eYY] + 41 Return $g_aGUI EndFunc ;==>__GUIValues Func __Graphic() Local $aValues[12] = [0, 0, 0, 0, 1, 0, 1654, 500, 0, 0, 0, 0] Return $aValues EndFunc ;==>__Graphic Func _EXIT() Exit EndFunc ;==>_EXIT Func _EXIT_BEFORE($sInput = 0) If $bDEBUG Then ConsoleWrite("#Func _exit( $sInput=" & (IsDeclared("sInput") ? $sInput : "Null") & " )" & @LF) _GDIPlus_StringFormatDispose($g_hFormat) _GDIPlus_FontFamilyDispose($g_hFamily) _GDIPlus_GraphicsDispose($g_hBackbuffer) _GDIPlus_BitmapDispose($g_hBitmap) _GDIPlus_PenDispose($g_hPen) _GDIPlus_GraphicsDispose($g_hGraphic) _GDIPlus_Shutdown() GUIDelete($g_aGUI[1][$eHandle]) GUIDelete($g_aGUI[0][$eHandle]) EndFunc ;==>_EXIT_BEFORE Func _GDIUpdate() _GDIPlus_GraphicsClear($g_hBackbuffer, 0xFFFFFFFF) For $each In $oPage.Item("dot") _GDIPlus_Box($g_hBackbuffer, $oPage.Item("dot").Item($each).Item("x"), $oPage.Item("dot").Item($each).Item("y") + $g_iVERTICAL, $oPage.Item("dot").Item($each).Item("width"), $oPage.Item("dot").Item($each).Item("height"), ($g_hMouseOverControl == $each ? 0xFF00FF00 : 0xFF0000FF)) ;~ ConsoleWrite(">" & $oPage.Item("dot").Item($each).Item("font_color") & @LF) _GDIPlus_Text($g_hBackbuffer, _ $oPage.Item("dot").Item($each).Item("label"), _ $oPage.Item("dot").Item($each).Item("font_name"), _ $oPage.Item("dot").Item($each).Item("font_size"), _ Number($oPage.Item("dot").Item($each).Item("font_weight") + $oPage.Item("dot").Item($each).Item("font_italic") + $oPage.Item("dot").Item($each).Item("font_underline") + $oPage.Item("dot").Item($each).Item("font_strike")), _ $oPage.Item("dot").Item($each).Item("x"), _ $oPage.Item("dot").Item($each).Item("y") + $g_iVERTICAL, _ $oPage.Item("dot").Item($each).Item("width"), _ $oPage.Item("dot").Item($each).Item("height"), _ $oPage.Item("dot").Item($each).Item("font_color") _ ) Next _GDIPlus_Box($g_hBackbuffer, 64, 64 + $g_iVERTICAL, 128, 128) _GDIPlus_GraphicsDrawLine($g_hBackbuffer, 10, 150 + $g_iVERTICAL, 390, 150 + $g_iVERTICAL, $g_hPen) _GDIPlus_GraphicsDrawImageRect($g_hGraphic, $g_hBitmap, $g_aGDI[$eXX], $g_aGDI[$eYY], $g_aGDI[$eWidth], $g_aGDI[$eHeight]) EndFunc ;==>_GDIUpdate Func _GDIPlus_Text($hGraphic, $text, $font, $size, $properties, $xx, $yy, $ll, $aa, $color = 0xFFFFFFFF) ;~ ConsoleWrite("_GDIPlus_Text( $hGraphic=" & $hGraphic & ", $text=" & $text & ", $font=" & $font & ", $size=" & $size & ", $properties=" & $properties & ", $xx=" & $xx & ", $yy=" & $yy & ", $ll=" & $ll & ", $aa=" & $aa & ", $color=" & $color & " )" & @LF) Local $hGUI, $hBrush, $hFormat, $hFamily, $hFont, $aInfo $hBrush = _GDIPlus_BrushCreateSolid($color) $hFormat = _GDIPlus_StringFormatCreate() $hFamily = _GDIPlus_FontFamilyCreate($font) $hFont = _GDIPlus_FontCreate($hFamily, $size, $properties) $tLayout = _GDIPlus_RectFCreate($xx, $yy, $ll, $aa) $aInfo = _GDIPlus_GraphicsMeasureString($g_hBackbuffer, $text, $hFont, $tLayout, $hFormat) If IsArray($aInfo) Then _GDIPlus_GraphicsDrawStringEx($g_hBackbuffer, $text, $hFont, $aInfo[0], $hFormat, $hBrush) Else EndIf EndFunc ;==>_GDIPlus_Text Func _GDIPlus_Box($hToGraphic, $xx, $yy, $iWidth, $iHeight, $color = 0xFF000000) ; _GDIPlus_Box2 Local $aBox[5][2] $aBox[0][0] = 4 $aBox[1][0] = $xx $aBox[1][1] = $yy $aBox[2][0] = $xx + $iWidth - 1 $aBox[2][1] = $yy $aBox[3][0] = $xx + $iWidth - 1 $aBox[3][1] = $yy + $iHeight - 1 $aBox[4][0] = $xx $aBox[4][1] = $yy + $iHeight - 1 If $color Then _GDIPlus_PenSetColor($g_hPen, $color) _GDIPlus_GraphicsDrawPolygon($hToGraphic, $aBox, $g_hPen) Else _GDIPlus_GraphicsDrawPolygon($hToGraphic, $aBox) EndIf EndFunc ;==>_GDIPlus_Box Func Scrollbar_Create($hWnd, $iBar, $iMax) Local $size = WinGetClientSize($hWnd) Switch $iBar Case $SB_HORZ $size = $size[0] Case $SB_VERT $size = $size[1] Case Else Return 0 EndSwitch ReDim $g_aScrollAmounts_GuiScroll[UBound($g_aScrollAmounts_GuiScroll) + 1][3] $g_aScrollAmounts_GuiScroll[UBound($g_aScrollAmounts_GuiScroll) - 1][0] = $hWnd $g_aScrollAmounts_GuiScroll[UBound($g_aScrollAmounts_GuiScroll) - 1][1] = $iBar $g_aScrollAmounts_GuiScroll[UBound($g_aScrollAmounts_GuiScroll) - 1][2] = $g_aScrollAmounts_GuiScroll[0][0] _GUIScrollBars_EnableScrollBar($hWnd, $iBar) _GUIScrollBars_SetScrollRange($hWnd, $iBar, 0, $iMax - 1) _GUIScrollBars_SetScrollInfoPage($hWnd, $iBar, $size) GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") Return $iMax EndFunc ;==>Scrollbar_Create Func Scrollbar_GetPos($hWnd, $iBar) Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $iBar) Return DllStructGetData($tSCROLLINFO, "nPos") EndFunc ;==>Scrollbar_GetPos Func Scrollbar_Scroll($hWnd, $iBar, $iPos) Local $iRound, $iCurrentPos, $tSCROLLINFO $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $iBar) $iCurrentPos = DllStructGetData($tSCROLLINFO, "nPos") DllStructSetData($tSCROLLINFO, "nPos", $iPos) DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $iBar, $tSCROLLINFO) If $iBar = $SB_VERT Then $iRound = 0 For $i = 1 To UBound($g_aScrollAmounts_GuiScroll) - 1 If $g_aScrollAmounts_GuiScroll[$i][0] = $hWnd And $g_aScrollAmounts_GuiScroll[$i][1] = $SB_VERT Then $iRound = $g_aScrollAmounts_GuiScroll[$i][2] EndIf Next If Not $iRound Then Return 0 _GUIScrollBars_ScrollWindow($hWnd, 0, Round(($iCurrentPos - $iPos) / $iRound) * $iRound) ElseIf $iBar = $SB_HORZ Then $iRound = 0 For $i = 1 To UBound($g_aScrollAmounts_GuiScroll) - 1 If $g_aScrollAmounts_GuiScroll[$i][0] = $hWnd And $g_aScrollAmounts_GuiScroll[$i][1] = $SB_HORZ Then $iRound = $g_aScrollAmounts_GuiScroll[$i][2] EndIf Next If Not $iRound Then Return 0 _GUIScrollBars_ScrollWindow($hWnd, Round(($iCurrentPos - $iPos) / $iRound) * $iRound, 0) Else Return 0 EndIf Return 1 EndFunc ;==>Scrollbar_Scroll Func Scrollbar_Step($iStep, $hWnd = 0, $iBar = 0) Local $iID If Not $hWnd Or Not $iBar Then $g_aScrollAmounts_GuiScroll[0][0] = $iStep Return 1 EndIf $iID = 0 For $i = 1 To UBound($g_aScrollAmounts_GuiScroll) - 1 If $g_aScrollAmounts_GuiScroll[$i][0] = $hWnd And $g_aScrollAmounts_GuiScroll[$i][1] = $iBar Then $iID = $i ExitLoop EndIf Next If Not $iID Then Return 0 $g_aScrollAmounts_GuiScroll[$iID][2] = $iStep Return 1 EndFunc ;==>Scrollbar_Step Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $wParam, $lParam Local $iRound = 0, $yPos Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Local $Min, $Max, $Page, $Pos, $TrackPos ; Get all the vertial scroll bar information Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT) $Min = DllStructGetData($tSCROLLINFO, "nMin") $Max = DllStructGetData($tSCROLLINFO, "nMax") $Page = DllStructGetData($tSCROLLINFO, "nPage") ; Save the position for comparison later on $yPos = DllStructGetData($tSCROLLINFO, "nPos") $Pos = $yPos $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") For $i = 1 To UBound($g_aScrollAmounts_GuiScroll) - 1 If $g_aScrollAmounts_GuiScroll[$i][0] = $hWnd And $g_aScrollAmounts_GuiScroll[$i][1] = $SB_VERT Then $iRound = $g_aScrollAmounts_GuiScroll[$i][2] EndIf Next If Not $iRound Then Return $GUI_RUNDEFMSG Switch $nScrollCode Case $SB_TOP ; user clicked the HOME keyboard key DllStructSetData($tSCROLLINFO, "nPos", $Min) Case $SB_BOTTOM ; user clicked the END keyboard key DllStructSetData($tSCROLLINFO, "nPos", $Max) Case $SB_LINEUP ; user clicked the top arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos - $iRound) Case $SB_LINEDOWN ; user clicked the bottom arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos + $iRound) Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page) Case $SB_THUMBTRACK ; user dragged the scroll box DllStructSetData($tSCROLLINFO, "nPos", Round($TrackPos / $iRound) * $iRound) EndSwitch ;~ // Set the position and then retrieve it. Due to adjustments ;~ // by Windows it may not be the same as the value set. DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) ;// If the position has changed, scroll the window and update it $Pos = DllStructGetData($tSCROLLINFO, "nPos") If Not ($Pos == $yPos) Then $g_iVERTICAL += ($yPos - $Pos) Return $GUI_RUNDEFMSG EndFunc ;==>WM_VSCROLL Func GUI_Disable() ;~ $hGui[0] = 0 ;~ GUISetState(@SW_ENABLE, $hGui[1]) ;~ GUISetState(@SW_SHOW, $hGui[1]) ;~ GUIDelete($g_aGUI[1][$eHandle]) EndFunc ;==>GUI_Disable Func ARGB_TO_RGB($iInput = 0) ; convert ALPHA-RGB to RGB Return Number("0x" & StringRight(Hex($iInput, 8), 6)) EndFunc FUNC RGB_TO_ARGB($iInput = 0) ; convert RGB to ALPHA-RGB Return Number("0xFF" & StringRight(Hex($iInput, 8), 6)) EndFunc Func RGB_TO_BGR($iInput) $iInput = Hex($iInput, 6) Return Number("0x" & StringMid($iInput, 5, 2) & StringMid($iInput, 3, 2) & StringMid($iInput, 1, 2)) EndFunc ;==>RGB_TO_BGR Func BGR_TO_RGB($iInput) $iInput = Hex($iInput, 6) Return Number("0x" & StringMid($iInput, 5, 2) & StringMid($iInput, 3, 2) & StringMid($iInput, 1, 2)) EndFunc ;==>BGR_TO_RGB Edited August 28, 2014 by Detefon Visit my repository Link to comment Share on other sites More sharing options...
martin Posted August 30, 2014 Share Posted August 30, 2014 If you want to move items which have been drawn, which amounts to redrawing evrything with the moved item in the new place, then I think there is no choice but to use the mouse X,Y position and work everything out and use double buffering for your graphics. I think you need something like this pseudocode. global $arrayOfElements[100];to be redimed as needed Global $ElementCount, $hovered func createItemType1 $Elementcount += 1; $arrayOfElements[$ElementCount] = createItem1 endfunc func drawAll clearcanvas for $n = 1 to $ElementCount drawelement($arrayOfElements[$n) next endfunc func OnMouseMove if not $mousedown for $n = 1 to $ElementCount if isInItem($arrayOfElements[$n]) then $hovered = $n next else if mousexy <> lastmousexy then setnewpos($arrayOfElements[$hovered],lastmousexy, mousexy) drawall endif endfunc func onMouseDown $Mousedown = true endfunc func onMouseUp $Mousedown = false endfunc For the function isInItem then >Malkey has done some work on this. Every item created would have to have some border set as a set of lines or points to make an enclosed shape. Then Malkeys functions can be used to see if the x,y coord is inside an item. There are example in that thread showing how you can detect a cursor is inside different shapes. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
nitekram Posted June 18, 2015 Share Posted June 18, 2015 Does anyone have the link that was provided for Malkey example - I have looked but unable to locate - thanks 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
LarsJ Posted June 18, 2015 Share Posted June 18, 2015 I think it's Check if a point is within various defined closed shapes Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
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