Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is there any way to position the inputbox$ window?
#1
It would be helpful if it didn't have to always start at 0, 0 of the program window.
Reply
#2
Code: (Select All)
Locate 12, 40: Input "What"; w$

Oh InputBox$ Sorry:
Code: (Select All)
' for saving and restoring screen settins
Sub ScnState (restoreTF As Long) 'Thanks Steve McNeill
    Static defaultColor~&, backGroundColor~&
    Static font&, dest&, source&, row&, col&, autodisplay&, mb&
    If restoreTF Then
        _Font font&
        Color defaultColor~&, backGroundColor~&
        _Dest dest&
        _Source source&
        Locate row&, col&
        If autodisplay& Then _AutoDisplay Else _Display
        _KeyClear
        While _MouseInput: Wend 'clear mouse clicks
        mb& = _MouseButton(1)
        If mb& Then
            Do
                While _MouseInput: Wend
                mb& = _MouseButton(1)
                _Limit 100
            Loop Until mb& = 0
        End If
    Else
        font& = _Font: defaultColor~& = _DefaultColor: backGroundColor~& = _BackgroundColor
        dest& = _Dest: source& = _Source
        row& = CsrLin: col& = Pos(0): autodisplay& = _AutoDisplay
        _KeyClear
    End If
End Sub


' You can grab this box by title and drag it around screen for full viewing while answering prompt.
' Only one line allowed for prompt$
' boxWidth is 4 more than the allowed length of input, it needs to be longer than title$ and prompt$ also
' Utilities > Input Box > Input Box 1 tester v 2019-07-31

Function inputBox$ (title$, prompt$, boxWidth As _Byte)
    Dim ForeColor As _Unsigned Long, BackColor As _Unsigned Long
    Dim sw As Long, sh As Long, curScrn As Long, backScrn As Long, ibx As Long 'some handles

    'colors
    ForeColor = &HFF000055 '<  change as desired  prompt text color, back color or type in area
    BackColor = &HFF6080CC '<  change as desired  used fore color in type in area

    'items to restore at exit
    ScnState 0

    'screen snapshot
    sw = _Width: sh = _Height: curScrn = _Dest
    backScrn = _NewImage(sw, sh, 32)
    _PutImage , curScrn, backScrn

    'moving box around on screen
    Dim bxW As Long, bxH As Long
    Dim mb As Long, mx As Long, my As Long, mi As Long, grabx As Long, graby As Long
    Dim tlx As Long, tly As Long 'top left corner of message box
    Dim lastx As Long, lasty As Long
    Dim inp$, kh&

    'draw message box
    bxW = boxWidth * 8: bxH = 7 * 16
    ibx = _NewImage(bxW, bxH, 32)
    _Dest ibx
    Color &HFF880000, &HFFFFFFFF
    Locate 1, 1: Print Left$(Space$(Int((boxWidth - Len(title$) - 3)) / 2) + title$ + Space$(boxWidth), boxWidth)
    Color &HFFFFFFFF, &HFFBB0000
    Locate 1, boxWidth - 2: Print " X "
    Color ForeColor, BackColor
    Locate 2, 1: Print Space$(boxWidth);
    Locate 3, 1: Print Left$(Space$((boxWidth - Len(prompt$)) / 2) + prompt$ + Space$(boxWidth), boxWidth);
    Locate 4, 1: Print Space$(boxWidth);
    Locate 5, 1: Print Space$(boxWidth);
    Locate 6, 1: Print Space$(boxWidth);
    inp$ = ""
    GoSub finishBox

    'convert to pixels the top left corner of box at moment
    bxW = boxWidth * 8: bxH = 5 * 16
    tlx = (sw - bxW) / 2: tly = (sh - bxH) / 2
    lastx = tlx: lasty = tly
    _KeyClear
    'now allow user to move it around or just read it
    While 1
        Cls
        _PutImage , backScrn
        _PutImage (tlx, tly), ibx, curScrn
        _Display
        While _MouseInput: Wend
        mx = _MouseX: my = _MouseY: mb = _MouseButton(1)
        If mb Then
            If mx >= tlx And mx <= tlx + bxW And my >= tly And my <= tly + 16 Then 'mouse down on title bar
                If mx >= tlx + bxW - 24 Then Exit While
                grabx = mx - tlx: graby = my - tly
                Do While mb 'wait for release
                    mi = _MouseInput: mb = _MouseButton(1)
                    mx = _MouseX: my = _MouseY
                    If mx - grabx >= 0 And mx - grabx <= sw - bxW And my - graby >= 0 And my - graby <= sh - bxH Then
                        'attempt to speed up with less updates
                        If ((lastx - (mx - grabx)) ^ 2 + (lasty - (my - graby)) ^ 2) ^ .5 > 10 Then
                            tlx = mx - grabx: tly = my - graby
                            Cls
                            _PutImage , backScrn
                            _PutImage (tlx, tly), ibx, curScrn
                            lastx = tlx: lasty = tly
                            _Display
                        End If
                    End If
                    _Limit 400
                Loop
            End If
        End If
        kh& = _KeyHit
        Select Case kh& 'whew not much for the main event!
            Case 13: Exit While
            Case 27: inp$ = "": Exit While
            Case 32 To 128: If Len(inp$) < boxWidth - 4 Then inp$ = inp$ + Chr$(kh&): GoSub finishBox Else Beep
            Case 8: If Len(inp$) Then inp$ = Left$(inp$, Len(inp$) - 1): GoSub finishBox Else Beep
        End Select

        _Limit 60
    Wend

    'put things back
    ScnState 1 'need fg and bg colors set to cls
    Cls '? is this needed YES!!
    _PutImage , backScrn
    _Display
    _FreeImage backScrn
    _FreeImage ibx
    ScnState 1 'because we have to call _display, we have to call this again
    inputBox$ = inp$
    Exit Function

    finishBox:
    _Dest ibx
    Color BackColor, ForeColor
    Locate 5, 2: Print Left$(" " + inp$ + Space$(boxWidth - 2), boxWidth - 2)
    _Dest curScrn
    Return
