Liberty BASIC Community Forum
« API's for Beginners »

Welcome Guest. Please Login or Register.
Dec 12th, 2017, 07:54am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 sticky  Author  Topic: API's for Beginners  (Read 1294 times)
datwill
Guest
xx Re: API's for Beginners
« Reply #15 on: Jan 22nd, 2015, 11:38am »

Yes, thanks! It would be hard to memorize the exact pattern in which I would actually create the progress bar or whatever, but I don't need to!
User IP Logged

datwill
Guest
xx Re: API's for Beginners
« Reply #16 on: Jan 24th, 2015, 10:21am »

I've learned at LBE: great! Just need to know what the class names are for the different controls (I know tab strips: SysTabStripControl32 or something similar). Well, what I'm actually saying is could you tell me?
User IP Logged

petermat
New Member
Image


member is offline

Avatar




PM


Posts: 39
xx Re: API's for Beginners
« Reply #17 on: Dec 2nd, 2016, 7:20pm »

I have a basic understanding of using API's - but cannot find my way around the maze of what is available. I would like to open a windows explorer window to allow the user to select an existing file known to them, (but not to the programmer) so that I can subsequently open that file. Can someone please point me to the correct API / DLL info?
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is online

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5585
xx Re: API's for Beginners
« Reply #18 on: Dec 3rd, 2016, 01:40am »

There is native command for that, no need for api

Filedialog
User IP Logged

petermat
New Member
Image


member is offline

Avatar




PM


Posts: 39
xx Re: API's for Beginners
« Reply #19 on: Dec 3rd, 2016, 09:10am »

Thank you - sorry not to have found it - looking in the wrong place.
« Last Edit: Dec 3rd, 2016, 09:25am by petermat » User IP Logged

petermat
New Member
Image


member is offline

Avatar




PM


Posts: 39
xx Re: API's for Beginners
« Reply #20 on: Dec 3rd, 2016, 3:02pm »

Ah, but! FileDialog, not surprisingly, allows the name of a file to be determined. However for one use I just need a folder path. Agreed I can say something like "Please select a random file in the folder you want the results files to appear. The file you select will not be overwritten!" - but this is a little clumsy. Am I still missing a 'FolderDialog' equivalent or does this push me to API, Or?
User IP Logged

MKnarr
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 431
xx Re: API's for Beginners
« Reply #21 on: Dec 3rd, 2016, 4:34pm »

It's not easy but if all you need is the folder:

Code:
BIF.RETURNONLYFSDIRS = 1
    MAX.PATH = 260
    STRUCT BrowseInfo,_
    hWndOwner As uLong,_
    pIDLRoot As Long,_
    pszDisplayName As Long,_
    lpszTitle$ As ptr,_
    ulFlags As Long,_
    lpfnCallback As Long,_
    lParam As Long,_
    iImage As Long
    'Set the owner window, optional
    BrowseInfo.hWndOwner.struct = 0
    BrowseInfo.lpszTitle$.struct = text$
    'Return only if the user selected a directory
    BrowseInfo.ulFlags.struct = BIF.RETURNONLYFSDIRS
    'Show the 'Browse for folder dialog
    calldll #shell32, "SHBrowseForFolder",_
    BrowseInfo as struct,_
    lpIDList as long
    If lpIDList>0 Then
        sPath$ = space$(MAX.PATH) + chr$(0)
        'Get the path from the IDList
        calldll #shell32, "SHGetPathFromIDList",lpIDList as long,sPath$ as ptr,r as long
        open "ole32" for dll as #ole
        'Free the block of memory
        calldll #ole, "CoTaskMemFree",_
        lpIDList as long,_
        r as long
        close #ole
        iNull = InStr(sPath$, chr$(0))
        If iNull Then sPath$ = Left$(sPath$, iNull - 1)
    End If
    print sPath$

 
User IP Logged

petermat
New Member
Image


member is offline

Avatar




PM


