Text-block

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by merendo.

I´m coding a little HTML Editor. And now I have a big problem , which doesn´t allow me to go on with working until I´ve fixed it. So I´m gonna ask you for a sollution: I want to draw a block, where you can enter text, like this:

This is a field, where you can enter text. Now I ask you if it is also possible to draw a field like this in PB in a window. I also want to make it possible, that the user can change fonts, sizes, colors and so on. I also want to have the scrollbars on the right side of the field. Is this possible???

All right. I´m not sure how I can enable HTML support for this topic post. Please be so kind and copy the code in an external HTML document and view it with a browser.

Greetings and thanks, merendo

We always need to hear both sides of the story (by Phil Collins)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

Hi,

If you want the font style to be the same in the whole (this is how it works usually) you can use an Edit control to do that (that is, a multilined StringGadget, I don't know how to do it without CreateWindowEx_()). In any case, you can use the RichEdit library to achieve the desired result (I think it will save you typing).

Feel free to ask for further help. Bye,

El_Choni
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by merendo.

I feel.
No, I don´t want the font to be the same in the whole block. I want to have block, where the user can mark text, and press a button. When a such event happens, the font should change only in the marked area. (Don´t know how, f.e.: FontRequester(), and then using the font commands)

We always need to hear both sides of the story (by Phil Collins)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

Hi,

If you decide to use the RichEdit library to do so, a sample code would be something like:

Code: Select all

;
;
; RichEdit example
;
; PureBasic example program: how to use the RichEdit library version 1.5
; Uses also the API
; Requires PureBasic 3.0
;
; by El_Choni
;

Global ParentHandle, hMenu, RichEditID
Global WindowWidth, WindowHeight
Global RichEditIndex
Global rc.RECT
Global Quit.b

DisableDebugger

Procedure Error(ErrorMessage.s, fatal.b) ; Error handling
  MessageRequester("Error", ErrorMessage, 0)
  If fatal
    End
  EndIf
EndProcedure

#IDM_BASE = 10000
#IDM_FORMAT_FONT = #IDM_BASE+20

Procedure WndProc(hWnd, uMsg, wParam, lParam)
  result = 0
  Select uMsg
    Case #WM_COMMAND
      If lParam = 0
        Select wParam & $ffff
          Case #IDM_FORMAT_FONT
            FontDialog(#CF_BOTH)
        EndSelect
      EndIf
    Case #WM_SIZE
      If (hWnd=ParentHandle) & (IsIconic_(ParentHandle)=0)
        WindowWidth = lParam & $ffff
        WindowHeight = lParam>>16
        GetClientRect_(ParentHandle, @rc)
        ResizeRichEdit(RichEditIndex, 0, 0, rc\right-rc\left, rc\bottom-rc\top)
        result = 1
      EndIf
    Case #WM_CLOSE
      If hWnd = ParentHandle
        Quit = 1
      EndIf
    Default
      If hWnd  ParentHandle
        result = DefWindowProc_(hWnd, uMsg, wParam, lParam)
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

EnableDebugger

hMenu = CreateMenu(0)
If hMenu
  MenuTitle("&Format")
    MenuItem(#IDM_FORMAT_FONT, "&Font")
EndIf

If OpenWindow(0, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget, "RichEdit sample")

  ParentHandle = WindowID()
  SetClassLong_(ParentHandle, #GCL_HBRBACKGROUND, 0)
  AttachMenu(0, ParentHandle)
  WindowWidth = WindowWidth()
  WindowHeight = WindowHeight()

  RichEditIndex = 0
  If OpenRichEdit(ParentHandle, RichEditIndex, 0, 0, 0, 0, "")
    RichEditID = RichEditID(0)
    SetWindowLong_(RichEditID, #GWL_EXSTYLE, #WS_EX_CLIENTEDGE)
    GetClientRect_(ParentHandle, @rc)
    ResizeRichEdit(RichEditIndex, 0, 0, rc\right-rc\left, rc\bottom-rc\top)
    ActivateRichEdit(RichEditIndex)
  Else
    Error("Could not open the RichEdit control.", 1)
  EndIf

  SetForegroundWindow_(ParentHandle)
  UseWindow(0)
  SetWindowCallback(@WndProc())

  Repeat
    WaitWindowEvent()
  Until Quit = 1

EndIf

End
Of course, you would have to install the library. It's available at Paul's site:

http://www.reelmediaproductions.com/pb

I would post it at DarkUni's also, but I don't know how.

I hope your project goes Ok, here we are if you need any help.

Bye,

El_Choni
Post Reply