Author Topic: Problem With Wiki Example  (Read 6485 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem With Wiki Example
« Reply #30 on: August 23, 2019, 01:32:46 pm »
Wow... I read all of these replies and I have no idea where to start on mine. Or is it possible yet? I feel like I just walked into a classroom of PhD programmers. :)

I fixed Tiny Navigator, should I start thread? I was going to try a files window like Steve has before posting.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Problem With Wiki Example
« Reply #31 on: May 13, 2020, 09:32:13 am »
The way I've found to get around the 64 vs 32 bit issue is using the 32 bit library for the 32 bit programs and using a PowerShell script to call an open file dialog in 64 bit versions instead and outputting the returned filename to a text file that I can read it back from.
PowerShell code:
Quote
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
    InitialDirectory = '.\'
    Filter = 'All Files (*.*)|*.*'
}
$null = $FileBrowser.ShowDialog()
$FileName = $FileBrowser.FileName
if ($FileName -ne ''){
Write-Host $FileName
$FileName > 'openfilename.txt'
exit 1
}
else{
exit 0
}
QB64 Code:
Code: QB64: [Select]
  1. SHELL$ = "PowerShell -WindowStyle Hidden -ExecutionPolicy Bypass " + CHR$(34) + "&'" + _STARTDIR$ + "\OpenFile.ps1';exit $LASTEXITCODE" + CHR$(34)
  2. IF a = 1 THEN
  3.     OPEN "openfilename.txt" FOR BINARY AS #1
  4.     LINE INPUT #1, OFile$
  5.     PRINT "Cancelled"
  6. OFile$ = RIGHT$(OFile$, LEN(OFile$) - 3)
  7. PRINT OFile$
You trim off the last three characters because there are some hidden characters that Windows Forms seems to add and they will screw up all the file handling if you don't trim them off. I hope this can help someone!
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Problem With Wiki Example
« Reply #32 on: May 13, 2020, 01:09:40 pm »
Here is a way to really adapt the open file dialog for 64 bit. The only issue is that you can't use the initial directory parameter due to the fact that it is through a PowerShell call. (Fixed this as I was writing this post.)
A screenshot of the dialog:
 
qb64 open file demo.png

