用CType轉(zhuǎn)成你的窗口類(lèi)型就可以引用了
創(chuàng)新互聯(lián)建站主要從事成都做網(wǎng)站、網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)憑祥,10多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專(zhuān)業(yè),歡迎來(lái)電咨詢(xún)建站服務(wù):18980820575
比如你的子窗口類(lèi)是MyForm
單擊父窗口Button2顯示它包含字符串MyPath的內(nèi)容的代碼如下
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox(CType(Me.ActiveMdiChild, MyForm).MyPath)
End Sub
將NewForm設(shè)置為全局變量就可以了,如果新建窗口比較多,就設(shè)置為數(shù)組,例如:
Public Class Form1
Dim NewForm(10) As Form
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
NewForm(0) = New Form
NewForm(0).Show()
End Sub
End Class
根據(jù)補(bǔ)充信息,修改如下:
在窗體上加入控件command1,然后復(fù)制下面代碼,運(yùn)行,啟動(dòng)畫(huà)圖程序,單擊command1,即可找到你要的畫(huà)紙的句柄!
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 Sub Command1_Click()
Dim huatu, huazi
Dim i As Integer
huatu = FindWindowEx(0, 0, vbNullString, "未命名 - 畫(huà)圖")
Do Until huatu = 0
huazi = FindWindowEx(huatu, 0, "AfxFrameOrView42u", vbNullString)
huazi = FindWindowEx(huazi, 0, "Afx:1000000:8", vbNullString)
i = i + 1
MsgBox "找到第" i "個(gè)畫(huà)紙,它的句柄是:" huazi
huatu = FindWindowEx(0, huatu, vbNullString, "未命名 - 畫(huà)圖")
Loop
End Sub