Get Processes List In PowerBuilder


Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
forward global type w_main from window end type type dw_main from datawindow within w_main end type type cb_1 from commandbutton within w_main end type type str_process from structure within w_main end type end forward type str_process from structure unsignedlong StructSize unsignedlong cntusage unsignedlong processid unsignedlong defaultheapid unsignedlong moduleid unsignedlong cntthreads unsignedlong parentprocessid unsignedlong pcpriclassbase long dwflags character FileName[256] end type global type w_main from window integer width = 2359 integer height = 1408 boolean titlebar = true string title = "Process" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true dw_main dw_main cb_1 cb_1 end type global w_main w_main type prototypes Function Long GetCurrentProcessId() Library "kernel32.dll" Function Long CreateToolhelp32Snapshot(Long Flags, Long ProcessId) Library "kernel32.dll" Function Integer Process32First(ULong Snapshot, Ref str_Process sProcess) Library "kernel32.dll" Alias For "Process32First;Ansi" Function Integer Process32Next(ULong Snapshot, Ref str_Process sProcess) Library "kernel32.dll" Alias For "Process32Next;Ansi" Function ULong GetWindowThreadProcessId(ULong hwnd, Ref ULong lpdwProcessId) Library "user32.dll" Function ULong GetWindowText(ULong hwnd, Ref String lpString, ULong cch) Library "user32.dll" Alias For "GetWindowTextA;Ansi" end prototypes on w_main.create this.dw_main=create dw_main this.cb_1=create cb_1 this.Control[]={this.dw_main,& this.cb_1} end on on w_main.destroy destroy(this.dw_main) destroy(this.cb_1) end on type dw_main from datawindow within w_main integer width = 2304 integer height = 1120 integer taborder = 10 string title = "none" string dataobject = "d_process" boolean hscrollbar = true boolean vscrollbar = true boolean livescroll = true borderstyle borderstyle = stylelowered! end type type cb_1 from commandbutton within w_main integer y = 1152 integer width = 402 integer height = 112 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Load" end type event clicked;str_Process lst_Process //Process structure String ls_FileName[], ls_CurExeName //Up to 100 processes, can be improved String ls_win_txt ULong ln_ProcessID, ln_SameCount, ln_Snapshot ULong ln_Circle, ln_Count ULong ll_new, ll_handle ln_ProcessID = GetCurrentProcessId() //Get the ID of the current process If IsNull(ln_ProcessID) Or ln_ProcessID < 1 Then Return -1 //return if error occurs End If ln_Snapshot = CreateToolhelp32Snapshot(2,0) //Create a process snapshot on the heap If (ln_Snapshot < 1) Then Return -1 //return if error occurs End If lst_Process.StructSize = 296 //Win32api Process structure size ln_SameCount = 0 //The number of copies is 0 If Process32First(ln_Snapshot,lst_Process) = 0 Then Return -1 //Return if the first process fails End If ln_Count = 1 ls_FileName[ln_Count] = lst_Process.Filename //The listed process names are put into the array //If the listed process ID is equal to the current process ID, then you know the name of the current process and save If lst_Process.ProcessID = ln_ProcessID Then ls_CurExeName = lst_Process.Filename End If ls_win_txt = Space(200) Do While True //Take the enumerated process names in a loop and put them into an array If Process32Next(ln_Snapshot, lst_Process) = 0 Then Exit //Enumerated End If ln_Count = ln_Count + 1 ls_FileName[ln_Count] = lst_Process.Filename If lst_Process.ProcessID = ln_ProcessID Then ls_CurExeName = lst_Process.Filename End If ll_new = dw_main.InsertRow(0) dw_main.SetItem(ll_new, "process_no", lst_Process.ProcessID) dw_main.SetItem(ll_new, "process_file", ls_FileName[ln_Count]) If GetWindowThreadProcessId(lst_Process.ProcessID, ll_handle) > 0 Then GetWindowText(ll_handle, ls_win_txt, 255) dw_main.SetItem(ll_new, "process_handle", ll_handle) dw_main.SetItem(ll_new, "process_nam", ls_win_txt) End If Loop dw_main.Sort() end event |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
release 10.5; datawindow(units=0 timer_interval=0 color=67108864 processing=1 HTMLDW=no print.printername="" print.documentname="" print.orientation = 0 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size = 0 print.canusedefaultprinter=yes print.prompt=no print.buttons=no print.preview.buttons=no print.cliptext=no print.overrideprintjob=no print.collate=yes print.preview.outline=yes hidegrayline=no grid.lines=0 ) header(height=80 color="536870912" ) summary(height=0 color="536870912" ) footer(height=0 color="536870912" ) detail(height=92 color="536870912" ) table(column=(type=long updatewhereclause=yes name=process_no dbname="process_no" ) column=(type=char(250) updatewhereclause=yes name=process_file dbname="process_file" ) column=(type=long updatewhereclause=yes name=process_handle dbname="process_handle" ) column=(type=char(250) updatewhereclause=yes name=process_nam dbname="process_nam" ) sort="process_file A " ) column(band=detail id=1 alignment="1" tabsequence=10 border="0" color="33554432" x="14" y="8" height="76" width="297" format="[general]" html.valueishtml="0" name=process_no visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes font.face="Tahoma" font.height="-10" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) column(band=detail id=2 alignment="0" tabsequence=20 border="0" color="33554432" x="325" y="8" height="76" width="869" format="[general]" html.valueishtml="0" name=process_file visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes font.face="Tahoma" font.height="-10" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) column(band=detail id=3 alignment="1" tabsequence=30 border="0" color="33554432" x="1207" y="8" height="76" width="407" format="[general]" html.valueishtml="0" name=process_handle visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes font.face="Tahoma" font.height="-10" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) column(band=detail id=4 alignment="0" tabsequence=40 border="0" color="33554432" x="1627" y="8" height="76" width="475" format="[general]" html.valueishtml="0" name=process_nam visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes font.face="Tahoma" font.height="-10" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) text(band=header alignment="2" text="Process No" border="6" color="33554432" x="14" y="8" height="64" width="297" html.valueishtml="0" name=process_no_t visible="1" font.face="Tahoma" font.height="-10" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) text(band=header alignment="2" text="Process File" border="6" color="33554432" x="325" y="8" height="64" width="869" html.valueishtml="0" name=process_file_t visible="1" font.face="Tahoma" font.height="-10" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) text(band=header alignment="2" text="Process Handle" border="6" color="33554432" x="1207" y="8" height="64" width="407" html.valueishtml="0" name=process_handle_t visible="1" font.face="Tahoma" font.height="-10" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) text(band=header alignment="2" text="Process Nam" border="6" color="33554432" x="1627" y="8" height="64" width="475" html.valueishtml="0" name=process_nam_t visible="1" font.face="Tahoma" font.height="-10" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) htmltable(border="1" ) htmlgen(clientevents="1" clientvalidation="1" clientcomputedfields="1" clientformatting="0" clientscriptable="0" generatejavascript="1" encodeselflinkargs="1" netscapelayers="0" pagingmethod=0 generatedddwframes="1" ) xhtmlgen() cssgen(sessionspecific="0" ) xmlgen(inline="0" ) xsltgen() jsgen() export.xml(headgroups="1" includewhitespace="0" metadatatype=0 savemetadata=0 ) import.xml() export.pdf(method=0 distill.custompostscript="0" xslfop.print="0" ) export.xhtml() |
Find Projects On Github click here
Good Luck!
Subscribe
Login
0 Comments
Oldest