| 发表于:2007-09-06 16:42:541楼 得分:100 |
option explicit const synchronize = &h100000 const infinite = &hffffffff private declare function openprocess lib "kernel32 " (byval dwdesiredaccess as long, byval binherithandle as long, byval dwprocessid as long) as long private declare function closehandle lib "kernel32 " (byval hobject as long) as long private declare function waitforsingleobject lib "kernel32 " (byval hhandle as long, byval dwmilliseconds as long) as long private declare function setwindowpos lib "user32 " (byval hwnd as long, byval hwndinsertafter as long, byval x as long, byval y as long, byval cx as long, byval cy as long, byval wflags as long) as long private declare function movewindow lib "user32 " (byval hwnd as long, byval x as long, byval y as long, byval nwidth as long, byval nheight as long, byval brepaint as long) as long private declare function getwindowthreadprocessid lib "user32 " (byval hwnd as long, lpdwprocessid as long) as long private declare function findwindowex lib "user32 " alias "findwindowexa " (byval hwnd1 as long, byval hwnd2 as long, byval lpsz1 as string, byval lpsz2 as string) as long private declare function getwindowtext lib "user32 " alias "getwindowtexta " (byval hwnd as long, byval lpstring as string, byval cch as long) as long private declare function getparent lib "user32 " (byval hwnd as long) as long private declare function showwindow lib "user32 " (byval hwnd as long, byval ncmdshow as long) as long dim i as long dim mnum as long private const sw_showmaximized = 3 private function mgetwindow(byval mpid as long) as long dim lpdpid() as long dim bwnd as long dim bwndback as long dim lpid as long dim mstr1 as string * 25, mstr2 as string * 25, m1 as long, m2 as long, mb as boolean m1 = len(mstr1) m2 = len(mstr2) bwndback = 0 mnum = 0 redim lpdpid(0) '历遍所有窗体,如果对应进程pid与已知pid相同,则存入数组 do bwnd = findwindowex(0, bwndback, vbnullstring, vbnullstring) if bwnd = 0 then exit do getwindowthreadprocessid bwnd, lpid if lpid = mpid then '如果pid相同 if getparent(bwnd) = 0 then '列举所有为父窗的窗体,如果需要的是mid应该把这里的条件修改为> 0 mb = false for i = 0 to ubound(lpdpid) getwindowtext bwnd, mstr1, m1 getwindowtext lpdpid(i), mstr2, m2 'debug.print mstr1 & "------------------ " & mstr2 if mstr1 = mstr2 then mb = true lpdpid(i) = 0 end if next if mb = false then lpdpid(mnum) = bwnd ' list2.additem lpdpid(mnum) mnum = mnum + 1 redim preserve lpdpid(mnum) end if end if end if bwndback = bwnd ' list1.additem bwnd doevents loop mgetwindow = lpdpid(0) end function private sub command1_click() dim pid as long, phnd as long ' 分别声明process id 及 process handle 变数 pid = shell( "notepad.exe ", vbnormalfocus) 'shell 传回 process id me.print pid 'phnd = openprocess(synchronize, 0, pid) '取得 process handle phnd = mgetwindow(pid) me.print phnd 'setwindowpos phnd, 0, 1024, 120, 130, 0, &h40 movewindow phnd, 500, 500, 120, 130, true end sub | | |
|