Page 1 of 1

String Gadget Alignment

Posted: Sun Jan 02, 2005 7:44 am
by cecilcheah
How come when i add the following code in the StringGadget, all my text appears right aligned?

Code: Select all

StringGadget(#TBKText, 13, 143, 580, 150, "",#PB_String_Multiline|#WS_VSCROLL|#ESB_DISABLE_LEFT | #ESB_DISABLE_RIGHT)
....

SetGadgetText(#TBKText, TBK(NodeItem)\TBKText)
...


Anyone knows?

Cecil

Posted: Sun Jan 02, 2005 8:39 am
by Xombie
I did a quick test with the Gadget.pb example in Purebasic and changed the first StringGadget line to...

Code: Select all

StringGadget(0,  20, Top, 200, GadgetHeight, "", #PB_String_MultiLine | #WS_VSCROLL | #ESB_DISABLE_LEFT | #ESB_DISABLE_RIGHT)
And then did a ...

Code: Select all

SetGadgetText(0, "Test")
To test it and it shows up left-aligned. So I dunno.

Re: String Gadget Alignment

Posted: Sun Jan 02, 2005 10:20 am
by GPI
cecilcheah wrote:

Code: Select all

StringGadget(#TBKText, 13, 143, 580, 150, "",#PB_String_Multiline|#WS_VSCROLL|#ESB_DISABLE_LEFT | #ESB_DISABLE_RIGHT)
....

SetGadgetText(#TBKText, TBK(NodeItem)\TBKText)
...
Because this example only work on XP and use an unauthorizate way of useing the constants.

Posted: Sun Jan 02, 2005 11:45 am
by cecilcheah
Yes, i am developing in Win 98, not XP. Is there any way around this?

Cecil

Posted: Sun Jan 02, 2005 1:30 pm
by GPI
only for editor-gadgets

Code: Select all

Procedure EditorGadgetEnableTextWarp(Id); - Activate the automatic word-warp for a EditorGadget
  GID=GadgetID(Id)
  dc=GetWindowDC_(GID)
  SendMessage_(GID, #EM_SETTARGETDEVICE ,dc ,-1)
  ReleaseDC_(GID,dc)
EndProcedure

Re: String Gadget Alignment

Posted: Wed Apr 13, 2005 6:18 pm
by zikitrake
cecilcheah wrote:How come when i add the following code in the StringGadget, all my text appears right aligned?

Code: Select all

StringGadget(#TBKText, 13, 143, 580, 150, "",#PB_String_Multiline|#WS_VSCROLL|#ESB_DISABLE_LEFT | #ESB_DISABLE_RIGHT)
....

SetGadgetText(#TBKText, TBK(NodeItem)\TBKText)
...


Anyone knows?

Cecil
Someone has solved this? Using a stringgadget in win98

Bye

Posted: Wed Apr 13, 2005 10:49 pm
by Sparkie
I'm not at home so I can't test this on Win98, but this is a Win32API multiline Edit Control with wordwrap. I assume that's what you are looking for :?:

Code: Select all

Global editFont.l 
editFont = LoadFont(0, "Verdana", 10) 

; --> Procedure for creating multiline, wordwrap edit control 
Procedure CreateWordrapEdit(controlId, x, y, width, height, text$) 
  ; you can add #WS_EX_CLIENTEDGE For border 
  hEdit = CreateWindowEx_(#WS_EX_LEFT | #WS_EX_LTRREADING | #WS_EX_RIGHTSCROLLBAR, "Edit", text$, #WS_CHILD | #WS_GROUP | #WS_VSCROLL | #WS_TABSTOP | #WS_VISIBLE | #ES_AUTOVSCROLL | #ES_LEFT | #ES_MULTILINE , x, y, width, height, WindowID(0), controlId, GetModuleHandle_(0), 0) 
  SendMessage_(hEdit, #WM_SETFONT, editFont, 1) 
  ProcedureReturn hEdit 
EndProcedure 

; --> Procedure for setting edit control text 
Procedure SetEditText(editId, editText$) 
  result = SendMessage_(editId, #WM_SETTEXT, 0, editText$) 
  ProcedureReturn result 
EndProcedure 

; --> Procedure for getting edit control text 
Procedure.s GetEditText(editId) 
  ; --> Get the text lenght  (we add 1 for ending null) 
  tlen = SendMessage_(editId, #WM_GETTEXTLENGTH, 0, 0) + 1 
  editText$ = Space(tlen) 
  SendMessage_(editId, #WM_GETTEXT, tlen  , @editText$) 
  ProcedureReturn editText$ 
EndProcedure 

If OpenWindow(0, 0, 0, 300, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "My Edit Control") And CreateGadgetList(WindowID(0)) 
  ; --> Create our edit control 
  edit_0 = CreateWordrapEdit(0, 5, 5, 290, 150, "This is my wordrap Edit control") 
  ButtonGadget(1, 40, 165, 100, 20, "Change text") 
  ButtonGadget(2, 150, 165, 100, 20, "Get text") 
  Repeat 
    event = WaitWindowEvent() 
    Select event 
      Case #PB_EventGadget 
        Select EventGadgetID() 
          Case 1 
            ; --> Setting the text 
            SetEditText(edit_0, "This is my new text.") 
          Case 2 
            ; --> Getting the text 
            eText$ = GetEditText(edit_0) 
            MessageRequester("The text is", eText$) 
        EndSelect 
    EndSelect 
  Until event = #PB_Event_CloseWindow 
EndIf 
End
I would think the standard PB StringGadget could do the same, but for some reason it always has the #ES_AUTOHSCROLL flag, and I have yet to find a way to prevent it. :(

* Edited to clean it up a little ;)

Posted: Thu Apr 14, 2005 7:31 am
by zikitrake
Sparkie Very Thanks!!! I will test it at home.

Posted: Fri Apr 15, 2005 10:44 am
by zikitrake
:D It works great on Win98

Sparkie, very very VERY Thank you!

Posted: Fri Apr 15, 2005 5:22 pm
by Sparkie
You're welcome zikitrake. :)

Posted: Tue May 10, 2005 7:05 pm
by zikitrake
Sparkie wrote:I'm not at home so I can't test this on Win98, but this is a Win32API multiline Edit Control with wordwrap. I assume that's what you are looking for :?:

Code: Select all

Global editFont.l 
editFont = LoadFont(0, "Verdana", 10) 

; --> Procedure for creating multiline, wordwrap edit control 
Procedure CreateWordrapEdit(controlId, x, y, width, height, text$) 
  ; you can add #WS_EX_CLIENTEDGE For border 
  hEdit = CreateWindowEx_(#WS_EX_LEFT | #WS_EX_LTRREADING | #WS_EX_RIGHTSCROLLBAR, "Edit", text$, #WS_CHILD | #WS_GROUP | #WS_VSCROLL | #WS_TABSTOP | #WS_VISIBLE | #ES_AUTOVSCROLL | #ES_LEFT | #ES_MULTILINE , x, y, width, height, WindowID(0), controlId, GetModuleHandle_(0), 0) 
  SendMessage_(hEdit, #WM_SETFONT, editFont, 1) 
  ProcedureReturn hEdit 
EndProcedure 

; --> Procedure for setting edit control text 
Procedure SetEditText(editId, editText$) 
  result = SendMessage_(editId, #WM_SETTEXT, 0, editText$) 
  ProcedureReturn result 
EndProcedure 

; --> Procedure for getting edit control text 
Procedure.s GetEditText(editId) 
  ; --> Get the text lenght  (we add 1 for ending null) 
  tlen = SendMessage_(editId, #WM_GETTEXTLENGTH, 0, 0) + 1 
  editText$ = Space(tlen) 
  SendMessage_(editId, #WM_GETTEXT, tlen  , @editText$) 
  ProcedureReturn editText$ 
EndProcedure 

If OpenWindow(0, 0, 0, 300, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "My Edit Control") And CreateGadgetList(WindowID(0)) 
  ; --> Create our edit control 
  edit_0 = CreateWordrapEdit(0, 5, 5, 290, 150, "This is my wordrap Edit control") 
  ButtonGadget(1, 40, 165, 100, 20, "Change text") 
  ButtonGadget(2, 150, 165, 100, 20, "Get text") 
  Repeat 
    event = WaitWindowEvent() 
    Select event 
      Case #PB_EventGadget 
        Select EventGadgetID() 
          Case 1 
            ; --> Setting the text 
            SetEditText(edit_0, "This is my new text.") 
          Case 2 
            ; --> Getting the text 
            eText$ = GetEditText(edit_0) 
            MessageRequester("The text is", eText$) 
        EndSelect 
    EndSelect 
  Until event = #PB_Event_CloseWindow 
EndIf 
End
I would think the standard PB StringGadget could do the same, but for some reason it always has the #ES_AUTOHSCROLL flag, and I have yet to find a way to prevent it. :(

* Edited to clean it up a little ;)
In this code, how can I set the focus in a created "CreateWordrapEdit"?

I am you very thanked, Sparkie

Posted: Tue May 10, 2005 7:19 pm
by Sparkie
Assuming the handle to the CreateWordrapEdit is edit_0 as in the code above, add this to set the focus.

Code: Select all

SetFocus_(edit_0)

Posted: Tue May 10, 2005 9:08 pm
by zikitrake
:oops: It knew it but I forgot it!

1000 thankyou!