如何实现
用自己的程序控制另一个程序具备刷新(类似于按F5那样产生的效果)的功能?那个程序有一个快捷键f5是刷新的。  如何实现如何实现阿!!!!!!!!!还有
http://community.csdn.net/Expert/topic/3221/3221750.xml?temp=.1629755
有没有更好的方法阿?
我用的是
将所有的内容提取,晒选小节的值,在将所有的内容写回去,又慢又麻烦。
拜托诸位了。

解决方案 »

  1.   

    //用自己的程序控制另一个程序具备刷新(类似于按F5那样产生的效果)的功能?那个程序有一个快捷键f5是刷新的。  先使另一个程序获得焦点,然后发送键盘消息(简单点的就用sendkeys)
      

  2.   

    不知道你具体要刷新什么程序,下面我以刷新ie为例说明以下:
    窗体:一个listbox
    窗体代码:
    Option Explicit
    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 FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Const SW_RESTORE = 9
    Dim mhwnd() As LongPrivate Sub Form_Load()
        Dim MyStr As String
        Dim i As Long
        Dim test_hwnd As Long
        i = 0
        test_hwnd = FindWindowEx(0, 0, "IEFrame", vbNullString)
        Do While test_hwnd <> 0
            ReDim Preserve mhwnd(i)
            mhwnd(i) = test_hwnd
            MyStr = String(100, Chr$(0))
            GetWindowText test_hwnd, MyStr, 100
            MyStr = Left$(MyStr, InStr(MyStr, Chr$(0)) - 1)
            List1.AddItem CStr(test_hwnd) + "-----" + MyStr
            test_hwnd = FindWindowEx(0, test_hwnd, "IEFrame", vbNullString)
            i = i + 1
        Loop
    End SubPrivate Sub List1_Click() '刷新指定的ie窗口
        Dim whwnd As Long
        whwnd = mhwnd(List1.ListIndex)
        ShowWindow whwnd, SW_RESTORE
        SendKeys "{F5}"
    End Sub
      

  3.   

    为何针对serv_u 这款软件就不行呢????????????似乎无法获得焦点并刷新发送不过去?
      

  4.   

    //为何针对serv_u 这款软件就不行呢给个下载地址
      

  5.   

    这款软件公司以前就有   您可以在www.baidu.com上查  可以查到
      

  6.   

    加上一句SetForegroundWindow whwnd就可以了:
    Option Explicit
    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 FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private Const SW_RESTORE = 9
    Dim mhwnd() As LongPrivate Sub Form_Load()
        Dim MyStr As String
        Dim i As Long
        Dim test_hwnd As Long
        i = 0
        test_hwnd = FindWindowEx(0, 0, "TAdminForm", vbNullString)
        Do While test_hwnd <> 0
            ReDim Preserve mhwnd(i)
            mhwnd(i) = test_hwnd
            MyStr = String(100, Chr$(0))
            GetWindowText test_hwnd, MyStr, 100
            MyStr = Left$(MyStr, InStr(MyStr, Chr$(0)) - 1)
            List1.AddItem CStr(test_hwnd) + "-----" + MyStr
            test_hwnd = FindWindowEx(0, test_hwnd, "TAdminForm", vbNullString)
            i = i + 1
        Loop
    End SubPrivate Sub List1_Click() '刷新指定的serv-U窗口
        Dim whwnd As Long
        whwnd = mhwnd(List1.ListIndex)
        SetForegroundWindow whwnd
        ShowWindow whwnd, SW_RESTORE
        SendKeys "{F5}"
    End Sub
      

  7.   

    非常感谢
    rainstormmaster 
    最终结决
    Public Function S_servU()  '/向目标窗体发送刷新消息
        Dim test_hwnd As Long
        
        test_hwnd = FindWindowEx(0, 0, "TAdminForm", vbNullString)
        
        SetForegroundWindow test_hwnd
        
        ShowWindow test_hwnd, SW_RESTORE
        
        SendKeys "%VZ"
        SendKeys "{F5}"
        
    End Function