How to Select Multiple Items in a Listbox, need to select more than one at a tim

Started by ChillyWilly, October 19, 2009, 02:14:29 AM

Previous topic - Next topic

ChillyWilly

i do tech work fixing computers , alot of time the computers are so full of running apps it makes it difficult to select the processes one at a time in task manager to kill the process.

im trying to make a process killer that allows me to select multiple items at once and click the button to kill

so far i got the apps listed and i kill kill one selection at a time


i tried using LBS_MULTIPLESEL style for listbox , but it messes selected item when timer calls refresh and i dont know how to cycle through the selected items and kill each

option casemap:none
include C:\masm32\include\windows.inc
include C:\masm32\include\kernel32.inc
include C:\masm32\include\user32.inc
includelib C:\masm32\lib\kernel32.lib
includelib C:\masm32\lib\user32.lib

WndProc PROTO:DWORD,:DWORD,:DWORD,:DWORD
Refresh PROTO
.const
szAppTitle db "-=[ Kill'em All ]=-", 0
szMsgAbout db "Version 1.0", 13, 10
db "Coded by chillywilly", 13, 10
db "http://winasm.net", 0

.data?
    ThaPath   db 256 dup(?)
hInst dd ?
hMainWnd dd ?
hList dd ?
hSnapshot dd ?
EditHwnd HWND ?
ThaProcess PROCESSENTRY32 <>

.code
start:
invoke GetModuleHandle, 0
mov [hInst], eax
invoke DialogBoxParam, eax, 1000, 0, ADDR WndProc, eax
invoke ExitProcess, eax
WndProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD

.if uMsg==WM_INITDIALOG
call Refresh
invoke SetTimer,hWnd,1000,1000,addr WndProc ;/// set a refresh timer
invoke LoadIcon, [lParam], 1

invoke SendMessage, [hWnd], WM_SETICON, IMAGE_ICON, eax
    invoke GetDlgItem, hWnd, 1005
        mov EditHwnd, eax
invoke GetDlgItem, [hWnd], 1001
mov [hList], eax


.elseif uMsg == WM_TIMER      ; timer message received?
    call Refresh
            ret
.elseif uMsg==WM_COMMAND
;
        mov eax,[wParam]
        mov edx,[wParam]
        shr edx,16
        .IF dx==BN_CLICKED  ;/// Button click message
            .IF ax==1003  ;/// kill button
            invoke SendMessage, [hList], LB_GETCURSEL, 0, 0
invoke SendMessage, [hList], LB_GETITEMDATA, eax, 0
invoke OpenProcess, PROCESS_TERMINATE, 1, eax
invoke TerminateProcess, eax, 0
invoke Sleep, 500 ; wait for the process to terminate
            .ELSEIF ax==1004 ;/// Info button
              invoke MessageBox, [hWnd], ADDR szMsgAbout, ADDR szAppTitle, MB_OK OR MB_ICONASTERISK OR MB_APPLMODAL
        .ENDIF

.endif

.elseif uMsg==WM_CLOSE
invoke EndDialog, [hWnd], 0
.endif
xor eax, eax
ret
WndProc endp

Refresh proc

invoke SendMessage,[hList],LB_GETCURSEL,0,0  ;///save the selection location
mov esi,eax
invoke SendMessage, [hList], LB_RESETCONTENT, 0, 0

mov [ThaProcess.dwSize], sizeof ThaProcess
invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0
mov [hSnapshot], eax
invoke Process32First, eax, ADDR ThaProcess

.while eax
invoke SendMessage, [hList], LB_ADDSTRING, 0, ADDR ThaProcess.szExeFile
invoke SendMessage, [hList], LB_SETITEMDATA, eax, [ThaProcess.th32ProcessID]
invoke Process32Next, [hSnapshot], ADDR ThaProcess
.endw
invoke CloseHandle, [hSnapshot]

invoke SendMessage,[hList],LB_SETCURSEL,esi,0  ;///re-set the old slection location
ret
Refresh endp


end start

jj2007

First, specifying the drive as in
Quoteinclude  C:\masm32\include\windows.inc
is a bad idea, because those who read your posts might have installed Masm32 on D: (even worse would be include windows.inc, assuming that the other one uses exactly the same environment variables).
Second, your example does not run: the resource file is missing.
Regards, JJ

ChillyWilly

Quote from: jj2007 on October 19, 2009, 09:11:30 AM
First, specifying the drive as in
Quoteinclude  C:\masm32\include\windows.inc
is a bad idea, because those who read your posts might have installed Masm32 on D: (even worse would be include windows.inc, assuming that the other one uses exactly the same environment variables).
Second, your example does not run: the resource file is missing.
Regards, JJ

the app is a simple form with a listbox and 2 buttons

ill post it later if that helps