Here is the PowerShell code, fully fixed to accept a custom title, Start Directory, and Filter for filetypes
Quote
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
}
$FileBrowser.Title = $args[0]
$initial = $args[1].ToString().Replace("/","\")
$FileBrowser.InitialDirectory = $initial
$chosenfilter = $args[2].ToString().Replace("^/^","|")
$FileBrowser.Filter = $chosenfilter

$null = $FileBrowser.ShowDialog()
$FileName = $FileBrowser.FileName
if ($FileName -ne ''){
$FileName > 'openfilename.txt'
exit 1
}
else{
exit 0
}
And here is the current QB64 code that would allow you to call a function similar to GetOpenFileNameA and display an Open File Dialog:
Code: QB64: [Select]
  1. OFile$ = GetOpenFileName64("Select a file, jackass", "C:\Users\zacharys\[redacted]\Desktop\QB64 Files\qb32", "QB64 Files (*.BAS)|*.bas|All Files (*.*)|*.*")
  2. FUNCTION GetOpenFileName64$ (Title$, InitialDir$, Filter$)
  3.     SHELL$ = "PowerShell -WindowStyle Hidden -ExecutionPolicy Bypass " + CHR$(34) + "&'" + _STARTDIR$ + "\OpenFile.ps1'"
  4.     SHELL$ = SHELL$ + " " + "\" + CHR$(34) + Title$ + "\" + CHR$(34)
  5.     IF INSTR(InitialDir$, "\") THEN
  6.         InitialDir$ = ReplaceStringItem(InitialDir$, "\", "/")
  7.     END IF
  8.     SHELL$ = SHELL$ + " " + "\" + CHR$(34) + InitialDir$ + "\" + CHR$(34)
  9.     IF INSTR(Filter$, "|") THEN
  10.         Filter$ = ReplaceStringItem(Filter$, "|", "^/^")
  11.         'Filter$ = ReplaceStringItem(Filter$, "/", "|")
  12.     END IF
  13.     SHELL$ = SHELL$ + " " + "\" + CHR$(34) + Filter$ + "\" + CHR$(34)
  14.     SHELL$ = SHELL$ + ";exit $LASTEXITCODE" + CHR$(34)
  15.     a = _SHELLHIDE(SHELL$)
  16.     '_ECHO SHELL$
  17.     IF a = 1 THEN
  18.         F = FREEFILE
  19.         OPEN "openfilename.txt" FOR BINARY AS #F
  20.         LINE INPUT #F, OFile$
  21.         CLOSE #F
  22.         OFile$ = RIGHT$(OFile$, LEN(OFile$) - 3)
  23.         GetOpenFileName64 = OFile$
  24.     ELSE
  25.         GetOpenFileName64 = ""
  26.         '    PRINT "Cancelled"
  27.     END IF
  28.  
  29.  FUNCTION ReplaceStringItem$ (text$, old$, new$)
  30.     DO
  31.         find = INSTR(start + 1, text$, old$) 'find location of a word in text
  32.         IF find THEN
  33.             first$ = LEFT$(text$, find - 1) 'text before word including spaces
  34.             last$ = RIGHT$(text$, LEN(text$) - (find + LEN(old$) - 1)) 'text after word
  35.             text$ = first$ + new$ + last$
  36.         END IF
  37.         start = find
  38.     LOOP WHILE find
  39.     ReplaceStringItem = text$

UPDATE!!!!! 2:50 PM: 8:20 AM 5/14/2020
Here is the code for making the GetSaveFileName function:
PowerShell:
Quote
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.SaveFileDialog -Property @{
}
$FileBrowser.Title = $args[0]
$initial = $args[1].ToString().Replace("/","\")
$FileBrowser.InitialDirectory = $initial
$chosenfilter = $args[2].ToString().Replace("^/^","|")
$FileBrowser.Filter = $chosenfilter

$null = $FileBrowser.ShowDialog()
$FileName = $FileBrowser.FileName
if ($FileName -ne ''){
$FileName > 'savefilename.txt'
exit 1
}
else{
exit 0
}
And QB64:
Code: QB64: [Select]
  1.    
  2. SFile$ = GetSaveFileName64("Save a file, jackass", "C:\Users\zacharys\[redacted]\Desktop\QB64 Files\qb32", "QB64 Files (*.BAS;*.BI;*.BM;*.FRM)|*.BAS;*.BI;*.BM;*.FRM|All Files (*.*)|*.*")
  3. FUNCTION GetSaveFileName64$ (Title$, InitialDir$, Filter$)
  4.     SHELL$ = "PowerShell -ExecutionPolicy Bypass " + CHR$(34) + "&'" + _STARTDIR$ + "\SaveFile.ps1'"
  5.     SHELL$ = SHELL$ + " " + "\" + CHR$(34) + Title$ + "\" + CHR$(34)
  6.     IF INSTR(InitialDir$, "\") THEN
  7.         InitialDir$ = ReplaceStringItem(InitialDir$, "\", "/")
  8.     END IF
  9.     SHELL$ = SHELL$ + " " + "\" + CHR$(34) + InitialDir$ + "\" + CHR$(34)
  10.     IF INSTR(Filter$, "|") THEN
  11.         Filter$ = ReplaceStringItem(Filter$, "|", "^/^")
  12.         'Filter$ = ReplaceStringItem(Filter$, "/", "|")
  13.     END IF
  14.     SHELL$ = SHELL$ + " " + "\" + CHR$(34) + Filter$ + "\" + CHR$(34)
  15.     SHELL$ = SHELL$ + ";exit $LASTEXITCODE" + CHR$(34)
  16.     a = _SHELLHIDE(SHELL$)
  17.     'a = SHELL(SHELL$)
  18.     '_ECHO SHELL$
  19.     IF a = 1 THEN
  20.         F = FREEFILE
  21.         OPEN "savefilename.txt" FOR BINARY AS #F
  22.         LINE INPUT #F, SFile$
  23.         CLOSE #F
  24.         SFile$ = RIGHT$(SFile$, LEN(SFile$) - 3)
  25.         GetSaveFileName64 = SFile$
  26.     ELSE
  27.         GetSaveFileName64 = ""
  28.         '    PRINT "Cancelled"
  29.     END IF
qb64 save file demo.png
« Last Edit: May 14, 2020, 08:20:16 am by SpriggsySpriggs »
Shuwatch!