Code: Select all
InputRequester("test","THIS IS A LONG TEXT."+Chr(10)+"IS THERE ANY WAY YOU CAN SEE IT IN FULL ???","")
Code: Select all
InputRequester("test","THIS IS A LONG TEXT."+Chr(10)+"IS THERE ANY WAY YOU CAN SEE IT IN FULL ???","")
Code: Select all
; http://www.purearea.net/pb/CodeArchiv/CodeArchiv.html
; English forum:
; Author: Unknown (updated for PB4.00 by blbltheworm)
; Date: 19. January 2003
; OS: Windows
; Demo: No
;Here's my own version of an input requester, which is superior to the
;built-in InputRequester() command in these ways:
;
;(1) It's "modal" (it locks the calling window until done).
;(2) The prompt area is bigger And can have multi-line text.
;(3) You can hit Esc/Enter To abort/accept the requester.
;(4) It has a Cancel button in addition To an OK button.
;(5) It has a standard Windows look-and-feel about it.
;(6) It plays the "question" audio prompt sound.
;
;It works with Or without a calling window, And here's how you call it:
Procedure.s InputBox(CallerID.l,title$,prompt$,def$)
;
; Remember which window (if any) called this InputBox.
;
If CallerID<>0 : CallerNum=EventWindow() : EndIf
;
box=OpenWindow(999,0,0,357,120,title$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
;
TextGadget(996,10,8,265,73,prompt$)
ButtonGadget(997,288,8,60,23,"OK",#PB_Button_Default)
ButtonGadget(998,288,36,60,23,"Cancel")
StringGadget(999,9,92,339,20,def$,#ES_MULTILINE|#ES_AUTOVSCROLL) ; Flags stop "ding" sounds.
SendMessage_(GadgetID(999),#EM_SETSEL,0,Len(def$)) ; Select all of def$ (if declared).
;
If CallerID<>0
EnableWindow_(CallerID,#False) ; Disable caller until our InputBox closes ("modal" effect).
EndIf
SetWindowPos_(WindowID(999),#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE) ; InputBox always on top.
;
GetAsyncKeyState_(#VK_RETURN) : GetAsyncKeyState_(#VK_ESCAPE) ; Clear key buffers before loop.
SetForegroundWindow_(WindowID(999)) : SetActiveGadget(999) ; Activate InputBox and its StringGadget.
MessageBeep_(#MB_ICONQUESTION) ; Play a sound prompt for the user (not supported on Win XP!).
;
Repeat
Sleep_(1) : ev=WindowEvent() : id=EventGadget() : where=GetForegroundWindow_()
ret=GetAsyncKeyState_(#VK_RETURN) : esc=GetAsyncKeyState_(#VK_ESCAPE)
Until where=box And ((ev=#PB_Event_Gadget And (id=997 Or id=998)) Or ret=-32767 Or esc=-32767 Or ev=#PB_Event_CloseWindow)
;
If id=997 Or ret=-32767 : text$=GetGadgetText(999) : EndIf ; OK clicked or Return key pressed.
;
CloseWindow(999) ; Close InputBox.
;
If CallerID<>0
EnableWindow_(CallerID,#True) ; Re-enable caller again.
SetForegroundWindow_(CallerID); Give focus back to caller.
; And give event control back to caller.
While WindowEvent() : Wend ; Clear events from caller (necessary!).
EndIf
;
ProcedureReturn text$
;
EndProcedure
;(Updated To fix a gadget number-clash problem, And To Select all of
;the Default text [def$] when the prompt opens, rather than just put
;the cursor at the End of it. Now you can just accept def$ by hitting
;Enter when the prompt opens, Or just start typing a new value without
;having To delete all the text first).
;
;--------------------------------------------------------------------------------
;Edited by - PB on 19 Jan 2003 00:44:03
;Usage:
;a$=InputBox(title$,prompt$,Default$)
;Example:
a$=InputBox(0,"InputBox","Please" + Chr(10) + " input " + Chr(10) + " a string:","This text is already there.... ;)")
Debug a$
;Naturally prompt$ can include Chr(13) For multi-line text, And Default$
;can be empty (null) If you don't want a default entry placed in it.
;I called it InputBox() so as not To clash with InputRequester(), And
;because it emulates the Visual Basic InputBox() command.
; IDE Options = PureBasic v4.00 (Windows - x86)
; Folding = -
Code: Select all
Procedure myINPUT(Title$,Def$)
If IsGadget(10)
FreeGadget(10)
EndIf
ContainerGadget(10,WindowWidth(0)>>1-150,WindowHeight(0)>>1-100,300,200,#WS_CLIPSIBLINGS)
SetGadgetColor(10,#PB_Gadget_BackColor,0)
TextGadget(11,10,10,200,25,Title$)
SetGadgetColor(11,#PB_Gadget_BackColor,0)
SetGadgetColor(11,#PB_Gadget_FrontColor,$FFFFFF)
StringGadget(12,10,45,280,100,Def$,#ES_MULTILINE|#ESB_DISABLE_BOTH)
ButtonGadget(13,90,155,60,30,"OK")
ButtonGadget(14,170,155,60,30,"Cancel")
CloseGadgetList()
EndProcedure
flags = #PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0,0,0,800,600,"Test",Flags)
myINPUT("test","THIS IS A LONG TEXT."+Chr(10)+"IS THERE ANY WAY YOU CAN SEE IT IN FULL ???")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Menu
Select EventMenu()
Case 1
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 13
text$ = GetGadgetText(12)
Debug text$
FreeGadget(10)
Case 14
title$ = ""
def$ = ""
FreeGadget(10)
EndSelect
EndSelect
Until Quit = 1
End
Code: Select all
Enumeration
#Requester_Window ; 0
#Requester_container ;10
#Requester_txt_title ;11
#Requester_txt_question ;12
#Requester_str_def ;13
#Requester_btn_ok ;14
#Requester_btn_cancel ;15
#Requester_container2 ;16
EndEnumeration
Procedure myINPUT(Title$, Question$, Def$)
If IsGadget(#Requester_container)
FreeGadget(#Requester_container)
EndIf
ContainerGadget(#Requester_container ,WindowWidth(0)>>1-150,WindowHeight(0)>>1-100,300,235,#WS_CLIPSIBLINGS | #PB_Container_Raised)
SetGadgetColor(#Requester_container ,#PB_Gadget_BackColor,RGB(220,220,220))
TextGadget(#Requester_txt_question,5,27,284,70, Question$)
SetGadgetColor(#Requester_txt_question,#PB_Gadget_BackColor,0)
SetGadgetColor(#Requester_txt_question,#PB_Gadget_FrontColor,#Green)
StringGadget(#Requester_str_def ,5,105,284,72,Def$,#ES_MULTILINE|#ESB_DISABLE_BOTH)
ButtonGadget(#Requester_btn_ok,60,190,60,30,"OK")
ButtonGadget(#Requester_btn_cancel,175,190,60,30,"Cancel")
If IsGadget(#Requester_container2)
FreeGadget(#Requester_container2)
EndIf
ContainerGadget(#Requester_container2,0,0,300,20,#WS_CLIPSIBLINGS | #PB_Container_Single)
SetGadgetColor(#Requester_container2,#PB_Gadget_BackColor,RGB(220,220,220))
TextGadget(#Requester_txt_title,3,0,288,20,Title$)
SetGadgetColor(#Requester_txt_title,#PB_Gadget_BackColor,RGB(200,200,200))
SetGadgetColor(#Requester_txt_title,#PB_Gadget_FrontColor,0)
CloseGadgetList()
SetActiveGadget(#Requester_str_def)
SendMessage_(GadgetID(#Requester_str_def),#EM_SETSEL,0,Len(def$)) ; Select all of def$ (if declared).
EndProcedure
flags = #PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(#Requester_Window,0,0,800,600,"Test",Flags)
SetWindowColor(#Requester_Window, RGB(210,210,120))
Title$ = " I HAVE A QUESTION ?"
Question$ = " WITH A LONG TEXT." + Chr(10) + " IS THERE ANY WAY YOU CAN SEE IT IN FULL ???"
myINPUT(Title$ , Question$,"Certainly !!" + Chr(13) + Chr(10) + "You will need To use the code from RASHAD")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Menu
Select EventMenu()
Case 1
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #Requester_btn_ok
text$ = GetGadgetText(#Requester_str_def )
Debug text$
FreeGadget(#Requester_container2)
FreeGadget(#Requester_container)
Case #Requester_btn_cancel
title$ = ""
def$ = ""
FreeGadget(#Requester_container2)
FreeGadget(#Requester_container)
EndSelect
EndSelect
Until Quit = 1
End
Code: Select all
Enumeration
#main_window;0
#container ;10
#txt_title ;11
#txt_question;12
#str_def ;13
#btn_ok ;14
#btn_cancel ;15
EndEnumeration
Procedure myINPUT(Title$, Question$, Def$)
If IsGadget(#container)
FreeGadget(#container)
EndIf
ContainerGadget(#container,WindowWidth(#main_window)>>1-150,WindowHeight(#main_window)>>1-100,300,220,#WS_CLIPSIBLINGS | #PB_Container_Raised)
SetGadgetColor(#container,#PB_Gadget_BackColor,#main_window)
TextGadget(#txt_title,10,10,260,50,Title$)
SetGadgetColor(#txt_title,#PB_Gadget_BackColor,#main_window)
SetGadgetColor(#txt_title,#PB_Gadget_FrontColor,#Red)
TextGadget(#txt_question,10,30,260,50, Question$)
SetGadgetColor(#txt_question,#PB_Gadget_BackColor,#main_window)
SetGadgetColor(#txt_question,#PB_Gadget_FrontColor,#Green)
StringGadget( #str_def,10,60,280,100,Def$,#ES_MULTILINE|#ESB_DISABLE_BOTH)
ButtonGadget( #str_def,90,175,60,30,"OK")
ButtonGadget(#btn_cancel,170,175,60,30,"Cancel")
CloseGadgetList()
EndProcedure
flags = #PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(#main_window,0,0,800,600,"Test",Flags)
SetWindowColor(#main_window, RGB(210,210,120))
Title$ = "I HAVE A QUESTION ?"
Question$ = " WITH A LONG TEXT." + Chr(10) + "IS THERE ANY WAY YOU CAN SEE IT IN FULL ???"
myINPUT(Title$ , Question$,"Certainly !! "+Chr(10)+"you will need to use the code from RASHAD")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Menu
Select EventMenu()
Case 1 ;what does case 1 ??
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #str_def
text$ = GetGadgetText( #txt_question)
Debug text$
FreeGadget(#container)
Case #btn_cancel
title$ = ""
def$ = ""
FreeGadget(#container)
EndSelect
EndSelect
Until Quit = 1
End
PureBasic's built-in InputRequester() function does not seem to support this. However, here's a proof-of-concept to a custom input requester, with some extended functions which can be easily modified as required. It includes the following features:Fig wrote:...make InputRequester() display 2 lines of text ?
Code: Select all
Global irWin, irInput, irButton1, irButton2
Procedure InputRequester_X(title.s = "Custom Input Requester",
message.s = "Please input the required value:",
defaultValue.s = "", buttons.s = "OK")
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Tool
irWin = OpenWindow(#PB_Any, 0, 0, 300, 170, title, wFlags)
irMsg = TextGadget(#PB_Any, 30, 20, 240, 50, "")
irInput = StringGadget(#PB_Any, 20, 70, 260, 30, defaultValue)
If CountString(message, "|")
messages1$ = Trim(StringField(message, 1, "|"))
messages2$ = Trim(StringField(message, 2, "|"))
message = messages1$ + #CRLF$ + messages2$
EndIf
SetGadgetText(irMsg, message)
If CountString(buttons, "|")
buttonText1$ = Trim(StringField(buttons, 1, "|"))
buttonText2$ = Trim(StringField(buttons, 2, "|"))
irButton1 = ButtonGadget(#PB_Any, 20, 120, 120, 30, buttonText1$)
irButton2 = ButtonGadget(#PB_Any, 160, 120, 120, 30, buttonText2$)
Else
irButton1 = ButtonGadget(#PB_Any, 40, 120, 220, 30, buttons)
EndIf
EndProcedure
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
mainWin = OpenWindow(#PB_Any, 20, 20, 400, 300, "Custom Input Requester", wFlags)
mainInput = TextGadget(#PB_Any, 20, 70, 360, 30, "Input value: ")
inputButton1 = ButtonGadget(#PB_Any, 20, 140, 360, 40, "Input Requester With Default Values")
inputButton2 = ButtonGadget(#PB_Any, 20, 190, 360, 40, "1 Button / 1 Line Message / Close Timer")
inputButton3 = ButtonGadget(#PB_Any, 20, 240, 360, 40, "2 Buttons / 2 Line Message / No Close Timer")
clock = TextGadget(#PB_Any, 20, 20, 360, 40, "Time: 00:00:00", #PB_Text_Right)
SetGadgetColor(mainInput, #PB_Gadget_BackColor, #White)
AddWindowTimer(mainWin, 0, 1000)
Repeat
windowEvent = WaitWindowEvent()
Select EventWindow()
Case mainWin
Select windowEvent
Case #PB_Event_CloseWindow
appQuit = #True
Case #PB_Event_Timer
currentTime$ = FormatDate("%hh:%ii:%ss", Date())
SetGadgetText(clock, "Time: " + currentTime$)
If IsWindow(irWin)
If countDown > 1
countDown - 1
buttonText$ = Trim(StringField(buttonText$, 1, "|"))
countDown$ = " (" + Str(countdown) + ")"
SetGadgetText(irButton1, buttonText$ + countDown$)
ElseIf countDown <> -1
CloseWindow(irWin)
DisableWindow(mainWin, #False)
SetActiveWindow(mainWin)
EndIf
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case inputButton1, inputButton2, inputButton3
DisableWindow(mainWin, #True)
If EventGadget() = inputButton1
countDown = -1
InputRequester_X()
Else
If EventGadget() = inputButton2
countDown = 10 ;10-second close timer
title$ = "Input Requester 1"
message$ = "(wrapped lines) This requester will " +
"automatically close after 10 seconds..."
defaultText$ = "default text of 1-button requester"
buttonText$ = "OK"
Else
countDown = -1 ;no close timer
title$ = "Input Requester 2"
message$ = "Input message line 1... | Input message line 2..."
defaultText$ = "default text of 2-button requester"
buttonText$ = "OK | CANCEL"
EndIf
InputRequester_X(title$, message$, defaultText$, buttonText$)
EndIf
EndSelect
EndSelect
Case irWin ;inputRequester handler
Select windowEvent
Case #PB_Event_CloseWindow
countDown = 0
CloseWindow(irWin)
DisableWindow(mainWin, #False)
SetActiveWindow(mainWin)
Case #PB_Event_Gadget
Select EventGadget()
Case irButton1, irButton2
If EventGadget() = irButton1
SetGadgetText(mainInput, "Input value: " + GetGadgetText(irInput))
EndIf
countDown = 0
CloseWindow(irWin)
DisableWindow(mainWin, #False)
SetActiveWindow(mainWin)
EndSelect
EndSelect
EndSelect
Until appQuit
Code: Select all
Procedure myINPUT(Title$,Def$)
If IsGadget(10)
FreeGadget(10)
EndIf
ContainerGadget(10,WindowWidth(0)>>1-150,WindowHeight(0)>>1-100,300,200,#WS_CLIPSIBLINGS)
SetGadgetColor(10,#PB_Gadget_BackColor,$CD9F00)
TextGadget(11,10,10,200,25,Title$)
SetGadgetColor(11,#PB_Gadget_BackColor,$CD9F00)
SetGadgetColor(11,#PB_Gadget_FrontColor,$FFFFFF)
StringGadget(12,10,45,280,100,Def$,#ES_MULTILINE|#ESB_DISABLE_BOTH)
ButtonGadget(13,90,155,60,30,"OK")
ButtonGadget(14,170,155,60,30,"Cancel")
CloseGadgetList()
hrgn = CreateRoundRectRgn_(0,0,300,200,35,35)
SetWindowRgn_(GadgetID(10),hrgn,1)
EndProcedure
flags = #PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0,0,0,800,600,"Test",Flags)
myINPUT("test","THIS IS A LONG TEXT."+Chr(10)+"IS THERE ANY WAY YOU CAN SEE IT IN FULL ???")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Menu
Select EventMenu()
Case 1
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 13
text$ = GetGadgetText(12)
Debug text$
FreeGadget(10)
Case 14
title$ = ""
def$ = ""
FreeGadget(10)
EndSelect
EndSelect
Until Quit = 1
End
Code: Select all
Global icoH
Procedure _InputRequester(Title$,in$)
OpenWindow(1, 0, 0, 320, 200, "Input Requester", #PB_Window_SystemMenu|#PB_Window_WindowCentered, WindowID(0))
DisableWindow(0, 1)
ImageGadget(10,10,10,32,32,icoH)
TextGadget(11,50,10,200,25,Title$,#SS_CENTERIMAGE)
StringGadget(12,10,50,300,100,in$,#ES_MULTILINE|#ESB_DISABLE_BOTH)
ButtonGadget(13, 140, 160, 40, 30, "OK")
EndProcedure
icoH = LoadIcon_(0,#IDI_WINLOGO)
OpenWindow(0, #PB_Ignore, #PB_Ignore, 400, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 170, 260, 60, 30, "Input")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case 0
Break
Default
DisableWindow(0, #False)
CloseWindow(EventWindow())
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 0
_InputRequester("Test","THIS IS A LONG TEXT."+#CRLF$+"IS THERE ANY WAY YOU CAN SEE IT IN FULL ???")
Case 13
DisableWindow(0, #False)
CloseWindow(1)
EndSelect
EndSelect
ForEver