coda
Junior Member
Posts: 74
|
Post by coda on Jan 31, 2024 3:13:11 GMT -5
Hi... just wondering if anyone knows if there is some magical way to find a user's default word processor using either LB or win32api or will I have to ask my user to find the path to the .exe etc... depending on the OS. Any help greatly appreciated.
|
|
|
Post by tsh73 on Jan 31, 2024 4:44:38 GMT -5
You probably need that EXE just to pass somefile.docx to it Try to leave it to Windows "run explorer.exe some_path\somefile.docx" - opens Microsoft Word for me. Even for paths/file names with spaces.
|
|
|
Post by metro on Jan 31, 2024 8:02:50 GMT -5
I dug this out of someone's code, it maybe useful
File2check$= "clipboardAPI.pdf" ' has to exist
lpszFile$= File2check$ lpszDirectory$ = Path2File$(/Folder) ' doesn't seem to need the folder if the file is in the DefaultDir$"
lpszResult$ = space$(255) + chr$(0) ' set up empty buffer calldll #shell32, "FindExecutableA", _ lpszFile$ as ptr,lpszDirectory$ as ptr,lpszResult$ as ptr, _ result as long
print trim$(lpszResult$)
'result for me =C:\Program Files\Foxit Software\Foxit Reader\FoxitPDFReader.exe (Linux/Wine)
|
|
|
Post by xxgeek on Jan 31, 2024 11:01:26 GMT -5
Thanks metro, nice piece of code for future use.
I did a bit of testing and editing just to make it more understandable for any new users.
Your code works with any file type, but if a file type has NO associated program to open it, your code returns an empty string.
'posted by metro at LB forums 'Finds the associated program for any file you point to 'The file must exist for this to work.
'Test files 'File2check$= "clipboardAPI.pdf" ' as is this file has to exist in DefaultDir$ File2check$= "demo.bas" ' as is this file has to exist in DefaultDir$ 'File2check$= "C:\Users\exexg\Desktop\B2E\autoSave.vbs" 'File2check$= "C:\\Intel\new\pdf\test.pdf"
lpszFile$= File2check$ lpszDirectory$ = Path2File$'(/Folder) ' doesn't seem to need the folder if the file is in the DefaultDir$"
lpszResult$ = space$(255) + chr$(0) ' set up empty buffer calldll #shell32, "FindExecutableA", _ lpszFile$ as ptr,lpszDirectory$ as ptr,lpszResult$ as ptr, _ result as long
print trim$(lpszResult$)
'result for me using Windows 10 Pro = 'C:\Program Files (x86)\Just BASIC v2.0\jbasic.exe .bas files 'C:\Windows\System32\WScript.exe .vbs files 'C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe .pdf files'
|
|
|
Post by PaulDZ on Feb 1, 2024 0:48:15 GMT -5
I dug this out of someone's code, it maybe useful Metro, do you remember who's code you might have pulled this from? If so, please let us know so they can get the recognition they deserve. I also remember someone mentioning some kind of repository of code. Keeping that in mind, I've recoded the routines as functions with a few lines of code preceding them for testing purposes: dim info$(10, 10)
FileToCheck$= "dice.bas" print GetDefaultProgram$(FileToCheck$) wait end
Function GetDefaultProgram$(File2Check$) if fileExists(DefaultDir$, File2Check$)<>0 then ' Make sure the file exists lpszFile$= File2Check$ lpszDirectory$ = Path2File$'(/Folder) ' doesn't seem to need the folder if the file is in the DefaultDir$" lpszResult$ = space$(255) + chr$(0) ' set up empty buffer calldll #shell32, "FindExecutableA", _ ' make the Call lpszFile$ as ptr, _ lpszDirectory$ as ptr, _ lpszResult$ as ptr, _ result as long
GetDefaultProgram$ = lpszResult$ ' Set the result else GetDefaultProgram$ = "File Not Found" ' when file not found end if End Function
function fileExists(path$, filename$) 'dimension the array info$() at the beginning of your program (i.e. dim info$(10, 10)) files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
|
|
|
Post by metro on Feb 1, 2024 1:27:23 GMT -5
I dug this out of someone's code, it maybe useful Metro, do you remember who's code you might have pulled this from? If so, please let us know so they can get the recognition they deserve. Sorry Paul, EDIT: I have no idea what just happened , I posted along reply and it just disappeared
I made no notes in my own code as to where I found it.
In nutshell, many newsletters read over 10 years plus. Also Alyce's web site and over 460 emails from Stefan and over 1000 from others in the old Yahoo Users group. (that I still have)
Stefan quite often came up some gems when dealing with API's
it could have been anywhere.
I usually do make an effort to note code that is not mine when I post.
EDIT 2: Found it, Not sure I can post all the detail. What copyright is in place for old newsletters? grepping through my LB folder I see FindExecutable is mentioned in NL 119 too.
|
|
coda
Junior Member
Posts: 74
|
Post by coda on Mar 5, 2024 7:30:12 GMT -5
Thankyou, everyone. Sorry for the late response. I have very little access to internet, ATM. I appreciate your help greatly. I shall have a look at what you have all said, tonight. :-)
|
|
honky
Junior Member
Posts: 63
|
Post by honky on Mar 5, 2024 10:01:23 GMT -5
When I have this case, I put a "filedialog" and a notice that requires opening the file concerned. And I thus recover the full path.
|
|