How do I create a "select folder OR file dialog window" in REALbasic? - realbasic

You can use
SelectFolder() to get a folder
or
GetOpenFolderitem(filter as string) to get files
but can you select either a folder or file? ( or for that matter selecting multiple files )

The MonkeyBread plugin allows this in the OpenDialogMBS class.
http://www.monkeybreadsoftware.net/pluginhelp/navigation-opendialogmbs.shtml
OpenDialogMBS.AllowFolderSelection as Boolean
property, Navigation, MBS Util Plugin (OpenDialog), class OpenDialogMBS, Plugin version: 7.5, Mac OS X: Works, Windows: Does nothing, Linux x86: Does nothing, Feedback.
Function: Whether folders can be selected.
Example:
dim o as OpenDialogMBS
dim i,c as integer
dim f as FolderItem
o=new OpenDialogMBS
o.ShowHiddenFiles=true
o.PromptText="Select one or more files/folders:"
o.MultipleSelection=false
o.ActionButtonLabel="Open files/folders"
o.CancelButtonLabel="no, thanks."
o.WindowTitle="This is a window title."
o.ClientName="Client Name?"
o.AllowFolderSelection=true
o.ShowDialog
c=o.FileCount
if c>0 then
for i=0 to c-1
f=o.Files(i)
FileList.List.AddRow f.AbsolutePath
next
end if
Notes:
Default is false.
Setting this to true on Windows or Linux has no effect there.
(Read and Write property)

It's not possible via any of the built-in APIs. There might be a plugin to do it, but I don't think there's OS support for it.

A bit late, but it's been included in recent versions. I'll put it here in case someone stumbles like me in this question:
RealBasic Multiple Selection: OpenDialog.MultiSelect

Assuming you're using .Net I think you'll need to create your own control (or buy one).

Related

How to register a windows file extension via the sdk on window 10.x