End Function

If still not good enough, this code you can MOD.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#3
Thanks @BPlus, that's an interesting little program!
But no, I meant a popup specifically outside the program window, not one that is sitting over any part of the program window. Like the Inputbox$ control, with the default value selected so you can copy it to the clipboard.

The QB64PE one looks identical to the one in vbscript / VBA / VB6 (which can be moved, run the below vbscript) 
so it must be system-level, so it's probably possible to edit the QB64PE IDE to add those parameters, but that would be a lot of work. 
Another option would be to generate a vbscript on the fly and shell out to it, or have it accept command line args. 

A simpler solution for my purpose is display a prompt in _TITLE, collect input with _KeyDown, update clipboard with _Clipboard$. 

Thanks again! That code might come in handy for some other projects! 
Do you have a version that can display & detect clicks on OK / Cancel / Yes / No buttons??  Smile

Code: (Select All)
' "PositionInputbox.vbs" = A vbscript that demostrates how to position inputbox
Dim m_ProgramPath: m_ProgramPath = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\")) ' executable path
Dim m_ProgramName: m_ProgramName = Mid(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\") + 1) ' executable filename
dim strComputer : dim objWMIService : dim colItems : dim objItem
Dim ScreenWidth: Dim ScreenHeight : dim xMax : dim yMax : dim xMin : dim yMin
Dim xPos : Dim yPos : Dim dx : Dim dy
dim sValue : dim sPrompt : dim sTitle : dim sDefault : Dim xTwips : Dim yTwips
dim sError : sError = ""
if len(sError)=0 then
    ' Get screen size
    ' Author: Demon
    ' Website: http://demon.tw
    ' Date: 2012/5/7
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_DesktopMonitor",,48)
    For Each objItem in colItems
        ScreenWidth = objItem.ScreenWidth
        ScreenHeight = objItem.ScreenHeight
        if len(ScreenWidth) > 0 and len(ScreenHeight) > 0 then exit for
    Next
    if len(ScreenWidth) = 0 or len(ScreenHeight) = 0 then sError = "Error: can't determine screen resolution. Exiting."
end if
if len(sError)=0 then
    ' Move inputbox around
    ' https://www.devguru.com/content/technologies/vbscript/functions-inputbox.html
    ' https://www.vbforums.com/showthread.php?419303-Screen-Position-of-the-InputBox
    xMin = 0 : yMin = 0 : xMax = ScreenWidth - 375 : yMax = ScreenHeight - 240
    xPos = xMin : yPos = yMin : dx = 100 : dy = 200
    Do
        sPrompt = "Press Enter or cick OK to see InputBox move."  & vbcrlf & _
            "Clear the text and click OK to quit." & vbcrlf & _
            "Screen resolution = " & xMax & "x" & yMax
        sTitle = m_ProgramName
        sDefault = xPos & "," & yPos
        xTwips = 15 * xPos : yTwips = 15 * yPos
        sValue = InputBox(sPrompt, sTitle, sDefault, xTwips, yTwips)
        if len(sValue) = 0 then exit do
        xPos = xPos + dx
        if xPos < xMin then dx = 0 - dx : xPos = xMin : dx = 0 : if dy = 0 then dy = 100
        if yPos < yMin then dy = 0 - dy : yPos = yMin : dy = 0 : if dx = 0 then dx = -200
        yPos = yPos + dy
        if xPos > xMax then dx = 0 - dx : xPos = xMax : dx = 0 : if dy = 0 then dy = -100
        if yPos > yMax then dy = 0 - dy : yPos = yMax : dy = 0 : if dx = 0 then dx = 200
    Loop
end if
if len(sError) > 0 then msgbox sError
if IsObject(objItem) then set objItem = nothing
if IsObject(colItems) then set colItems = nothing
if IsObject(objWMIService) then set objWMIService = nothing
WScript.Quit()
Reply
#4
"Do you have a version that can display & detect clicks on OK / Cancel / Yes / No buttons??"

Boo hoo!
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#5
I'll take that as a No, but that was just me being lazy - you already did all the hard work making a dragable popup window, we can probably modify your routine to support buttons, etc. I can't look at it right now, but maybe later!  Wink
Reply
#6
A "no" for Halloween

I created InputBox and MessageBox before QB64pe added them built-in. If I want buttons I'd use that and I think they might be draggable too.

Great ways to communicate with user at Runtime without messing up the screen!

Another idea is to run a separate program that writes a reply into a file or clipboard readable by the program that wants the info. How desparate are you?

Actually the clipboard idea is pretty good and could be used for other programs needing info from user. The caller clears clipboard and waits for contents to be read, come to think you might not even need a separate program!!!
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#7
All good ideas. Not desperate - there will be time to explore these on a less busy day. Happy Halloween!
Reply
#8
@madscijr 

We also discussed something along those here: https://qb64phoenix.com/forum/showthread.php?tid=3018


Reply
#9
You would most likely need to just figure out how to make your own input box using the Win32 API and give the coordinates for it in the creation. But, considering it takes input, you would need callback functions and a lot of code. You can also use PowerShell to make a GUI input box, and it might allow you to choose where it starts. I can't remember if it does.
The noticing will continue
Reply
#10
(10-31-2025, 06:10 PM)Petr Wrote: We also discussed something along those here: https://qb64phoenix.com/forum/showthread.php?tid=3018

Thanks, I will check that out!


(11-05-2025, 02:40 PM)SpriggsySpriggs Wrote: You would most likely need to just figure out how to make your own input box using the Win32 API and give the coordinates for it in the creation. But, considering it takes input, you would need callback functions and a lot of code. You can also use PowerShell to make a GUI input box, and it might allow you to choose where it starts. I can't remember if it does.

Interesting... I had read PowerHell can do GUIs, and you have a lot more control than with traditional vbscript. I wonder what the Linux / Mac equivalent (if one exists) would be?

For now, I just set the _TITLE to display debug values and did a _KEYDOWN for input, which did the job for debugging.

But I will check out the link Petr mentioned and look into doing GUIs with PowerShell. Always good to have more tricks up one's sleeve!

Thanks again, guys!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Enlarging window for older BAS programs (ie. Screen 7 mode) paulel 5 387 12-24-2025, 09:36 PM
Last Post: paulel
  auto-detecting screen resolution for optimal window size on non-Windows systems madscijr 11 1,040 11-10-2025, 07:23 PM
Last Post: madscijr
  auto-detecting screen resolution for optimal window size on non-Windows systems madscijr 0 214 10-26-2025, 06:58 PM
Last Post: madscijr
  Play wav file in the background without a window on the forground Rudy M 12 1,125 09-18-2025, 07:08 PM
Last Post: Pete
  file.. open dialog window pmackay 2 397 08-31-2025, 11:27 PM
Last Post: pmackay

Forum Jump:


Users browsing this thread: