String Gadget Alignment

Just starting out? Need help? Post your questions and find answers here.
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

String Gadget Alignment

Post 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
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post 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.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: String Gadget Alignment

Post 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.
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Post by cecilcheah »

Yes, i am developing in Win 98, not XP. Is there any way around this?

Cecil
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post 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
zikitrake
Addict
Addict
Posts: 876
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: String Gadget Alignment

Post 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
PB 6.21 beta, PureVision User
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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 ;)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
zikitrake
Addict
Addict
Posts: 876
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

Sparkie Very Thanks!!! I will test it at home.
PB 6.21 beta, PureVision User
zikitrake
Addict
Addict
Posts: 876
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

:D It works great on Win98

Sparkie, very very VERY Thank you!
PB 6.21 beta, PureVision User
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

You're welcome zikitrake. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
zikitrake
Addict
Addict
Posts: 876
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post 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
PB 6.21 beta, PureVision User
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
zikitrake
Addict
Addict
Posts: 876
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

:oops: It knew it but I forgot it!

1000 thankyou!
PB 6.21 beta, PureVision User
Post Reply