Note: this question is not about dart but the windows registry.
I've implemented a library and tooling (called dcli) to write cli apps in the dart language.
When a user types the name of a dart script on the command line I need windows to start dcli and pass the dart script and any command line arguments.
e.g.
hellow.dart a b c
Will result in the following command being run
dcli.bat hellow.dart a b c
I need to do this via the 'C' registry api (I'm calling the registry api from dart using its foreign function interface (ffi) which allows it to call C entry points). This part of the problem is already solved and I can successfully add registry keys from dart.
My problem is knowing what registry settings to create because, particularly with the advent of windows 10, the documentation is a mess.
This is my rather poor attempt so far.
// create a ProgID for dcli 'noojee.dcli'
regSetString(HKEY_CURRENT_USER,
r'\Software\Classes\noojee.dcli',
defaultRegistryValueName, 'dcli');
// associate the .dart extension with dcli's prog id
regSetString(HKEY_CURRENT_USER, r'\Software\Classes\.dart',
defaultRegistryValueName, 'noojee.dcli');
regSetString(HKEY_CURRENT_USER,
r'SOFTWARE\Classes\.dart\OpenWithProgids',
'noojee.dcli.dart', '');
// this path doesn't look correct
regSetExpandString(
HKEY_CURRENT_USER,
r'dcli\shell\open\command',
defaultRegistryValueName,
'c:\path\to\dcli.bat %1 %2 %3 %4 %5 %6 %7 %8 %9');
regSetString(
HKEY_CURRENT_USER,
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.dart\OpenWithList',
'a',
'dcli.bat');
regSetString(
HKEY_CURRENT_USER,
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.dart',
'MRUList',
'a');
regSetNone(
HKEY_CURRENT_USER,
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.dart\OpenWithProgids',
'noojee.dcli');
One thing that confuses me is the use of HKEY_CLASSES_ROOT.
The doco appears to say that it is read only but then goes on to show examples creating keys under it.
I have the added complication that vscode with the dart-code extension likes to add its own association (which makes no sense) and I need to override this if it exists but ideally make it an alternative on the explorer menu.
HKEY_CLASSES_ROOT is a virtual merged view of HKEY_CURRENT_USER\Software\Classes and HKEY_LOCAL_MACHINE\Software\Classes (on Win2000 and later). It is not read-only but writing to it is not the best idea because writes usually go to the machine part except the times it does not.
The FileExts key is undocumented, don't write to it.
In your code, r'dcli\shell\open\command' is incorrect, the first component in the classes key should be the progid the extension points to, try r'SOFTWARE\Classes\noojee.dcli\shell\open\command'.
It basically goes like this:
HKEY_CURRENT_USER\Software\Classes\.myext = myprogid
HKEY_CURRENT_USER\Software\Classes\myprogid\shell\verb\command = "c:\path\app.exe" "%1" (where %1 is replaced by the path of the file, %2 is only used for printers).
Thanks to #Anders I arrived at the following:
Note: defaultRegistryValueName is just an empty string ''.
const progIdPath = r'Software\Classes\.dart\OpenWithProgids';
if (regKeyExists(HKEY_CURRENT_USER, progIdPath)) {
regDeleteKey(HKEY_CURRENT_USER, progIdPath);
}
regCreateKey(HKEY_CURRENT_USER, progIdPath);
regSetString(HKEY_CURRENT_USER, progIdPath, 'noojee.dcli', '');
const commandPath = r'Software\Classes\noojee.dcli\shell\open\command';
if (regKeyExists(HKEY_CURRENT_USER, commandPath)) {
regDeleteKey(HKEY_CURRENT_USER, commandPath);
}
regCreateKey(HKEY_CURRENT_USER, commandPath);
regSetString(
HKEY_CURRENT_USER,
commandPath,
defaultRegistryValueName,
'"${DCliPaths().pathToDCli}" '
'"%1"%*');
The only issues is that the %* doesn't seem to be doing anything useful.
From the doco I've found it should expand any no. of args (e.g. more than 9) however I only ever get 8 (as %1 is the command itself) and "%1" yeilds the same result as "%1"%*

How to cancel the binding of option key in OSX?

I know that OXS bind special keys on option key, such as option+y=¥,option+t=þ... But now, I want to cancel all these bindings, and use option+character as the shortcuts in JetBrains IDEs and other apps.
I have searched for hours and still haven't found a useful way.Can anyone share a tool or the correct way?I used the way to add Library/KeyBindings/DefaultKeyBinding.dict file, but it only canceled some key-bindings, not work for all.
It is my DefaultKeyBinding.dict file below :
{
"~d" = "deleteWordForward:";
"^w" = "deleteWordBackward:";
"~f" = "moveWordForward:";
"~b" = "moveWordBackward:";
"~u" = "pageUp:";
}
Now ,option+f/b can used as my jetbrains IDEs shortcut,but option+u still print special character.
I have found a way: if I select Unicode Hex Input as my input source from System preferences->keyBoard->Input Sources, all bindings now disappeared!

VB6, Adding an integer to a control name in a for loop

I am currently trying you learn VB6 and came across this issue.
I wanted to loop through a for loop and adding a number to a control name.
Dim I As Integer
For I = 1 To 5
S = CStr(I)
If TextS.Text = "" Then
LabelS.ForeColor = &HFF&
Else
LabelS.ForeColor = &H80000012
End If
Next I
This S needs to be added to Text and Label so the colour will be changed without needing to use 5 If Else statements
I hope you can help me with this.
From your comment below:
What i mean is this: If Text1.text = "" Then I need this 1 to be replaced with the variable I, so the for loop can loop through my 5 textboxes and the same for my Labels.
You can't do that (look up a variable using an expression to create its name) in VB6. (Edit: While that statement is true, it's not true that you can't look up form controls using a name from an expression. See "alternative" below.)
What you can do is make an array of your textboxes, and then index into that array. The dev env even helps you do that: Open your form in the dev env and click the first textbox. Change its name to the name you want the array to have (perhaps TextBoxes). Then click the next textbox and change its name to the same thing (TextBoxes). The dev env will ask you:
(Don't ask me why I have a VM lying around with VB6 on it...)
Click Yes, and then you can rename your other textboxes TextBoxes to add them to the array. Then do the same for your labels.
Then your code should look like this:
For I = TextBoxes.LBound To TextBoxes.UBound
If TextBoxes(I).Text = "" Then
Labels(I).ForeColor = &HFF&
Else
Labels(I).ForeColor = &H80000012
End If
Next
LBound is the lowest index of the control array, UBound is the highest. (You can't use the standard LBound and Ubound that take the array as an argument, because control arrays aren't quite normal arrays.) Note also that there's no need to put I on the Next line, that hasn't been required since VB4 or VB5. You can, though, if you like being explicit.
Just make sure that you have exactly the same number of TextBoxes as Labels. Alternately, you could create a user control that consisted of a label and a textbox, and then have a control array of your user control.
Alternative: : You can use the Controls array to look up a control using a name resulting from an expression, like this:
For I = 1 To 5
If Me.Controls("Text" & I).Text = "" Then
Me.Controls("Label" & I).ForeColor = &HFF&
Else
Me.Controls("Label" & I).ForeColor = &H80000012
End If
Next
This has the advantage of mapping over to a very similar construct in VB.Net, should you migrate at some point.
Side note:
I am currently trying you learn VB6...
(tl;dr - I'd recommend learning something else instead, VB6 is outdated and the dev env hasn't been supported in years.)
VB6's development environment has been discontinued and unsupported for years (since 2008). The runtime is still (I believe) supported because of the sheer number of apps that use it, although the most recent patch seems to be from 2012. But FWIW, you'd get a better return on your study time learning VB.net or C#.Net (or any of several non-Microsoft languages), rather than VB6...

how to bring the choose.file() dialog to the foreground

I'm using the function choose.dir() in a script that is run with rscript.exe under Windows XP. The problem is that the directory choosing dialog does not pop up as a top-level window. How can I bring the dialogue to the foreground?
In the meantime, I solved my problem by using visual basic script. Of course, this only works with windows:
tf <- tempfile(fileext = '.vbs')
cat('Set folder = CreateObject("Shell.Application") _
.BrowseForFolder(0, "Please choose a folder" _
, &H0001, 17)
Wscript.Echo folder.Self.Path
', file = tf)
tail(shell(paste('Cscript', tf), intern = T), 1)
After searching the rhelp archives it appears the answer is that you can't use choose.dir and file.choose in a non-interactive session. You might be able to do something similar, since list.files, file.info, file.access and files can be used to gather information, you can display this by writing to a graphics device and executing a system() call to get it displayed, and readLines can be used to get user input.

How to set "Run as administrator" flag on shortcut created by MSI installer

I have a Setup and Deployment project in Visual Studio 2010.
I would like the installer to create two shortcuts to the executable of another project in my solution. One normal shortcut that simply runs the application using current credentials and another which has the Run as administrator flag set, thereby ensuring that the user is asked for credentials with administrative rights when clicking the shortcut.
Running the application with administrative rights enables certain features that are otherwise not available.
Setting this flag doesn't seem to be possible at first glance. Can this be done directly in Visual Studio? If not, are there any other options?
Edit: If not, is it possible to modify the shortcut programmatically using a custom installer class?
I know this is quite an old question, but I needed to find an answer and I thought I could help other searchers. I wrote a small function to perform this task in VBScript (pasted below). It is easily adapted to VB.net / VB6.
Return codes from function:
0 - success, changed the shortcut.
99 - shortcut flag already set to run as administrator.
114017 - file not found
114038 - Data file format not valid (specifically the file is way too small)
All other non-zero = unexpected errors.
As mentioned by Chada in a later post, this script will not work on msi Advertised shortcuts. If you use this method to manipulate the bits in the shortcut, it must be a standard, non-advertised shortcut.
References:
MS Shortcut LNK format: http://msdn.microsoft.com/en-us/library/dd871305
Some inspiration: Read and write binary file in VBscript
Please note that the function does not check for a valid LNK shortcut. In fact you can feed it ANY file and it will alter Hex byte 15h in the file to set bit 32 to on.
If copies the original shortcut to %TEMP% before amending it.
Daz.
'# D.Collins - 12:58 03/09/2012
'# Sets a shortcut to have the RunAs flag set. Drag an LNK file onto this script to test
Option Explicit
Dim oArgs, ret
Set oArgs = WScript.Arguments
If oArgs.Count > 0 Then
ret = fSetRunAsOnLNK(oArgs(0))
MsgBox "Done, return = " & ret
Else
MsgBox "No Args"
End If
Function fSetRunAsOnLNK(sInputLNK)
Dim fso, wshShell, oFile, iSize, aInput(), ts, i
Set fso = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")
If Not fso.FileExists(sInputLNK) Then fSetRunAsOnLNK = 114017 : Exit Function
Set oFile = fso.GetFile(sInputLNK)
iSize = oFile.Size
ReDim aInput(iSize)
Set ts = oFile.OpenAsTextStream()
i = 0
Do While Not ts.AtEndOfStream
aInput(i) = ts.Read(1)
i = i + 1
Loop
ts.Close
If UBound(aInput) < 50 Then fSetRunAsOnLNK = 114038 : Exit Function
If (Asc(aInput(21)) And 32) = 0 Then
aInput(21) = Chr(Asc(aInput(21)) + 32)
Else
fSetRunAsOnLNK = 99 : Exit Function
End If
fso.CopyFile sInputLNK, wshShell.ExpandEnvironmentStrings("%temp%\" & oFile.Name & "." & Hour(Now()) & "-" & Minute(Now()) & "-" & Second(Now()))
On Error Resume Next
Set ts = fso.CreateTextFile(sInputLNK, True)
If Err.Number <> 0 Then fSetRunAsOnLNK = Err.number : Exit Function
ts.Write(Join(aInput, ""))
If Err.Number <> 0 Then fSetRunAsOnLNK = Err.number : Exit Function
ts.Close
fSetRunAsOnLNK = 0
End Function
This is largely due to the fact that Windows Installer uses 'Advertised shortcuts' for the Windows Installer packages.
There is no way inherently to disable this in Visual Studio, but it is possible to modify the MSI that is produced to make sure that it does not use advertised shortcuts (or uses only one). There are 2 ways of going about this:
If your application uses a single exe or two - Use ORCA to edit the MSI. Under the shortcuts table, change the Target Entry to "[TARGETDIR]\MyExeName.exe" - where MyExeName is the name of your exe - this ensures that that particular shortcut is not advertised.
Add DISABLEADVTSHORTCUTS=1 to the the property Table of the MSI using ORCA or a post build event (using the WiRunSQL.vbs script). If you need more info on this let me know. This disables all advertised shortcuts.
it may be better to use the first approach, create 2 shortcuts and modify only one in ORCA so that you can right click and run as admin.
Hope this helps
This is not supported by Windows Installer. Elevation is usually handled by the application through its manifest.
A solution is to create a wrapper (VBScript or EXE) which uses ShellExecute with runas verb to launch your application as an Administrator. Your shortcut can then point to this wrapper instead of the actual application.
Sorry for the confusion - I now understand what you are after.
There are indeed ways to set the shortcut flag but none that I know of straight in Visual Studio. I have found a number of functions written in C++ that set the SLDF_RUNAS_USER flag on a shortcut.
Some links to such functions include:
http://blogs.msdn.com/b/oldnewthing/archive/2007/12/19/6801084.aspx
http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/thread/a55aa70e-ae4d-4bf6-b179-2e3df3668989/
Another interesting discussion on the same topic was carried out at NSIS forums, the thread may be of help. There is a function listed that can be built as well as mention of a registry location which stores such shortcut settings (this seems to be the easiest way to go, if it works) - I am unable to test the registry method at the moment, but can do a bit later to see if it works.
This thread can be found here: http://forums.winamp.com/showthread.php?t=278764
If you are quite keen to do this programatically, then maybe you could adapt one of the functions above to be run as a post-install task? This would set the flag of the shortcut after your install but this once again needs to be done on Non-Advertised shortcuts so the MSI would have to be fixed as I mentioned earlier.
I'll keep looking and test out the registry setting method to see if it works and report back.
Chada
I needed to make my application to be prompted for Administator's Rights when running from Start Menu or Program Files.
I achieved this behavior after setting in \bin\Debug\my_app.exe 'Run this program as administator' checkbox to true. ( located in Properties\Compatibility section ).
While installing project, this file was copied to the Program Files (and therefore the shortcut in the Start Menu) with needed behavior.
Thanks,
Pavlo

Resources