2015-08-08 80 views
1
Declare Function GetForegroundWindow Lib "user32.dll"() As Int32 

Declare Function GetWindowThreadProcessId Lib "user32.dll" (
    ByVal hwnd As Int32, 
    ByRef lpdwProcessId As Int32) As Int32 

Public Function RetCurTitle() As Integer 
    Dim processID As Int32 
    Return GetWindowThreadProcessId(GetForegroundWindow(), processID) 
End Function 

我使用上述函数来获取活动窗口的进程ID。它返回4060AppActivate不适用于进程ID

之后,我打电话

AppActivate(4060) 

和应用程序崩溃。我尝试使用整数变量来代替4060,但同样的问题。

+0

您没有正确使用GetWindowThreadProcessId()。您正在返回拥有窗口的线程的*线程ID *,而不是进程ID。 –

回答

1

您的RetCurTitle()函数返回返回值GetWindowThreadProcessId(),这是线程ID,而不是进程ID。将您的功能更改为:

Public Function RetCurTitle() As Int32 
    Dim processID As Int32 
    GetWindowThreadProcessId(GetForegroundWindow(), processID) 
    Return processID 
End Function 
相关问题