For the archives, the solution was that I needed to use memoryblocks
instead of PString... like this:
--------------------------------------------------------------
Function GetFrontWindowName() As string
dim err as integer
dim mem as MemoryBlock
dim maxlen as integer
dim str as string
mem = new MemoryBlock(255)
Declare Function GetForegroundWindow Lib "user32.dll" As Integer
Soft Declare Function GetWindowTextA Lib "User32.dll" ( hwnd As
Integer, lpString As Ptr, nMaxCount as integer ) as Integer
Soft Declare Function GetWindowTextW Lib "User32.dll" ( hwnd As
Integer, lpString As Ptr, nMaxCount as integer ) as Integer
Try
maxlen = GetWindowTextW(GetForegroundWindow(),mem,255)
Catch
maxlen = GetWindowTextA(GetForegroundWindow(),mem,255)
End
str = mem.StringValue(0,maxlen*2)
str = str.DefineEncoding(encodings.UTF16)
str = str.ConvertEncoding(Encodings.WindowsANSI)
return str
End Function
--------------------------------------------------------------
If anyone has an idea on how to do this on Mac OS X, I'd surely like
to know!
Greg
On Mar 14, 2006, at 4:07 pm, 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.
Greg
P.S. - If anyone has an idea about how to get it on Mac OS X that
would be cool too!
_______________________________________________
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>
_______________________________________________
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>