Jump to content

Recommended Posts

Posted

I found code but I cant use it with my script.

Is there any change of getting every row with different background color?

#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <WinAPI.au3>
Opt("GUIDataSeparatorChar", chr(0x90))
$sData = "Caption|CommandLine|CreationClassName|datetime CreationDate|" & _
  "CSCreationClassName|CSName|Description|ExecutablePath|uint16-ExecutionState|" & _
  "Handle|HandleCount|datetime InstallDate|KernelModeTime|MaximumWorkingSetSize|" & _
  "MinimumWorkingSetSize|Name|OSCreationClassName|OSName|OtherOperationCount|" & _
  "OtherTransferCount|PageFaults|PageFileUsage|ParentProcessId|PeakPageFileUsage|" & _
  "PeakVirtualSize|PeakWorkingSetSize|Priority|PrivatePageCount|ProcessId|" & _
  "QuotaNonPagedPoolUsage|QuotaPagedPoolUsage|QuotaPeakNonPagedPoolUsage|" & _
  "QuotaPeakPagedPoolUsage|ReadOperationCount|ReadTransferCount|SessionId|" & _
  "Status|TerminationDate|ThreadCount|UserModeTime|VirtualSize|WindowsVersion|" & _
  "WorkingSetSize|WriteOperationCount|WriteTransferCount"
$Form1 = GUICreate("Task Manager pre alpha", 1000, 443, 0, 0,BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_OVERLAPPEDWINDOW,$WS_TILEDWINDOW,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS))
$ListView1 = GUICtrlCreateListView(StringReplace($sData,"|",chr(0x90)), 0, 5, 1000, 430, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $WS_HSCROLL, $WS_VSCROLL))
GUISetState(@SW_SHOW)
$ProcList = ProcessList()
$ColList = StringSplit($sData, "|")
$lstData = ""
;~ RegisterSortCallBack
GetData()
;~ MsgBox(0,0,$lstData)

$rows = StringSplit($lstData, @CRLF, 1)
For $i = 1 To $rows[0]
GUICtrlCreateListViewItem($rows[$i], $ListView1)
_GUICtrlListViewSetItemHighlight($ListView1,$i,$i*10)
Next
For $i = 0 To _GUICtrlListView_GetColumnCount($ListView1)
_GUICtrlListView_SetColumnWidth($ListView1, $i, $LVSCW_AUTOSIZE)
$Width = _GUICtrlListView_GetColumnWidth($ListView1, $i)
If $Width < 100 Then
  _GUICtrlListView_SetColumnWidth($ListView1, $i, $LVSCW_AUTOSIZE_USEHEADER)
EndIf
Next
WinSetTitle($Form1,"","Task Manager pre alpha - Processes: "& $rows[0] &" Properties: "&$i )
_GUICtrlListView_RegisterSortCallBack($ListView1)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
    _GUICtrlListView_UnRegisterSortCallBack($ListView1)
   Exit
  Case $ListView1
   _GUICtrlListView_SortItems($ListView1, GUICtrlGetState($ListView1))
EndSwitch
WEnd

Func GetData()
$colItems = ""
$objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", 0x10 + 0x20)
If IsObj($colItems) Then
  For $objItem In $colItems
   For $u = 1 To $ColList[0]
    $lstData &= Execute("$objItem." & $ColList[$u]) & chr(0x90)
;~  ConsoleWrite("$objItem."&$ColList[$u]&" ===> "&Execute("$objItem."&$ColList[$u])&@CRLF)
   Next
;~  Exit
   $lstData = StringTrimRight($lstData, 1)
   $lstData &= @CRLF
;~  consolewrite($lstData)
;~  Return
  Next
EndIf
EndFunc   ;==>GetData
Func _GUICtrlListViewSetItemHighlight($hListView, $iIndex, $sColor, $iLineWidth=2)
    Local $aItem_Rect = _GUICtrlListView_GetItemRect($hListView, $iIndex, 3)
    Local $aGUI_Pos = WinGetPos($Form1)
    Local $aLV_Pos = ControlGetPos($Form1, "", $ListView1)
    _DrawSquare($aItem_Rect[0]+$aGUI_Pos[0]+$aLV_Pos[0]+5, $aItem_Rect[1]+$aGUI_Pos[1]+$aLV_Pos[1]+25, _
        $aLV_Pos[2]-3, $aItem_Rect[3]- 22 - ($iIndex * 14), $sColor, $iLineWidth)
EndFunc
Func _DrawSquare($iLeft, $iTop, $iWidth, $iHeight, $sColor, $iLineWidth=2, $hWnd=0)
    Local $hDC = DllCall("User32.dll", "int", "GetDC", "hwnd", $hWnd)
    Local $aPen = DllCall("GDI32.dll", "int", "CreatePen", "int", 0, "int", $iLineWidth, "int", $sColor)
    DllCall("GDI32.dll", "int", "SelectObject", "int", $hDC[0], "int", $aPen[0])
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop)
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop+$iHeight)
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop+$iHeight)
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop+$iHeight, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop+$iHeight)
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "int", $hDC[0])
EndFunc

edited

Posted

Check out this topic in the example scripts folder. The example script posted to display the ColorConstantsEx.au3 file does that really well.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...