option explicitpublic const gw_hwndfirst = 0
public const gw_hwndnext = 2
public const gw_child = 5public const wm_settext = &hcpublic declare function getwindow lib "user32" _
(byval hwnd as long, _
byval wcmd as long) as longpublic declare function getdesktopwindow lib "user32" () as longpublic declare function getwindowthreadprocessid lib "user32" _
(byval hwnd as long, _
lpdwprocessid as long) as longpublic declare function bringwindowtotop lib "user32" _
(byval hwnd as long) as longpublic declare function setwindowtext lib "user32" _
alias "setwindowtexta" _
(byval hwnd as long, byval _
lpstring as string) as long
private function startshell(sapplication as string) as long dim hprocessid as long
hprocessid = shell(sapplication, vbnormalfocus)
startshell = gethwndfromprocessid(hprocessid)
end functionpublic function gethwndfromprocessid(hprocessidtofind as long) as long dim hwnddesktop as long
dim hwndchild as long
dim hwndchildprocessid as long
on local error goto gethwndfromprocessid_error
hwnddesktop = getdesktopwindow()
hwndchild = getwindow(hwnddesktop, gw_child)
do while hwndchild <> 0
call getwindowthreadprocessid(hwndchild, hwndchildprocessid)
if hwndchildprocessid = hprocessidtofind then
gethwndfromprocessid = hwndchild
exit do
end if
hwndchild = getwindow(hwndchild, gw_hwndnext)
loop
exit functiongethwndfromprocessid_error:
gethwndfromprocessid = 0
exit function
end functionprivate sub command1_click() dim hwndapp as long
hwndapp = startshell("notepad.exe")
if hwndapp then
call setwindowtext(hwndapp, "the handle to notepad is " & cstr(hwndapp))
call bringwindowtotop(hwndapp)
end ifend sub
希望大家帮帮忙
public const gw_hwndnext = 2
public const gw_child = 5public const wm_settext = &hcpublic declare function getwindow lib "user32" _
(byval hwnd as long, _
byval wcmd as long) as longpublic declare function getdesktopwindow lib "user32" () as longpublic declare function getwindowthreadprocessid lib "user32" _
(byval hwnd as long, _
lpdwprocessid as long) as longpublic declare function bringwindowtotop lib "user32" _
(byval hwnd as long) as longpublic declare function setwindowtext lib "user32" _
alias "setwindowtexta" _
(byval hwnd as long, byval _
lpstring as string) as long
private function startshell(sapplication as string) as long dim hprocessid as long
hprocessid = shell(sapplication, vbnormalfocus)
startshell = gethwndfromprocessid(hprocessid)
end functionpublic function gethwndfromprocessid(hprocessidtofind as long) as long dim hwnddesktop as long
dim hwndchild as long
dim hwndchildprocessid as long
on local error goto gethwndfromprocessid_error
hwnddesktop = getdesktopwindow()
hwndchild = getwindow(hwnddesktop, gw_child)
do while hwndchild <> 0
call getwindowthreadprocessid(hwndchild, hwndchildprocessid)
if hwndchildprocessid = hprocessidtofind then
gethwndfromprocessid = hwndchild
exit do
end if
hwndchild = getwindow(hwndchild, gw_hwndnext)
loop
exit functiongethwndfromprocessid_error:
gethwndfromprocessid = 0
exit function
end functionprivate sub command1_click() dim hwndapp as long
hwndapp = startshell("notepad.exe")
if hwndapp then
call setwindowtext(hwndapp, "the handle to notepad is " & cstr(hwndapp))
call bringwindowtotop(hwndapp)
end ifend sub
希望大家帮帮忙
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货