PDA

View Full Version : How can I get the Command$?



ReneMiner
18-04-2013, 09:10
I want to make my program load associated data when clicking on some document - i.e. some TBGL3dEd-image in win-explorer.
I know from vb6 the command$ which returns the parameters that have been appended to filename when the app started. How can I get the "command$"-parameters so I know which file the user wants to open?

And related to this/other way: Is there a possibility to detect if some filename from explorer was dragged + dropped into TBGL-window?


Edit: First question is answered already- because after posting this- the related topic list on bottom did show the solution...I searched APP_.../Core and just "Command"

OS_Command(s) now I've found, and also that I have to truncate CHR$(34) -"- from start and end of string before using it.

But also found out something strange here: If I open a model from Explorer now, App_Scriptpath seems to get set to the path where the model is located and my script creates new Subfolders for Models, Textures and Undo inside the models path as if they were not present in App_Scriptpath. So textures won't load because scriptpath is wrong then.

Petr Schreiber
18-04-2013, 10:10
Hi Rene,

OS_GetCommand behaves differentely when in thinAir and when the script is launched separately.

Why?

Because thinBASIC passes you the whole command line which the core interpreter receives.

If you want to get the parameters relevant for you script only, I do it this way:


Uses "OS"

MsgBox 0, Script_Parameter(1) ' -- This should return the file name for you

' Description: Function returns nth parameter of the script
' -----------------------------------------------------------------------------
' Parameters:
' -----------------------------------------------------------------------------
' index: index of nth parameter, starting from 1
Function Script_Parameter( index As Long ) As String
Long paramOffset = IIf(StartsWith(OS_GetCommand(0), "@"), 2, 1)
Function = OS_GetCommand(index+paramOffset)
End Function



Petr

ReneMiner
18-04-2013, 10:21
I did that way:

OS_GetCommand(2) holds the models path + filename


If OS_GetCommands >= 2 Then
sFileToLoad = Mid$(OS_GetCommand(2), 2, Len(OS_GetCommand(2)) - 2)
Call_IfExists "LOAD_Model" + FILE_PathSplit(sFileToLoad, %PATH_EXT) (sFileToLoad) To bSuccess
EndIf


Made an exe from my project, rightclick in Explorer some modelfile - m15, obj or tbgl3ded - choose my exe to open it and the model gets loaded. All ok, works so far...
BUT: App_Scriptpath - which gets accessed way before this call, contains/returns the path where the model is located then - but not the real App_Scriptpath where the script is located.
The needed Subdirs of my script are not found inside the models path - why should they be there? - and get created here as if they were not present in App_Scriptpath. So the assumed Subfolders as Textures & Undo are empty - no texture gets loaded - unnecessary folders get created at wrong place - App_Scriptpath returns/contains a wrong value.

My working-directories are wrong now since they get created inside the clicked models-path :(

So I might return to second way: Is there some possibility to detect if some filename from Explorer was dragged & dropped into TBGL-Window?

OT: @ Petr- got new system?

Petr Schreiber
18-04-2013, 11:44
Hi Rene,

regarding TBGL window and drag'n'drop - I think it should be achieveable now by using the EventShaper (http://www.thinbasic.com/community/showthread.php?11780-EventShaper-experimental-module-to-wrap-ugly-Win32-messages-into-user-defined-form&highlight=event+module). There is no specific support for Win32 messages in TBGL as of now.

The APP_ScriptPath behaviour is strange, it should work the same as in script. I will have a look.

OT: Yes :D It is beautiful machine, with raw power up to 5x bigger (both CPU and GPU) than my Win7 notebook for the same price which the notebook cost 3 years ago. Incredible.


Petr

ReneMiner
18-04-2013, 12:10
Sorry, the EventShaper looks like a seven-sealed-book to me - too much win-specific - confusing stuff that I have no idea about - also it uses UI and callbacks which I don't have for my just-in-TBGL-window-app and I want to avoid callbacks anyway since they are not native to basic but some way to communicate with OS. I don't like being a slave to OS-rules and all those cumbersome methods - I want to use Basic-commands and -methods - that's why I did not create the app in UI-dialog and made my own controls - so not to have these "ugly beasts" and "alien-windows-variables" in my script.

I don't know where to start with and how to find out the Path nor the Filename that was dropped into the window. Neither do I know, how to append some callback-functions to TBGL-window and how to register if it was a drag&drop-action. And just for this function the effort and needed resources seem way too high - I'd rather create some check-back for the App_Scriptpath - even if it would mean to save the correct path to some ini-file to "C:\" on the users system. That's not nice, I know - but it's a basic-way.

Or should there an issue created about?

Petr Schreiber
19-04-2013, 10:17
Hi Rene,

if APP_ScriptPath returns something else than script path... it is ideal candidate for issue. Failing example would help a lot.
One possible temporary solution:


Function Script_Path() As String

Function = FILE_PathSplit(APP_ScriptFullName, %PATH_ROOTPATH)

End Function


Regarding EventShaper - I understand :) Could you please add a feature request for TBGL to accept dragged files?


Petr

ReneMiner
19-04-2013, 15:37
I created an issue (http://www.thinbasic.com/community/project.php?issueid=396) with some example-code attached.