PDA

View Full Version : using INPUTBOX$



sandyrepope
10-05-2007, 20:11
When using the INPUTBOX$ is there a way to make sure that when it comes up to get input from the user that it starts out on top of the other windows?

Thanks
Sandy

ErosOlmi
10-05-2007, 21:17
Sorry, no.

You have to create your own input box.
I will try to make some code when home this night.

Ciao
Eros

Petr Schreiber
10-05-2007, 21:22
Could this work for you ?
It is just modified sampleScript :)

It adjusts dialog size with respect to number of $CRLF in question.



uses "UI"

dim ResultOfWeirdQuestion as string
ResultOfWeirdQuestion = myInputBox( "Please enter following letter"+$CRLF+"A - I like thinBASIC"+$CRLF+"B - I like thinBASIC a lot :D", "Question", "B")

msgbox 0, iif$( len(ResultOfWeirdQuestion), ResultOfWeirdQuestion, "<Nothing>")


FUNCTION myInputBox( sPrompt as string, sTitle as string, sDefault as string) AS string

%LBL_01 = 2000
%TXT_01 = 2001

local NumPromptLines as long = parsecount(sPrompt, $CRLF)
if NumPromptLines = 0 then NumPromptLines = 1

LOCAL hDlg AS long

local Msg AS LONG
local wParam AS LONG
local lParam AS LONG

local ReturnString as string

' -- Create new dialog - our pseudo INPUTBOX$
DIALOG NEW win_getForeground, sTitle, -1, -1, 150, 45+NumPromptLines*15, _
%WS_DLGFRAME OR %DS_CENTER OR %WS_CAPTION , _
0 TO hDlg

' -- Display the dialog
DIALOG SHOW modeless hDlg


WHILE IsWindow(hDlg)

' -- Get the message and fill wParam and lParam
Msg = GetMessage(hDlg, wParam, lParam)

' -- Now test the message
SELECT CASE Msg


case %WM_INITDIALOG '---Message fired at the very beginning when dialog is initialized

'---Add relevant controls
CONTROL ADD label , hDlg, %LBL_01, sPrompt, 5, 5, 140, NumPromptLines*15, 0
CONTROL ADD textbox , hDlg, %TXT_01, sDefault, 5, 5+NumPromptLines*15, 140, 12, 0
CONTROL ADD BUTTON , hDlg, %IDOK, "Submit", 5, 25+NumPromptLines*15, 60, 14, %BS_DEFAULT
CONTROL ADD BUTTON , hDlg, %IDCANCEL, "Cancel", 85, 25+NumPromptLines*15, 60, 14, 0
Win_SetForeground(hDlg)


case %WM_Command

select case wParam
case %IDCANCEL
exit while

case %IDOK
CONTROL GET TEXT hDlg, %TXT_01 TO ReturnString
function = ReturnString
exit while

end select

CASE %WM_SYSCOMMAND

SELECT CASE wParam
CASE %SC_CLOSE
EXIT WHILE
END SELECT

end select

wend

DIALOG END hDlg

END FUNCTION


Bye,
Petr

ErosOlmi
11-05-2007, 12:57
Nice example Petr. You was faster than me!

Here another example.
Use

MyInputBox(0, "Prompt", "Title", "Default text")
for not modal Inputbox.

Use

MyInputBox(ParentWindow, "Prompt", "Title", "Default text")
where ParentWindow is the window handle of the calling window to use it as modal.




uses "UI"

FUNCTION MyInputBox(hParent as long, Prompt as string, Title as string, DefText as string) AS STRING
dim hWnd as long
DIM Msg AS LONG
DIM wParam AS LONG
DIM lParam AS LONG

dim UserCancel as long
dim tmpString as string

dim x, y, BOXH, BOXW as long
dim LABH, LABW, TEXTY as long
dim BUTNX as long

dim idOK as long = 1
dim idCancel as long = 2
dim idPrompt as long = 100
dim idText as long = 103

IF RTRIM$(Prompt) = "" THEN
EXIT FUNCTION
END IF

BOXH = PARSECOUNT(Prompt, $CRLF) + 3
FOR X = 1 TO BOXH
Y = LEN(PARSE$(Prompt, $CRLF, X))
IF Y > BOXW THEN BOXW = Y
NEXT

Y = LEN(Title)
IF Y > BOXW THEN BOXW = Y
Y = LEN(DefText)
IF Y > BOXW THEN BOXW = Y

BOXH = BOXH * 12
IF BOXH < 52 THEN BOXH = 52

BOXW = BOXW * 4 + 100
LABH = BOXH - 12
LABW = BOXW - 40
TEXTY = BOXH - 12: BUTNX = LABW + 2

DIALOG NEW 0, Title, -1, -1, BOXW, BOXH, 0, 0 TO hWnd
CONTROL ADD LABEL , hWnd, idPrompt , Prompt , 0, 0, LABW, LABH
CONTROL ADD BUTTON , hWnd, idOK , "OK" , BUTNX, 2, 36, 12
CONTROL ADD BUTTON , hWnd, idCancel , "Cancel" , BUTNX, 16, 36, 12
CONTROL ADD TEXTBOX , hWnd, idText , DefText , 0, TEXTY, BOXW, 12
CONTROL SET FOCUS hWnd, 103

DIALOG SHOW modeless hWnd

WHILE UserCancel = %FALSE

'---Get the message and fill wParam and lParam
Msg = GetMessage(hWnd, wParam, lParam)

'---Now test the message
SELECT CASE Msg

CASE %WM_COMMAND
SELECT CASE wParam
CASE idCancel
UserCancel = %TRUE
function = ""
CASE idOK
UserCancel = %TRUE
CONTROL GET TEXT hWnd, idText TO tmpString
function = tmpString

END SELECT
CASE %WM_SYSCOMMAND
SELECT CASE wParam
CASE %SC_CLOSE
EXIT WHILE
END SELECT

CASE ELSE

END SELECT

WEND

DIALOG END hWnd

END FUNCTION

dim MyRetString as string
MyRetString = MyInputBox(0, "Prompt", "Title", "Default text")
msgbox 0, "Returned string:" & $crlf & MyRetString