Page 1 of 2

Input Requester Centered Char

Posted: Wed Jul 15, 2009 3:55 pm
by RASHAD

Code: Select all

Global InputString$

#InputString_Length = 20

Procedure NewChar(char) 
  If char > 31 And char < 128
      InputString$ + Chr(char)
  ElseIf char = 8
      InputString$ = Left(InputString$,Len(InputString$)-1)
  EndIf
   InputString$ = Left(InputString$,#InputString_Length)
  StartDrawing( ImageOutput(1) ) 
    Box(15,15,170,20,GetSysColor_(#COLOR_BTNFACE))
    FrontColor(RGB(Red(255),Green(0),Blue(0))) 
    DrawingMode(1) 
    SetCaretPos_((200-TextWidth(InputString$))/2+TextWidth(InputString$),17) 
    DrawText((200-TextWidth(InputString$))/2,17,InputString$) 
  StopDrawing() 
  SetGadgetState(0,ImageID(1)) 
EndProcedure 

Procedure WinProc(hWnd,Msg,wParam,lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select Msg 
    Case #WM_CHAR 
      NewChar(wParam) 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

CreateImage(1,200,50) 

OpenWindow(0,0,0,200,50,"Please Input Password",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ImageGadget(0,0,0,200,50,ImageID(1)) 
  SetWindowCallback(@WinProc())
  CreateCaret_(WindowID(0),0,2,16):ShowCaret_(WindowID(0))
 
  NewChar(0) 

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
End
RASHAD

Posted: Wed Jul 15, 2009 4:24 pm
by Rook Zimbabwe
I just tossed this off at work...

You didn't comment your code at all so I had to figure out what you think you are trying to do... not a good start there!

It seemed to me that you were trying to set the text on a button... I hashed a simple program that would do that without all those extended system calls...

Code: Select all

; PureBasic Visual Designer v3.95 build 1485 (PB4Code)


;- Window Constants
;
Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Button_0
  #String_0
EndEnumeration

Global chr$

Procedure CheckChar(chr$)
old$ = chr$
chr= Asc(chr$)
If chr > 31 And char < 128 
  new$ = old$ + chr$
EndIf
SetGadgetText(#Button_0, new$)
  
EndProcedure

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 216, 0, 408, 163, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      ButtonGadget(#Button_0, 20, 80, 350, 50, "")
      StringGadget(#String_0, 20, 20, 370, 40, "")
      
    EndIf
  EndIf
EndProcedure

; PureBasic Visual Designer v3.95 build 1485 (PB4Code)


Open_Window_0()

Repeat ; Start of the event loop
  
  Event = WaitWindowEvent() ; This line waits until an event is received from Windows
  
  WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
  
  GadgetID = EventGadget() ; Is it a gadget event?
  
  EventType = EventType() ; The event type
  
  ;You can place code here, and use the result as parameters for the procedures
  
  If Event = #PB_Event_Gadget
    
    If GadgetID = #Button_0
      
    ElseIf GadgetID = #String_0
      chr$ = GetGadgetText(#String_0)
      CheckChar(chr$)
    EndIf
    
  EndIf
  
Until Event = #PB_Event_CloseWindow ; End of the event loop

End
I hate the event loop in the demo VD... but I had to download that at work to lpay with this!

Posted: Wed Jul 15, 2009 5:57 pm
by RASHAD
Rook
I am so sorry for late
The internet is not available for me all the time
I am glad To hear from you my friend

My point is To center the text immediatly While typing

right now at least we have two different point of view

have a good day

RASHAD

Posted: Fri Jul 17, 2009 5:15 pm
by RASHAD
The options are endless:
1- You chang the size
2- You can change the starting position
3- You can change The req Input (char Or digit Or both)
4- Can change the limiit of characters req.
5- Can change Backcolor
6- Can change Frame color
7- Can change the foreground And the background colors
8- Can change the shape of the Caret

And more And more

make it fun

RASHAD

Code: Select all

Global InputString$,InputString_Length.l,IRx,IRy,Bx,By,FrColor,BColor,FColor
IRx=300
IRy=300
Bx=270
By=30
FrColor=$F50304
BColor=$FFFFFF
FColor=$0000FF
InputString$="123-456000"
InputString_Length = 30

; DataSection
;   Image0:
;   IncludeBinary "mobile.bmp"
; EndDataSection

Procedure NewChar(char) 
  If (char > 47 And char < 58) Or char = 45
      InputString$ + Chr(char)
  ElseIf char = 8
      InputString$ = Left(InputString$,Len(InputString$)-1)
  EndIf
   InputString$ = Left(InputString$,InputString_Length)
  StartDrawing( ImageOutput(1) )
    Box(0,0,Bx,By,FrColor)
    Box(2,2,Bx-4,By-10,BColor)
    FrontColor(FColor) 
    DrawingMode(1) 
    SetCaretPos_((300-TextWidth(InputString$))/2+TextWidth(InputString$),19) 
    DrawText((270-TextWidth(InputString$))/2,4,InputString$) 
  StopDrawing() 
  SetGadgetState(0,ImageID(1)) 
EndProcedure 

Procedure WinProc(hWnd,Msg,wParam,lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select Msg 
    Case #WM_CHAR 
      NewChar(wParam) 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

CreateImage(1,Bx,24)

OpenWindow(0,IRx,IRy,300,100,"              Please Input Your Mobile No",#PB_Window_TitleBar)
  ImageGadget(0,15,15,Bx,20,ImageID(1))
  ButtonGadget(1, 120, 60,60, 25,"OK") 
  SetWindowCallback(@WinProc())
  CreateCaret_(WindowID(0),1,3,16):ShowCaret_(WindowID(0))  
 
  NewChar(0) 

Repeat
   EventID = WaitWindowEvent()
   
   Select EventID

    Case #PB_Event_Gadget
    
     Select EventGadget()
     
           Case 1
                Quit = 1            
                
     EndSelect
  EndSelect
     
Until Quit = 1
End
Have fun
RASHAD

Posted: Fri Jul 17, 2009 10:41 pm
by PB
> I just tossed this off at work

Just make sure you don't get caught tossing off. ;)

Posted: Sat Jul 25, 2009 5:58 am
by Rescator
@RASHAD

Doesn't work on Vista here at all, and most likely not Win7 either.

The following looks pretty good on Vista, and should on XP and Win7 as well.
On Linux and Mac you'd have to get rid of the ES_ constant though so you'd loose the centering on those two platforms.

Code: Select all

If OpenWindow(0, 0, 0, 200, 40, "Please Input Password",#PB_Window_TitleBar|#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
    StringGadget(0, 8,  10, 184, 15, "",#PB_String_Password|#PB_String_BorderLess|#ES_CENTER) ;windows API constant
    SetWindowColor(0,0)
    SetGadgetColor(0,#PB_Gadget_BackColor,#White)
    SetGadgetColor(0,#PB_Gadget_FrontColor,#Red)
    SetActiveGadget(0)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
A #PB_String_Center would be really cool, but not sure if that is on the PureBasic wishlist yet?

Posted: Sat Jul 25, 2009 6:54 am
by RASHAD
@Rescator
Hello sir
It works fine with Win 7 I checked it already
But I did not check it with Vista,So let me see @ that


Thank you and have a good day

RASHAD

Posted: Sat Jul 25, 2009 7:20 am
by Rescator
I have Vista x64 btw.

Posted: Sat Jul 25, 2009 7:30 am
by RASHAD
You make it hard to me
I have Ultimate x86
But I have to know then I will answer that

Thank you again sir

RASHAD

Posted: Sat Jul 25, 2009 3:08 pm
by rsts
Works fine under Win 7 x64 - BUT I'm running 32 bit PB.

cheers

Posted: Sat Jul 25, 2009 3:42 pm
by RASHAD
@rsts
My guardian and my friend
Think for a way to enforce Sparkie to be back to the forum again
That man means to me a lot

RASHAD

Posted: Sat Jul 25, 2009 4:14 pm
by rsts
Runs fine under Win 7 64 bit PB too.

I'd be surprised if it's not ok under Vista, but anything's possible.

Will check a little later.

cheers

Posted: Sat Jul 25, 2009 4:26 pm
by Matt
rsts wrote:Runs fine under Win 7 64 bit PB too.

I'd be surprised if it's not ok under Vista, but anything's possible.

Will check a little later.

cheers
Works perfect under vista

Posted: Sat Jul 25, 2009 4:33 pm
by RASHAD
Hello Matt

PB x64
Win 7 x64

It works fine now
Please confirm

Code: Select all

Global InputString$,InputString_Length.l,IRx,IRy,Bx,By,FrColor,BColor,FColor
IRx=300
IRy=300
Bx=270
By=30
FrColor=$F50304
BColor=$FFFFFF
FColor=$0000FF
InputString$="123-456000"
InputString_Length = 30


Procedure NewChar(char) 
  If (char > 47 And char < 58) Or char = 45
      InputString$ + Chr(char)
  ElseIf char = 8
      InputString$ = Left(InputString$,Len(InputString$)-1)
  EndIf
   InputString$ = Left(InputString$,InputString_Length)
  StartDrawing( ImageOutput(1) )
    Box(0,0,Bx,By,FrColor)
    Box(2,2,Bx-4,By-10,BColor)
    FrontColor(FColor) 
    DrawingMode(1) 
    SetCaretPos_((300-TextWidth(InputString$))/2+TextWidth(InputString$),19) 
    DrawText((270-TextWidth(InputString$))/2,4,InputString$) 
  StopDrawing() 
  SetGadgetState(0,ImageID(1)) 
EndProcedure 

Procedure WinProc(hWnd,Msg,wParam,lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select Msg 
    Case #WM_CHAR 
      NewChar(wParam) 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

CreateImage(1,Bx,24)

OpenWindow(0,IRx,IRy,300,100,"              Please Input Your Mobile No",#PB_Window_TitleBar)
  ImageGadget(0,15,15,Bx,20,ImageID(1))
  ButtonGadget(1, 120, 60,60, 25,"OK") 
  SetWindowCallback(@WinProc(),0)
  CreateCaret_(WindowID(0),1,3,16):ShowCaret_(WindowID(0))  
 
  NewChar(0) 

Repeat
   EventID = WaitWindowEvent()
   
   Select EventID

    Case #PB_Event_Gadget
    
     Select EventGadget()
     
           Case 1
                Quit = 1            
                
     EndSelect
  EndSelect
     
Until Quit = 1
End

Posted: Sat Jul 25, 2009 4:43 pm
by rsts
Fine as PB64 under Win 7

cheers