Posts: 39
xx Re: API's for Beginners
« Reply #22 on: Dec 3rd, 2016, 6:54pm »

Thanks people! I suspect it would have taken my waaaaay over five minutes to work out that 'folder only' code. But between that and Filedialog I have what I wanted.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is online

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5585
xx Re: API's for Beginners
« Reply #23 on: Dec 4th, 2016, 04:10am »

If you specify the name of the file in the filedialog command you achieve what you need. The user navigates to a folder and the return is the full path with the specified file name.

So if you can name the file first the user can select a destination folder of their choice.

Still no need for API.

Code:
filedialog "Save As...", "test.txt", fileName$
print "File chosen is ";fileName$
 


Also you can do some error checking if they click on another file name rather than just "save".

Code:
savename$="test.txt"

filedialog "Select Folder to Save results to", savename$, fullpath$
f$=afterlast$(fullpath$,"\")
p$=upto$(fullpath$,f$)
fullpath$=p$+savename$
 
« Last Edit: Dec 4th, 2016, 04:24am by Rod » User IP Logged

petermat
New Member
Image


member is offline

Avatar




PM


Posts: 39
xx Re: API's for Beginners
« Reply #24 on: Dec 4th, 2016, 12:15pm »

Who knew that a good way to find out more about native commends was to enquire in the API forum!
OK Rod - that's also neat, thanks. As you wrote it this code will save an unwanted file "test.txt" in the user selected folder. Of course this can be "Kill"ed. However somewhat to my surprise using Open instead of Save also works. I expected an error message on trying to 'open' a file that does not exist - but the following works fine:
savename$="test.txt"
filedialog "Select Folder to open", savename$, fullpath$
f$=afterlast$(fullpath$,"\")
p$=upto$(fullpath$,f$)
fullpath$=p$+savename$
print "Full path of the file chosen is ";fullpath$
print "Just the chosen folder path is "; p$

- though this is vulnerable to the user actually selecting a file and opening it.
« Last Edit: Dec 4th, 2016, 12:43pm by petermat » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is online

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5585
xx Re: API's for Beginners
« Reply #25 on: Dec 4th, 2016, 1:40pm »

It is the programmers choice whether the file gets saved or opened, the code is only returning the path and chosen file name whether for saving or opening.

You have to specifically open or save the file once the fullpath$ is returned.
User IP Logged

petermat
New Member
Image


member is offline

Avatar




PM


Posts: 39
xx Re: API's for Beginners
« Reply #26 on: Dec 4th, 2016, 4:55pm »

Yes - sorry, I should have said "it looks to the user as though they will save an unwanted file "test.txt" into their selected folder".

How nice to be faced with two ways of doing what I wanted!

Thanks again.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is online

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5585
xx Re: API's for Beginners
« Reply #27 on: Dec 5th, 2016, 02:26am »

MKnarr's solution is cleaner and less confusing. In my example the file name would need to be set to the one they expect to see. Like "results.dat"
User IP Logged

petermat
New Member
Image


member is offline

Avatar




PM


Posts: 39
xx Re: API's for Beginners
« Reply #28 on: Dec 5th, 2016, 09:49am »

Does the fun never end?
Agree that the McNarr solution is "cleaner and less confusing" - but, as shown it defaults to starting at "My Computer" - whereas in Rod's solution specifying a start point is easy. In order to define an alternative start point one with the McNarr solution one has to delve into converting the path you are interested in starting from into a "PIDL" - per the following API since I don't think there is a native function to do this:
https://support.microsoft.com/en-us/kb/132750.
and apply the PIDL to the supplied code per:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb773205(v=vs.85).aspx.
(Though the application apears straightforward.)
Or, for (arguably) an even cleaner solution smiley with even more coding complexity sad see
https://www.codeproject.com/kb/winsdk/win32tipsandtricks.aspx#browse1
!
« Last Edit: Dec 5th, 2016, 09:52am by petermat » User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls