| 发表于:2007-02-15 10:18:16 楼主 |
这段模块里的代码那错了?? 发现含有标题蓝 前五个字符 中 有test1或test2时 让form2窗口置顶。。。。没有发现时。。。不显示form2窗口 declare function enumwindows lib "user32 " (byval lpenumfunc as any, byval lparam as long) as long declare function getwindowtext lib "user32 " alias "getwindowtexta " (byval hwnd as long, byval lpstring as string, byval cch as long) as long declare function getwindowrect lib "user32 " (byval hwnd as long, lprect as rect) as long private type rect left as long top as long right as long bottom as long end type 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 public const hwnd_topmost = -1 public const swp_nomove = &h2 public const swp_nosize = &h1 public const swp_nozorder = &h8 dim buf as string dim title as string dim bl as boolean public sub setformtopmost(theform as form) setwindowpos theform.hwnd, hwnd_topmost, 0, 0, 0, 0, _ swp_nozorder + swp_nomove + swp_nosize end sub public function enumproc(byval app_hwnd as long, byval lparam as long) as boolean '遍查主窗口 dim buf as string * 1024 dim length as long doevents dim r as rect length = getwindowtext(app_hwnd, buf, len(buf)) title = left$(buf, length) if left(title, 5) = "test1 " then '判断是否为窗口2 'showwindow (app_hwnd) getwindowrect app_hwnd, r 'msgbox r.left 'msgbox r.top 'msgbox r.right 'msgbox r.bottom form2.left = (r.left + 93) * 15 '定位 form2.top = (r.bottom - 42) * 15 setformtopmost form2 form2.show '显示form2窗口到指定位子 并且置顶 bl = true end if if left(title, 5) = "test2 " then '判断是否为 窗口2 'showwindow (app_hwnd) getwindowrect app_hwnd, r 'msgbox r.left 'msgbox r.top 'msgbox r.right 'msgbox r.bottom form2.left = (r.left + 80) * 15 form2.top = (r.bottom - 42) * 15 setformtopmost form2 form2.show bl = true end if if bl <> true then '如果没找到指定窗口 取消form2 置顶 'setwindowpos form2.hwnd, hwnd_notopmost, 0, 0, 0, 0, swp_nomove or swp_nosize '取消 置顶 ' end if enumproc = 1 '取消 ' end function 然后在time控件里 调用:: private sub timer1_timer() doevents enumwindows addressof enumproc, 0 '枚举窗口列表中的所有父窗口 end sub |
|
|
|
|