I'v got a problem when using the WindowsAPI "WindowFromPoint_(m)".Why the code below alway returns zero?And how can I use the "WindowFromPoint_()" function?
Code: Select all
m.point
m\x = 100
m\y = 100
Debug WindowFromPoint_(m)
Code: Select all
m.point
m\x = 100
m\y = 100
Debug WindowFromPoint_(m)
Code: Select all
m.point
m\x = 100
m\y = 100
Debug WindowFromPoint_(PeekQ(@m))
Code: Select all
m.point
m\x = 100
m\y = 100
Debug WindowFromPoint_(m\y << 32 + m\x)
Code: Select all
m.q
PokeL(@m, 100)
PokeL(@m+4, 100)
Debug WindowFromPoint_(m)
Code: Select all
Structure QuadPointUnion
StructureUnion
p.POINT
q.q
EndStructureUnion
EndStructure
m.QuadPointUnion
m\p\x = 100
m\p\y = 100
Debug WindowFromPoint_(m\q)
Code: Select all
m.POINT
m\x = 100
m\y = 100
Debug WindowFromPoint_(Val("$"+RSet(Hex(m\y), 8, "0")+RSet(Hex(m\x), 8, "0")))
Code: Select all
Import ""
WindowFromPoint(X.l, Y.l)
EndImport
m.POINT
m\x = 100
m\y = 100
Debug WindowFromPoint(m\x, m\y)
Try that one on x64Trond wrote:There is simply NO MERCY!Code: Select all
Import "" WindowFromPoint(X.l, Y.l) EndImport m.POINT m\x = 100 m\y = 100 Debug WindowFromPoint(m\x, m\y)
Hi,Trond.Trond wrote:It's a long story, but PB does not support passing structures as parameters by value, only by reference. WindowFromPoint_() is one of the rare functions that need a structure by value. We can work around this by pretending the structure is a single quad, since both a quad and a POINT is 8 bytes:Code: Select all
m.point m\x = 100 m\y = 100 Debug WindowFromPoint_(PeekQ(@m))
Code: Select all
Structure pp
StructureUnion
p.Processentry32
EndStructureUnion
EndStructure
Global pe.pp
Procedure.s GetWinName(shandle.l)
oPid.l
GetWindowThreadProcessId_(shandle,@oPid)
Pth = CreateToolhelp32Snapshot_(#TH32CS_SNAPALL,oPid)
bOk = Process32First_(pth,pe\p)
Debug bOK
While bOk
If pe\p\th32processID = opid
Debug pe\p\szexefile
EndIf
bOk = Process32Next_(Pth,@pe)
Wend
EndProcedure
h = OpenWindow(0,0,0,300,160,"欧耶")
Debug GetwinName(h)
http://msdn.microsoft.com/en-us/library/ms684834%28VS.85%29.aspx wrote:The calling application must set the dwSize member of PROCESSENTRY32 to the size, in bytes, of the structure.
Code: Select all
Procedure.s GetWinName(shandle.l)
pe.Processentry32
pe\dwSize = SizeOf(Processentry32) ; <-------------------HERE
oPid.l
GetWindowThreadProcessId_(shandle,@oPid)
Pth = CreateToolhelp32Snapshot_(#TH32CS_SNAPALL,oPid)
bOk = Process32First_(pth,pe)
While bOk
If pe\th32processID = opid
procname$=Space(#MAX_PATH)
CopyMemory(@pe\szExeFile,@procname$,#MAX_PATH)
CloseHandle_(Pth)
ProcedureReturn procname$
EndIf
bOk = Process32Next_(Pth,@pe)
Wend
EndProcedure
h = OpenWindow(0,0,0,300,160,"??")
Debug GetwinName(h)
cas wrote:You forgot one thing:
http://msdn.microsoft.com/en-us/library/ms684834%28VS.85%29.aspx wrote:The calling application must set the dwSize member of PROCESSENTRY32 to the size, in bytes, of the structure.Code: Select all
Procedure.s GetWinName(shandle.l) pe.Processentry32 pe\dwSize = SizeOf(Processentry32) ; <-------------------HERE oPid.l GetWindowThreadProcessId_(shandle,@oPid) Pth = CreateToolhelp32Snapshot_(#TH32CS_SNAPALL,oPid) bOk = Process32First_(pth,pe) While bOk If pe\th32processID = opid procname$=Space(#MAX_PATH) CopyMemory(@pe\szExeFile,@procname$,#MAX_PATH) CloseHandle_(Pth) ProcedureReturn procname$ EndIf bOk = Process32Next_(Pth,@pe) Wend EndProcedure h = OpenWindow(0,0,0,300,160,"??") Debug GetwinName(h)
Code: Select all
Global pe.Processentry32
pe\dwsize = SizeOf(Processentry32)
Procedure.s GetWinName(shandle.l)
oPid.l
GetWindowThreadProcessId_(shandle,@oPid)
Pth = CreateToolhelp32Snapshot_(#TH32CS_SNAPALL,0)
bOk = Process32First_(pth,pe)
While bOk
If pe\th32processID = opid
Debug PeekS(@pe\szexefile, -1, #PB_Ascii)
EndIf
bOk = Process32Next_(Pth,pe)
Wend
EndProcedure
h = OpenWindow(0,0,0,300,160,"欧耶")
Debug GetwinName(h)
Code: Select all
Debug GetFilePart(ProgramFilename())
Thank you,cas!cas wrote:I don't see use of global variable "pe.Processentry32" in your code and you are still having memory leak because there is missing "CloseHandle_(Pth)".![]()
You can always use this to get exe name of your own application:Code: Select all
Debug GetFilePart(ProgramFilename())