vb獲取視窗上多個控制元件的控制代碼,如何知道哪個是自己想要的

2021-05-05 07:36:33 字數 4069 閱讀 6492

1樓:匿名使用者

這個可能是你想要的東東吧!

=========================

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如何獲取視窗內控制元件的控制代碼?

2樓:匿名使用者

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

vb知道視窗控制代碼如何獲取視窗裡的所有文字?

3樓:

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得到內容。但是窗體上的標籤是找不到的……

4樓:匿名使用者

窗體上的文字,實際上在該窗體上的子窗體(就是窗體上的控制元件,如標籤控制元件,按鈕控制元件等)上的文字,你必須列舉該窗體下的子窗體後,再用getwindowtext獲取內容。

系統目錄獲取VB

登錄檔 hkey current user software microsoft windows currentversion explorer shell folders 再就是environ vb6?那用fso這個com net在my.computer空間 vb獲取不到系統目錄 將 dim sy...

vb怎麼獲取文字框裡的字串,VB怎麼獲取文字框裡的字串

先定義一個變數,然後將變數設定為文字框的內容即可。如下 以獲取text1控制元件為例 dim str1 as string 定義字元變數private sub text1 change 當text1字元改變時 str1 text1.text 設定為文字框的字串end sub dim a as str...

vb有多個frame,每個frame有多個optionbut

把你所有的optionbutton複製成控制元件組。然後在 option1 mouseup 事件中新增以下 for i 0 to option1.uboundoption1 i value falseif i index then option1 i value true next 把所有的opti...