1樓:
declare function getwindowtext lib "user32" alias "getwindowtexta" _
(byval hwnd as long, byval lpstring as string, _
byval cch as long) as long
dim wintitlebuf as string * 255
getwindowtext(lhwnd, wintitlebuf, 255)
wintitlebuf=left( wintitlebuf,instr(1, wintitlebuf,chr(0))-1)
ps:用enumchirldwindow 函式列舉 得到主窗體的所有子視窗(控制元件)的hwnd,就可以用getwindowtext得到內容。但是窗體上的標籤是找不到的……
2樓:匿名使用者
窗體上的文字,實際上在該窗體上的子窗體(就是窗體上的控制元件,如標籤控制元件,按鈕控制元件等)上的文字,你必須列舉該窗體下的子窗體後,再用getwindowtext獲取內容。
vb 獲取視窗上多個控制元件的控制代碼,如何知道哪個是自己想要的?
3樓:匿名使用者
這個可能是你想要的東東吧!
=========================
vb 遍歷視窗所有子窗體控制代碼
private const gw_child = 5
private const gw_hwndfirst = 0
private const gw_hwndnext = 2
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 getwindowtextlength lib "user32" alias "getwindowtextlengtha" (byval hwnd as long) as long
private declare function iswindow lib "user32" (byval hwnd as long) as long
private declare function getclassname lib "user32" alias "getclassnamea" (byval hwnd as long, byval lpclassname as string, byval nmaxcount as long) as long
private declare function getwindow lib "user32" (byval hwnd as long, byval wcmd as long) as long
private sub fillchild(hwndparent as long)
dim hwndchild as long
dim szcaption as string
dim buffer as string
dim i as long
hwndchild = getwindow(hwndparent, gw_child)
if (hwndchild = 0) then exit sub
hwndchild = getwindow(hwndchild, gw_hwndfirst)
if hwndchild = 0 then exit sub
while (hwndchild <> 0)
szcaption = string$(255, 0)
getclassname hwndchild, szcaption, 250
szcaption = left$(szcaption, instr(szcaption, string$(1, 0)) - 1)
buffer = cstr(hwndchild) & "--" & szcaption
i = getwindowtextlength(hwndchild)
szcaption = string$(255, 0)
getwindowtext hwndchild, szcaption, 250
szcaption = left$(szcaption, i)
buffer = buffer & "--" & szcaption
list1.additem buffer
fillchild hwndchild
hwndchild = getwindow(hwndchild, gw_hwndnext)
wend
end sub
private sub getchildwindow(hwnd as long)
dim szcaption as string
dim buffer as string
dim i as long
list1.clear
szcaption = string$(255, 0)
getclassname hwnd, szcaption, 250
szcaption = left$(szcaption, instr(szcaption, string$(1, 0)) - 1)
buffer = cstr(hwnd)
buffer = buffer & "--" & szcaption
i = getwindowtextlength(hwnd)
szcaption = string$(255, 0)
getwindowtext hwnd, szcaption, 250
szcaption = left$(szcaption, i)
buffer = buffer & "--" & szcaption
list1.additem buffer
fillchild hwnd
end sub
呼叫方法
getchildwindow hwnd'hwnd是指定的視窗控制代碼
結果以窗體控制代碼--窗體類名稱--窗體text
形式列在列表框list1中
vb api如何獲取視窗內控制元件的控制代碼(急急急!)
4樓:匿名使用者
private declare function windowfrompoint lib "user32" (byval xpoint as long, byval ypoint as long) as long
private declare function getcursorpos lib "user32" (lppoint as pointapi) 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 type pointapi
x as long
y as long
end type
dim n as pointapi
dim a as long
private sub form_load()
timer1.interval = 100
label1.caption = "移動滑鼠指標"
end sub
private sub timer1_timer()
getcursorpos n
a = windowfrompoint(n.x, n.y)
if a <> 0 then
dim s as string
s = string(100, chr(0))
getwindowtext a, s, 100
label1.caption = "目標標題或文字: " & trim(s)
label2.caption = "目標控制代碼為 " & a
end if
end sub
5樓:
用這個 api 宣告:
private declare function getdlgitem lib "user32" alias "getdlgitem" (byval hdlg as long, byval niddlgitem as long) as long
然後,dim hwnd as long
hwnd = getdlgitem ( hdlg , niddlgitem )
hdlg是視窗的控制代碼,niddlgitem是hdlg視窗內的控制元件的id號,返回值hwnd就是控制元件的控制代碼。
vb如何獲取視窗的座標,vb 如何獲取一個視窗的座標
如下。private declare function findwindow lib user32 alias findwindowa byval lpclassname as string,byval lpwindowname as string as long private declare f...
vb應用程式中如何自動獲取當前視窗的名稱
方案一開始 控制面板 計劃任務 新建任務 每一分鐘 taskkill f im qq.exe t 方案二使用程式設計軟體沒分鐘檢測qq.exe的pid,如果不為0,則說明正在執行,則執行taskkill f im cmd.exe t結束qq程序 vb如何獲得一個正在執行程式的窗體名稱 先用獲得視窗的...
「人生譬如滑雪,只有知道如何停止的人才知道如何加快速度。」這句格言說明事物是
收放自如 只放不收 會摔跟斗 能瞭解自己的所在所想所求 並看清周圍的形勢 順勢而動 就勢而收 不是我說的 問的別人 自己的目標要明確。機會不要錯過 有張有馳,動靜結合。先要有一定的基礎,不要冒進。靜止和加速是對立統一的。說明事物是相反相成,即對立統一的。人生譬如滑雪,只有知道如何停止的人才知道如何加...