怎样用API找到已打开的窗体并改更改窗体的标题?谢谢大虾

解决方案 »

  1.   

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As LongPrivate Sub Command1_Click()
        
        Dim lngRet As Long
        Dim strA As String
        Dim strKey As String
        
        strKey = "Form1"
        lngRet = FindWindow(strA, strKey)
        If lngRet <> 0 Then
            lngRet = SetWindowText(lngRet, "修改的标题")
        End If
        
    End Sub
      

  2.   

    '改变窗口标题
    Private Declare Function SetWindowText Lib "user32" _
        Alias "SetWindowTextA" (ByVal hwnd As Long, _
        ByVal lpString As String) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _
        lpClassName As String, ByVal lpWindowName As String) As LongPrivate Sub Command1_Click()
        Dim hwndCalc As Long
        hwndCalc = FindWindow(vbNullString, "Form2")
        SetWindowText hwndCalc, "Welcome to VB"
    End SubPrivate Sub Command2_Click()
        Form2.Show
    End Sub