for example another, not my programm, have some kind of this:
Code: Select all
Enumeration
#Window
#Container
#ListIcon
EndEnumeration
If OpenWindow(#Window, 100, 100, 300, 105, "Window for cathc", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ContainerGadget(#Container, 5, 5, 290, 95, #PB_Container_Raised)
ListIconGadget(#ListIcon, 5, 5, 270, 75, "Name", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection | #LVS_NOCOLUMNHEADER | #PB_ListIcon_CheckBoxes)
AddGadgetItem(#ListIcon, -1, "Harry Rannit")
AddGadgetItem(#ListIcon, -1, "Ginger Brokeit")
AddGadgetItem(#ListIcon, -1, "3 par")
AddGadgetItem(#ListIcon, -1, "num four")
CloseGadgetList()
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
save it with some "testwindow.exe" file, launch. then start code below.
i know how to read it. and maybe select one - by press "space" after select. i mean checkbox. but how to return checkbox is check or not check?
Code: Select all
Procedure.i SelectItem(pid.i, hwnd.i, toselectitem.i)
;/* get process Id, that has ListView */
;GetWindowThreadProcessId_(hList, @pid)
If pid
;/* open process With rights */
hProcess = OpenProcess_(#PROCESS_VM_WRITE|#PROCESS_VM_OPERATION, #True, pid)
If hProcess
;/* allocate memory in target process */
lpMem = VirtualAllocEx_(hProcess, #Null, SizeOf(LV_ITEM), #MEM_COMMIT, #PAGE_READWRITE)
If lpMem
;/* fill Structure */
With LV.LV_ITEM;
\state = #LVIS_SELECTED|#LVIS_FOCUSED
\mask = #LVIF_STATE
\stateMask = #LVIS_SELECTED|#LVIS_FOCUSED
EndWith
;/* copy LV To target process */
If (WriteProcessMemory_(hProcess, lpMem, @LV, SizeOf(LV_ITEM), @cdWrite.l))
;/* send message To Select */
ret = SendMessage_(hwnd, #LVM_SETITEMSTATE, toselectitem, lpMem)
EndIf
;/* free allocate memory */
VirtualFreeEx_(hProcess, lpMem, 0, #MEM_RELEASE)
EndIf
;/* close handle*/
CloseHandle_(hProcess)
EndIf
EndIf
ProcedureReturn ret
EndProcedure
Procedure.i NumberItem(pid.i, hwnd.i, selectitem$)
toselectitem = -2
lvi.LVITEM
_lvi.LVITEM
temp.s
Item.l
Count = SendMessage_(hwnd,#LVM_GETITEMCOUNT,0,0)
proc = OpenProcess_(#PROCESS_ALL_ACCESS, #False, pid)
If proc
*_lvi.LVITEM = VirtualAllocEx_(proc, 0, SizeOf(LVITEM), #MEM_COMMIT, #PAGE_READWRITE)
Item = VirtualAllocEx_(proc, 0, 255, #MEM_COMMIT, #PAGE_READWRITE)
temp = Space(255)
lvi\cchTextMax=255
For i=0 To Count-1
lvi\iSubItem = 0
lvi\pszText = Item
lvi\cchTextMax = 255
WriteProcessMemory_(proc, *_lvi, @lvi, SizeOf(LVITEM), 0)
; i need same as #LVM_GETITEMTEXT, but for checkbox?
SendMessage_(hwnd, #LVM_GETITEMTEXT, i, *_lvi)
ReadProcessMemory_(proc, item, @temp, 255, 0)
Debug temp
If temp = selectitem$
toselectitem = i
Break
EndIf
Next i
VirtualFreeEx_(proc, *_lvi, 0, #MEM_RELEASE);
VirtualFreeEx_(proc, item, 0, #MEM_RELEASE)
CloseHandle_(proc)
EndIf
ProcedureReturn toselectitem
EndProcedure
Prototype ProcessFirst(Snapshot, Process)
Prototype ProcessNext(Snapshot, Process)
Global ProcessFirst.ProcessFirst
Global ProcessNext.ProcessNext
Procedure GetPidProcess2(Name.s) ; Returns 'pid' of the first Process found if it exists / 0 if it doesn't exist
Protected ProcLib
Protected ProcName.s
Protected Process.PROCESSENTRY32
Protected x
Protected retval=#False
Name=UCase(Name.s)
ProcLib= OpenLibrary(#PB_Any, "Kernel32.dll")
If ProcLib
CompilerIf #PB_Compiler_Unicode
ProcessFirst = GetFunction(ProcLib, "Process32FirstW")
ProcessNext = GetFunction(ProcLib, "Process32NextW")
CompilerElse
ProcessFirst = GetFunction(ProcLib, "Process32First")
ProcessNext = GetFunction(ProcLib, "Process32Next")
CompilerEndIf
If ProcessFirst And ProcessNext
Process\dwSize = SizeOf(PROCESSENTRY32)
Snapshot =CreateToolhelp32Snapshot_(#TH32CS_SNAPALL,0)
If Snapshot
ProcessFound = ProcessFirst(Snapshot, Process)
x=1
While ProcessFound
ProcName=PeekS(@Process\szExeFile)
ProcName=GetFilePart(ProcName)
If UCase(ProcName)=UCase(Name)
ret=Process\th32ProcessID
Break
EndIf
ProcessFound = ProcessNext(Snapshot, Process)
x=x+1
Wend
EndIf
CloseHandle_(Snapshot)
EndIf
CloseLibrary(ProcLib)
EndIf
ProcedureReturn ret
EndProcedure
pid = GetPidProcess2("testwindow.exe") ; from droopy
hwndmain = FindWindow_(0, "Window for cathc")
If hwndmain
SetForegroundWindow_(hwndmain)
hwndpanel = FindWindowEx_(hwndmain, 0, "PureContainer", 0)
If hwndpanel
hwnd = FindWindowEx_(hwndpanel, 0, "SysListView32", 0)
selectnum = NumberItem(pid, hwnd, "Ginger Brokeit")
If selectnum > -2
If SelectItem(pid, hwnd, selectnum)
Debug "select done"
; space button
Delay(100)
PostMessage_(hwnd, #WM_KEYDOWN, 32, 0)
Delay(100)
PostMessage_(hwnd, #WM_KEYUP, 32, 0)
EndIf
EndIf
EndIf
EndIf