GregO wrote:
I'm trying to get the name of the frontmost window of the frontmost
application in Windows and Mac OS X. So far, I am fighting with the
Windows side. Can anyone tell me why the following doesn't work?
Declare function GetForegroundWindow Lib "user32.dll" As Integer
Soft Declare Function GetWindowTextA Lib "User32" ( hwnd As Integer,
lpString As PString, nMaxCount as integer ) as Integer
Soft Declare Function GetWindowTextW Lib "User32" ( hwnd As Integer,
lpString As PString, nMaxCount as integer ) as Integer
Try
maxlen = GetWindowTextW(GetForegroundWindow(),str,255)
Catch
maxlen = GetWindowTextA(GetForegroundWindow(),str,255)
End
I get the correct maxlen, but the name is not returned in the str
variable.
You need to declare lpString as ptr and pass a memoryblock. Set the
memoryblock size to 255, and then get the result from
memoryblock.cstring(0). Like this:
Declare Function GetWindowTextA Lib "User32" ( hwnd as Integer,
buffer as Ptr, bytes as Integer ) as Integer
Declare function GetForegroundWindow Lib "user32.dll" As Integer
Dim buffer as memoryBlock
Dim ret as integer
buffer = newmemoryBlock(255)
ret = GetWindowTextA(GetForegroundWindow(),buffer,buffer.size)
msgBox buffer.cstring(0)
hth,
Brian
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>