Jump to content

Alek

Active Members
  • Posts

    323
  • Joined

  • Last visited

Profile Information

  • Location
    Norway

Recent Profile Visitors

741 profile views

Alek's Achievements

Universalist

Universalist (7/7)

3

Reputation

  1. StringIsInt should do the job edit: argh, too slow
  2. Not sure about enableing/disabeling the checkbox but here is a example (from the help file) of a listview with checkbox #include <GuiListView.au3> Opt('MustDeclareVars', 1) $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work _Main() Func _Main() Local $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES), $hListView GUICreate("ListView Set Item Checked State", 400, 300) $hListView = GUICtrlCreateListView("", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($hListView, $exStyles) GUISetState() ; Add columns _GUICtrlListView_AddColumn($hListView, "Column 1", 100) _GUICtrlListView_AddColumn($hListView, "Column 2", 100) _GUICtrlListView_AddColumn($hListView, "Column 3", 100) ; Add items _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2) _GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1) _GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2) ; Check item 2 _GUICtrlListView_SetItemChecked($hListView, 1) MsgBox(4160, "Information", "Item 2 Checked: " & _GUICtrlListView_GetItemChecked($hListView, 1)) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main
  3. not sure 100% sure what you are asking for, but something like this?? #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> $Form = GUICreate("Hello", 800, 480, -1, -1, BitOR($WS_SYSMENU, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_THICKFRAME, $WS_CLIPSIBLINGS)) $Listview = GUICtrlCreateListView("Test 1|Test 2|Test 3", 10, 10, 780, 435, -1) GUICtrlSetResizing($Listview, BitOR($GUI_DOCKLEFT, $GUI_DOCKRIGHT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM)) GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) Local $width = BitAND($lParam, 0x0000FFFF) - 22 _GUICtrlListView_SetColumnWidth($Listview, 0, $width / 3) _GUICtrlListView_SetColumnWidth($Listview, 1, $width / 3) _GUICtrlListView_SetColumnWidth($Listview, 2, $width / 3) EndFunc
  4. you need to register the WM_PAINT event #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Gdiplus.au3> _GDIPlus_Startup() $Form = GUICreate("Hello world", 400, 400) GUISetState() $Main_Graphics = _GDIPlus_GraphicsCreateFromHWND($Form) _GDIPlus_GraphicsDrawLine($Main_Graphics, 0, 200, 400, 200) GUIRegisterMsg($WM_PAINT, "WM_PAINT") While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _GDIPlus_GraphicsDispose($Main_Graphics) _GDIPlus_Shutdown() Func WM_PAINT($hWnd, $nMsg, $wParam, $lParam) _GDIPlus_GraphicsDrawLine($Main_Graphics, 0, 200, 400, 200) EndFunc
  5. hmm, thats weird it uses 11% cpu on my system but changing it from mouseclick to mousedown mouseup uses < 1% While True Sleep(15) MouseDown("Left") MouseUp("Left") WEnd Edit: its due to MouseClickDelay and MouseClickDownDelay, changing them to 0 or 15+ makes the cpu usage drop.
  6. Was diging trough some old scrips and I found my old multi-process lan scanner and I thought it would be a nice script for the example forum How it works: the main script runs another script with a few parameters (IP and main scripts form handle) and the other script executes the ping command and uses SendMessage to send the result back to the main script. Orignaly the main script just re-ran it self with the same parameters but it was to much of a cpu and memory hog so I had to create a seperate script for the pinging. so here it is main script. #include <iNet.au3> #Include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <GuiStatusBar.au3> Global $ProcLimit = RegRead("HKEY_CURRENT_USER\Software\LanScanner\Settings","ProcessLimit") Global $UseExternalPinger = False If $ProcLimit = 0 Then $ProcLimit = 20 EndIf #Region RealPing.au3 #Include <SendMessage.au3> #NoTrayIcon Global $PingTimeout = RegRead("HKEY_CURRENT_USER\Software\LanScanner\Settings","PingTimeout") If $PingTimeout = 0 Then $PingTimeout = 1000 EndIf If $Cmdline[0] = 2 Then $ping = Ping($Cmdline[1], $PingTimeout) If $ping = 0 Then _SendMessage($Cmdline[2], 0x0F01) Else _SendMessage($Cmdline[2], 0x0F00, _IpToHex($Cmdline[1]), String($ping)) EndIf Exit EndIf Func _IpToHex($Ip) Local $array = StringSplit($Ip, ".") Return "0x" & Hex($array[1], 2) & Hex($array[2], 2) & Hex($array[3], 2) & Hex($array[4], 2) EndFunc #EndRegion TCPStartup() Global $RunTimer = 0 $Form = GUICreate("Lan scanner", 470, 175) $Menu_File = GUICtrlCreateMenu("&File") $Menu_Exit = GUICtrlCreateMenuItem("&Exit", $Menu_File) $Menu_Tools = GUICtrlCreateMenu("&Tools") $Menu_Settings = GUICtrlCreateMenuItem("&Settings", $Menu_Tools) $ListView =_GUICtrlListView_Create($Form, "IP|Name|Ping", 10, 10, 290, 115) _GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_FULLROWSELECT,$LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES)) GUICtrlCreateLabel("Start IP:", 310, 13) $Input1 = GUICtrlCreateInput(@IPAddress1, 360, 10, 100) GUICtrlCreateLabel("End IP:", 310, 43) $Input2 = GUICtrlCreateInput(@IPAddress1, 360, 40, 100) $Button1 = GUICtrlCreateButton("Start", 310, 70, 150, 25) $Progress1 = GUICtrlCreateProgress(4, 0, -1, -1) _GUICtrlListView_SetColumnWidth($Listview, 0, 100) _GUICtrlListView_SetColumnWidth($Listview, 1, 150) _GUICtrlListView_SetColumnWidth($Listview, 2, 40) $StatusBar = _GUICtrlStatusBar_Create($Form) Dim $StatusBar_Parts[4] = [150, 250, 370, -1] _GUICtrlStatusBar_SetParts ($StatusBar, $StatusBar_Parts) _GUICtrlStatusBar_SetText($StatusBar, "Running Process: 0") _GUICtrlStatusBar_SetText($StatusBar, "IP: ", 1) _GUICtrlStatusBar_EmbedControl($StatusBar, 3, GUICtrlGetHandle($Progress1)) GUIRegisterMsg(0x0F00, "_PingSucess") GUIRegisterMsg(0x0F01, "_PingDone") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() $Form2 = GUICreate("Settings", 400, 190) $Label1 = GUICtrlCreateLabel("Number of active processes at one time: " & $ProcLimit, 10, 10,380, 20) $Slider1 = GUICtrlCreateSlider(10, 30, 380, 40) GUICtrlSetLimit($Slider1, 40, 0) GUICtrlSetData($Slider1, $ProcLimit / 5) $Label2 = GUICtrlCreateLabel("Ping Timeout in milliseconds: 4000", 10, 80,380, 20) $Slider2 = GUICtrlCreateSlider(10, 100, 380, 40) GUICtrlSetLimit($Slider2, 100, 1) GUICtrlSetData($Slider2, $PingTimeout / 50) $Button2 = GUICtrlCreateButton("Apply", 280, 155, 50, 25) $Button3 = GUICtrlCreateButton("Close", 340, 155, 50, 25) GUISetState(@SW_HIDE) Global $ip = 0 Dim $ProcCount = 0 Dim $Run = False Dim $SliderData1 = $ProcLimit Dim $SliderData2 = $PingTimeout While True $Msg = GUIGetMsg(1) Switch $Msg[1] Case $Form Switch $Msg[0] Case $GUI_EVENT_CLOSE, $Menu_Exit Exit Case $Button1 If $ip = 0 Then _GUICtrlListView_DeleteAllItems($Listview) $ip = GUICtrlRead($Input1) GUICtrlSetState($Input1, $GUI_DISABLE) GUICtrlSetState($Input2, $GUI_DISABLE) GUICtrlSetData($Button1, "Stop") $Run = True $RunTimer = TimerInit() Else $ip = 0 GUICtrlSetState($Input1, $GUI_ENABLE) GUICtrlSetState($Input2, $GUI_ENABLE) GUICtrlSetData($Button1, "Start") GUICtrlSetData($Progress1, 0) $Run = False EndIf Case $Menu_Settings GUISetState(@SW_SHOW, $Form2) Case Else If $Msg[0] > 0 Then ConsoleWrite($Msg[0] & @CRLF) EndSwitch Case $Form2 Switch $Msg[0] Case $GUI_EVENT_CLOSE, $Button3 GUISetState(@SW_HIDE, $Form2) Case $Button2 If GUICtrlRead($Slider1) = 0 Then RegWrite("HKEY_CURRENT_USER\Software\LanScanner\Settings","ProcessLimit", "REG_DWORD", 1) $ProcLimit = 1 Else RegWrite("HKEY_CURRENT_USER\Software\LanScanner\Settings","ProcessLimit", "REG_DWORD", GUICtrlRead($Slider1) * 5) $ProcLimit = GUICtrlRead($Slider1) * 5 EndIf RegWrite("HKEY_CURRENT_USER\Software\LanScanner\Settings","PingTimeout", "REG_DWORD", GUICtrlRead($Slider2) * 50) GUISetState(@SW_HIDE, $Form2) Case $Slider1 If GUICtrlRead($Slider1) = 0 Then GUICtrlSetData($Label1, "Number of active processes at one time: 1") Else GUICtrlSetData($Label1, "Number of active processes at one time: " & GUICtrlRead($Slider1) * 5) EndIf EndSwitch EndSwitch If $SliderData1 <> GUICtrlRead($Slider1) Then $SliderData1 = GUICtrlRead($Slider1) If GUICtrlRead($Slider1) = 0 Then GUICtrlSetData($Label1, "Number of active processes at one time: 1") Else GUICtrlSetData($Label1, "Number of active processes at one time: " & GUICtrlRead($Slider1) * 5) EndIf EndIf If $SliderData2 <> GUICtrlRead($Slider2) Then $SliderData2 = GUICtrlRead($Slider2) GUICtrlSetData($Label2,"Ping Timeout in milliseconds: " & GUICtrlRead($Slider2) * 50) EndIf If Not $Run Or $ProcCount >= $ProcLimit Then ContinueLoop If $UseExternalPinger Then ;We get signicent effincy by running a external script rather then re-running this 1. If @Compiled Then $Pid = Run("RealPing.exe" & " " & $ip & " " & $Form, @WorkingDir) Else $Pid = Run(@AutoItExe & ' "' & @ScriptDir & "\RealPing.au3" & '" ' & $ip & " " & $Form, @WorkingDir) EndIf Else If @Compiled Then $Pid = Run(@AutoItExe & " " & $ip & " " & $Form, @WorkingDir) Else $Pid = Run(@AutoItExe & ' "' & @ScriptFullPath & '" ' & $ip & " " & $Form, @WorkingDir) EndIf EndIf If $Pid <> 0 Then ;ProcessSetPriority($Pid, 0) EndIf _GUICtrlStatusBar_SetText($StatusBar, "IP: " & $ip, 1) _GUICtrlStatusBar_SetText($StatusBar, _MsToTime(TimerDiff($RunTimer)), 2) $ProcCount += 1 GUICtrlSetData($Progress1, _IPGetPercentDiff($ip, GUICtrlRead($Input2))) If _IpGetNext($ip, GUICtrlRead($Input1), GUICtrlRead($Input2)) = 1 Then $ip = 0 GUICtrlSetState($Input1, $GUI_ENABLE) GUICtrlSetState($Input2, $GUI_ENABLE) GUICtrlSetData($Button1, "Start") $Run = False EndIf _GUICtrlStatusBar_SetText($StatusBar, "Running Process: " & $ProcCount & " / " & $ProcLimit) WEnd Func _PingSucess($hWnd, $Msg, $wParam, $lParam) Local $index = _GUICtrlListView_AddItem($Listview, _HexToIp($wParam), 0) _GUICtrlListView_AddSubItem($Listview, $index, _TCPIpToName(_HexToIp($wParam)), 1) _GUICtrlListView_AddSubItem($Listview, $index, Int("0x" & Hex($lParam)), 2) $ProcCount -= 1 _GUICtrlStatusBar_SetText($StatusBar, "Running Process: " & $ProcCount & " / " & $ProcLimit) EndFunc Func _PingDone($hWnd, $Msg, $wParam, $lParam) $ProcCount -= 1 _GUICtrlStatusBar_SetText($StatusBar, "Running Process: " & $ProcCount & " / " & $ProcLimit) EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $ListView If Not IsHWnd($ListView) Then $WndListView = GUICtrlGetHandle($ListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $Index = DllStructGetData($tInfo, "Index") $subitemNR = DllStructGetData($tInfo, "SubItem") ; make sure user clicks on the listview & only the activate If $Index <> -1 Then ; col1 ITem index $item = StringSplit(_GUICtrlListView_GetItemTextString($ListView, $Index),'|') $item = $item[1] $ping = Ping($item, 1000) If $ping = 0 Then Switch @error Case 1 _GUICtrlListView_SetItemText($Listview, $Index, "Off", 2) Case 2 _GUICtrlListView_SetItemText($Listview, $Index, "Non", 2) Case 3 _GUICtrlListView_SetItemText($Listview, $Index, "Bad", 2) Case 4 _GUICtrlListView_SetItemText($Listview, $Index, "Err", 2) EndSwitch Else _GUICtrlListView_SetItemText($Listview, $Index, $ping, 2) EndIf EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _HexToIp($Hex) Local $array = StringSplit($Hex, "") If StringLeft($Hex, 2) = "0x" Then Return Int("0x" & $array[3] & $array[4]) & "." & Int("0x" & $array[5] & $array[6]) & "." & Int("0x" & $array[7] & $array[8]) & "." & Int("0x" & $array[9] & $array[10]) Else Return Int("0x" & $array[1] & $array[2]) & "." & Int("0x" & $array[3] & $array[4]) & "." & Int("0x" & $array[5] & $array[6]) & "." & Int("0x" & $array[7] & $array[8]) EndIf EndFunc Func _IpGetDiff($ip1, $ip2) Local $ret[4] If _IpGetValue($ip1) > _IpGetValue($ip2) Then Return $ret EndIf Local $array1 = StringSplit($ip1, ".") Local $array2 = StringSplit($ip2, ".") $ret[0] = $array2[1] - $array1[1] $ret[1] = $array2[2] - $array1[2] $ret[2] = $array2[3] - $array1[3] $ret[3] = $array2[4] - $array1[4] Return $ret EndFunc Func _IpGetNext(ByRef $ip, $ip1, $ip2) Local $array = _IpGetDiff($ip, $ip2) Local $iparray = _IpGetDiff("0.0.0.0", $ip) Local $iparray1 = _IpGetDiff("0.0.0.0", $ip1) If $array[3] = 0 Then If $array[2] = 0 Then If $array[1] = 0 Then If $array[0] = 0 Then Return 1 Else $iparray[0] += 1 $iparray[1] = $iparray1[1] $iparray[2] = $iparray1[2] $iparray[3] = $iparray1[3] EndIf Else $iparray[1] += 1 $iparray[2] = $iparray1[2] $iparray[3] = $iparray1[3] EndIf Else $iparray[2] += 1 $iparray[3] = $iparray1[3] EndIf Else $iparray[3] += 1 EndIf $ip = $iparray[0] & "." & $iparray[1] & "." & $iparray[2] & "." & $iparray[3] Return 0 EndFunc Func _IpGetValue($ip) Local $array = StringSplit($Ip, ".") Return $array[1] + $array[2] + $array[3] + $array[4] EndFunc Func _IPGetPercentDiff($ip, $ip2) Local $array = StringSplit($ip, ".") Local $array2 = StringSplit($ip2, ".") $array[4] = ($array[4] + 1) / ($array2[4] + 1) $array[3] = ($array[3] + 1) / ($array2[3] + 1) $array[2] = ($array[2] + 1) / ($array2[2] + 1) $array[1] = ($array[1] + 1) / ($array2[1] + 1) Return $array[4] * $array[3] * $array[2] * $array[1] * 100 EndFunc Func _Swap(ByRef $1, ByRef $2) Local $tmp = $2 $2 = $1 $1 = $tmp EndFunc Func _HwndToInt($hWnd) Return Int("0x" & Hex($hWnd)) EndFunc Func _MsToTime($ms) Local $sec = Floor($ms / 1000) Local $hour = Floor($sec / 3600) $sec -= $hour * 3600 Local $min = Floor($sec / 60) $sec-= $min * 60 Return StringFormat("%02d:%02d:%02d", $hour, $min, $sec) EndFunc Real Pinger.au3 #Include <SendMessage.au3> #NoTrayIcon Global $PingTimeout = RegRead("HKEY_CURRENT_USER\Software\LanScanner\Settings","PingTimeout") If $PingTimeout = 0 Then $PingTimeout = 1000 EndIf If $Cmdline[0] = 2 Then $ping = Ping($Cmdline[1], $PingTimeout) If $ping = 0 Then _SendMessage($Cmdline[2], 0x0F01) Else _SendMessage($Cmdline[2], 0x0F00, _IpToHex($Cmdline[1]), String($ping)) EndIf Exit EndIf Func _IpToHex($Ip) Local $array = StringSplit($Ip, ".") Return "0x" & Hex($array[1], 2) & Hex($array[2], 2) & Hex($array[3], 2) & Hex($array[4], 2) EndFunc
  7. I'm guessing the adll files are stringtobinary (encrypted??) autoitscript which are called using execute. The only part of this that I find usfull is that you can update the adll file rather then the entire exe. other then that, why not just use #include??
  8. I usally use if ubound($Array) < $Expected_Array_Size then ;Handle array error endif PS: "Line 12734" Holy crap!!!!
  9. I...I...I...don't know what to say...
  10. wouldn't #NoTrayIcon #include <ScreenCapture.au3> $Pos = WinGetPos("Program Manager") If $CmdLine[0] = 1 Then _ScreenCapture_Capture($CmdLine[1], $Pos[0], $Pos[1], $Pos[0] + $Pos[2], $Pos[1] + $Pos[3]) Else _ScreenCapture_Capture(@ScriptDir & "\screenshot.jpg", $Pos[0], $Pos[1], $Pos[0] + $Pos[2], $Pos[1] + $Pos[3]) EndIfwork just as well?
  11. Might want to try with timer, it would make the resizing much more constant. Example a similar function I made a while back. Func WindowGlide($hwnd, $text, $x, $y, $width, $height, $time = 200) Local $OrgPos = WinGetPos($hwnd, $text) If @error Then Return SetError(1, 0, 0) EndIf Local $NewPos[4] Local $timer = TimerInit() Local $percent_done = 0 While TimerDiff($timer) < $time Sleep(10) $percent_done = TimerDiff($timer) / $time $NewPos[0] = $OrgPos[0] + ($x - $OrgPos[0]) * $percent_done $NewPos[1] = $OrgPos[1] + ($y - $OrgPos[1]) * $percent_done $NewPos[2] = $OrgPos[2] + ($width - $OrgPos[2]) * $percent_done $NewPos[3] = $OrgPos[3] + ($height - $OrgPos[3]) * $percent_done WinMove($hwnd, $text, $NewPos[0], $NewPos[1], $NewPos[2], $NewPos[3]) WEnd WinMove($hwnd, $text, $x, $y, $width, $height) Return 1 EndFunc
  12. Bin working on some bezier UDFs, wanted to be able to get coords along a bezier curve. here is a example of what i came up with. just click around on the GUI and see what happens #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <WinApi.au3> Opt("GUIOnEventMode", 1) ; Create GUI $hGUI = GUICreate("GDI+", 800, 600, -1, -1, $WS_SIZEBOX) ; Draw a cardinal spline _GDIPlus_Startup () $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI) $BackBuffer = _GDIPlus_BitmapCreateFromGraphics(400, 300, $hGraphic) $MainGraphic = _GDIPlus_ImageGetGraphicsContext($BackBuffer) _GDIPlus_GraphicsClear($MainGraphic, 0xFFFFFFFF) _GDIPlus_GraphicsSetSmoothingMode($MainGraphic, 2) Global $Bezier Global $MovePoint = -1 GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "GUI_EVENT_MOUSEMOVE") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "GUI_EVENT_PRIMARYDOWN") GUISetOnEvent($GUI_EVENT_PRIMARYUP, "GUI_EVENT_PRIMARYUP") GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_EVENT_CLOSE") GUISetState() While True Sleep(10) _Draw() WEnd Func GUI_EVENT_MOUSEMOVE() Local $ginfo = GUIGetCursorInfo() If $MovePoint > -1 Then _Bezier_SetControlPoint($Bezier, $MovePoint, $ginfo) EndIf EndFunc Func GUI_EVENT_PRIMARYDOWN() Local $ginfo = GUIGetCursorInfo() If UBound($Bezier) = 0 Then Local $point[2] $point[0] = $ginfo[0] $point[1] = $ginfo[1] $Bezier = _Bezier_Create($point) Return EndIf For $t = 0 To _Bezier_GetPointCount($Bezier) $P = _Bezier_GetControlPoint($Bezier, $t) If _InRange($ginfo, $P, 3) Then $MovePoint = $t Return EndIf Next $MovePoint = _Bezier_AddControlPoint($Bezier, $ginfo) EndFunc Func GUI_EVENT_PRIMARYUP() $MovePoint = -1 EndFunc Func GUI_EVENT_CLOSE() _GDIPlus_GraphicsDispose ($hGraphic) _GDIPlus_Shutdown () Exit EndFunc Func _InRect($point, $rectp1, $rectp2) If $point[0] > $rectp1[0] And $point[0] < $rectp2[0] And $point[1] > $rectp1[1] And $point[1] < $rectp2[1] Then Return True EndIf Return False EndFunc Func _InRange($point1, $point2, $range) If Sqrt(($point1[0] - $point2[0])^2 + ($point1[1] - $point2[1])^2) < $range Then Return True EndIf Return False EndFunc Func _Draw() Local $timer = TimerInit() _GDIPlus_GraphicsClear($MainGraphic, 0xFFFFFFFF) If UBound($Bezier) <> 0 Then _Bezier_Draw($MainGraphic, $Bezier, 40) EndIf _GDIPlus_GraphicsDrawImage($hGraphic, $BackBuffer, 0, 0) WinSetTitle($hGUI, "", "FPS: " & Round(1000 / TimerDiff($timer), 2)) EndFunc Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose ($BackBuffer) _GDIPlus_BitmapDispose($BackBuffer) $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI) ConsoleWrite($lParam & @CRLF) $BackBuffer = _GDIPlus_BitmapCreateFromGraphics(_WinAPI_LoWord($lParam), _WinAPI_HiWord($lParam), $hGraphic) $MainGraphic = _GDIPlus_ImageGetGraphicsContext($BackBuffer) _GDIPlus_GraphicsSetSmoothingMode($MainGraphic, 2) _Draw() EndFunc Func _Bezier_Draw($Graphics, $B, $subdivid = 25) Local $oldPoint = _Bezier_GetPoint($B, 0) Local $point For $x = 0 To 1 Step 1/$subdivid $point = _Bezier_GetPoint($B, $x) _GDIPlus_GraphicsDrawLine($Graphics, $oldPoint[0], $oldPoint[1], $point[0], $point[1]) $oldPoint = $point Next $point = _Bezier_GetPoint($B, 1) _GDIPlus_GraphicsDrawLine($Graphics, $oldPoint[0], $oldPoint[1], $point[0], $point[1]) Local $pen = _GDIPlus_PenCreate() _GDIPlus_PenSetDashStyle($pen, $GDIP_DASHSTYLEDASH) ;_GDIPlus_GraphicsDrawLine($Graphics, $B[0][0], $B[0][1], $B[1][0], $B[1][1], $pen) ;_GDIPlus_GraphicsDrawLine($Graphics, $B[2][0], $B[2][1], $B[3][0], $B[3][1], $pen) Local $oldPoint = _Bezier_GetControlPoint($B, 0) Local $point For $x = 0 To UBound($B) - 1 $point = _Bezier_GetControlPoint($B, $x) _GDIPlus_GraphicsDrawLine($Graphics, $oldPoint[0], $oldPoint[1], $point[0], $point[1], $pen) $oldPoint = $point _GDIPlus_GraphicsFillEllipse($Graphics, $B[$x][0] - 3, $B[$x][1] - 3, 6, 6) Next EndFunc #cs This is where the real bezier UDF start #ce Func _Bezier_GetPoint($B, $t) Local $n = UBound($B) - 1 For $k = 1 To $n For $i = 0 To $n - $k $B[$i][0] = (1 - $t) * $B[$i][0] + $t * $B[$i + 1][0] $B[$i][1] = (1 - $t) * $B[$i][1] + $t * $B[$i + 1][1] Next Next Local $ret[2] $ret[0] = $B[0][0] $ret[1] = $B[0][1] Return $ret EndFunc Func _Bezier_Create($points) If Mod(UBound($points), 2) <> 0 Then Return SetError(1, 0, -1) EndIf Local $B[UBound($points) / 2][2] For $x = 0 To UBound($B) - 1 $B[$x][0] = $points[$x * 2] $B[$x][1] = $points[($x * 2) + 1] Next Return $B EndFunc Func _Bezier_GetPointCount($B) Return UBound($B) - 1 EndFunc Func _Bezier_GetControlPoint($B, $point) If $point > UBound($B) - 1 Then Return SetError(1, 0, -1) EndIf Local $ret[2] $ret[0] = $B[$point][0] $ret[1] = $B[$point][1] Return $ret EndFunc Func _Bezier_SetControlPoint(ByRef $B, $point, $newpoint) If $point > UBound($B) - 1 Then Return SetError(1, 0, -1) EndIf $B[$point][0] = $newpoint[0] $B[$point][1] = $newpoint[1] Return $B EndFunc Func _Bezier_AddControlPoint(ByRef $B, $point) ReDim $B[UBound($B) + 1][UBound($B, 2)] $B[UBound($B) - 1][0] = $point[0] $B[UBound($B) - 1][1] = $point[1] Return UBound($B) - 1 EndFunc
  13. comment out ControlHide($TaskbarHwnd, "", 304), but why?
  14. hmm, it should do that if you close it from the system tray (next to the clock).
×
×
  • Create New...