khacharn
asked on
has somebody any idea on how to use GetWindowModuleFileName
hi all
i have a simple problem...
i have the code to know the active window on the desktop...
my problem is how to get the filepath of the file open in that window...
i tried using GetWindowModuleFileName() but it is not giving any output...
please help me...as soon as possible..
points will not be aa constraint if somebody help me solve the problem as soon as possible..
khacharn
i have a simple problem...
i have the code to know the active window on the desktop...
my problem is how to get the filepath of the file open in that window...
i tried using GetWindowModuleFileName() but it is not giving any output...
please help me...as soon as possible..
points will not be aa constraint if somebody help me solve the problem as soon as possible..
khacharn
Private Declare Function GetWindowModuleFileName Lib "user32" Alias "GetWindowModuleFileNameA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Sub Command1_Click()
Dim s As String
Dim ret As Long
s = String(260, 0)
ret = GetWindowModuleFileName(hW nd, s, 259)
s = Left(s, ret)
Debug.Print s
End Sub
Cheers
Private Sub Command1_Click()
Dim s As String
Dim ret As Long
s = String(260, 0)
ret = GetWindowModuleFileName(hW
s = Left(s, ret)
Debug.Print s
End Sub
Cheers
Private Declare Function GetWindowModuleFileName Lib "user32" Alias "GetWindowModuleFileNameA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Function FileNameFromHandle(ByVal hWnd As Long) As String
Dim s As String
Dim ret As Long
s = String(260, 0)
ret = GetWindowModuleFileName(hW nd, s, 259)
FileNameFromHandle = Left(s, ret)
End Function
'===Using===
Private Sub Command1_Click()
Debug.Print FileNameFromHandle(hWnd)
End Sub
Cheers
Private Function FileNameFromHandle(ByVal hWnd As Long) As String
Dim s As String
Dim ret As Long
s = String(260, 0)
ret = GetWindowModuleFileName(hW
FileNameFromHandle = Left(s, ret)
End Function
'===Using===
Private Sub Command1_Click()
Debug.Print FileNameFromHandle(hWnd)
End Sub
Cheers
ASKER
both the codes are not working
there is no path being returned...
it gives empty string...
please help soon
khacharn
there is no path being returned...
it gives empty string...
please help soon
khacharn
Works fine for me. Return path to VB50.exe
Which OS do you use?
Cheers
Which OS do you use?
Cheers
ASKER
both the codes are not working
there is no path being returned...
it gives empty string...
please help soon
khacharn
there is no path being returned...
it gives empty string...
please help soon
khacharn
ASKER
i am using WinNT..
donno why is it not working...
but hey this not what i want...
let me explain...
i want to know the filepath of the file which is opened ..
say if my current active application is WORD and i have a file opened from c:\cheeku\2.doc then i need the code which will return me the path above...
i hope i am clear..
please help soon on this...
khacharn
donno why is it not working...
but hey this not what i want...
let me explain...
i want to know the filepath of the file which is opened ..
say if my current active application is WORD and i have a file opened from c:\cheeku\2.doc then i need the code which will return me the path above...
i hope i am clear..
please help soon on this...
khacharn
Hi
If you're using NT/2000, these functions won't work (see http://support.microsoft.com/support/kb/articles/Q228/4/69.asp). You have to use psapi.dll instead.
If you're using NT/2000, these functions won't work (see http://support.microsoft.com/support/kb/articles/Q228/4/69.asp). You have to use psapi.dll instead.
ASKER
bad news...but can i get my thing done some other way...?
please help
did you get exactly what i want to do ?
khacharn
please help
did you get exactly what i want to do ?
khacharn
Sorry, have no more time today, I'll send answer tomorrow.
In brief - you need following API:
GetWindowThreadProcessID to get process pid.
OpenProcess - to get hProcess
Public Declare Function EnumProcessModules Lib "psapi.dll" _
(ByVal hProcess As Long, ByRef lphModule As Long, _
ByVal cb As Long, ByRef cbNeeded As Long) As Long
to enum, say, first 1 module in process
Public Declare Function GetModuleFileNameExA Lib "psapi.dll" _
(ByVal hProcess As Long, ByVal hModule As Long, _
ByVal ModuleName As String, ByVal nSize As Long) As Long
to get exe name
Cheers
In brief - you need following API:
GetWindowThreadProcessID to get process pid.
OpenProcess - to get hProcess
Public Declare Function EnumProcessModules Lib "psapi.dll" _
(ByVal hProcess As Long, ByRef lphModule As Long, _
ByVal cb As Long, ByRef cbNeeded As Long) As Long
to enum, say, first 1 module in process
Public Declare Function GetModuleFileNameExA Lib "psapi.dll" _
(ByVal hProcess As Long, ByVal hModule As Long, _
ByVal ModuleName As String, ByVal nSize As Long) As Long
to get exe name
Cheers
ASKER
ARK Hi..
i think you are not getting the requirements...
my problem is that i need to finf out the ACTIVE application....it can be WORD/EXCEL/ACROBAT READER...
after this i just need to know the path of the file open the the active application....i don't need the path of the application I NEED THE PATH OF THE ACTIVE DOCUMENT...
i think you must now have a a better idea of what i want..
please help soon
khacharn
i think you are not getting the requirements...
my problem is that i need to finf out the ACTIVE application....it can be WORD/EXCEL/ACROBAT READER...
after this i just need to know the path of the file open the the active application....i don't need the path of the application I NEED THE PATH OF THE ACTIVE DOCUMENT...
i think you must now have a a better idea of what i want..
please help soon
khacharn
khacharn,
A number of these questions are quite old. Please return and reward the Experts who have given you their time and knowledge in responding to your question.
https://www.experts-exchange.com/jsp/qShow.jsp?ta=mssql&qid=11503298
https://www.experts-exchange.com/jsp/qShow.jsp?ta=mssql&qid=11454878
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20176230
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20175433
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20174345
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20156027
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20155243
https://www.experts-exchange.com/jsp/qShow.jsp?ta=xml&qid=20011867
Thanks,
Netminder
Community Support Moderator
Experts Exchange
A number of these questions are quite old. Please return and reward the Experts who have given you their time and knowledge in responding to your question.
https://www.experts-exchange.com/jsp/qShow.jsp?ta=mssql&qid=11503298
https://www.experts-exchange.com/jsp/qShow.jsp?ta=mssql&qid=11454878
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20176230
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20175433
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20174345
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20156027
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20155243
https://www.experts-exchange.com/jsp/qShow.jsp?ta=xml&qid=20011867
Thanks,
Netminder
Community Support Moderator
Experts Exchange
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://feitsui.hyd.ncku.edu.tw/TLCheng/Basic/MyStdInclude/Basic/window.txt
?