SelectAll with WinGUI Editor_New

New to FreeBASIC? Post your questions here.
Tonigau
Posts: 14
Joined: Feb 25, 2021 20:19

SelectAll with WinGUI Editor_New

Postby Tonigau » Mar 17, 2021 8:39

I would like to copy all text in the lower Editor_New control without manually selecting first, any suggestions for a workaround.

I see there is EM_SETSEL in Win32 API but it is not implemented in WinGui.bi , It would need the start & end first.

In My App I can print the contents to console of the lower Editor_New with the Build Button without selecting.
The copy button is for the lower editor, it works if manual selecting first. (I have to put text there manually for test)

Sub BuildPtrTabl will put text result in lower Editor when I have it coded



Code: Select all

'-------------------------------------------------
' StringTableconv.bas    V1.0
' Tool for String Table --> String pointer Table
' Created on 2021-03-17  ToniG
' Last Update 2021- -
'-------------------------------------------------

#Include "WinGUI.bi"

Dim As HWND Window_Main, Editor1, Editor2, Btn_Build, Btn_Copy, Btn_Paste, Btn_Clear, Edit_Font
Dim As HFONT hFont
Dim As MSG msg
Dim As Long x0, y0, W1, H1, Rpos
Dim As String Text1
Declare Sub BuildPtrTabl (Editor2 As HWND)

  W1 = 1000   ' Window Width
  H1 = 700  ' Window Height
  Rpos = 200 ' Right ref
  Text1 = "Input:  String Table          Paste ClipBoard   (only ""string"" lines will be processed, other lines ignored)"
                                                     ' " _" line continuation wont work!!
'Create a window with text editors and a button:
'                            X    Y   W   H
Window_Main = Window_New   (100, 100, W1, H1, "Create String Pointer Table")
                                     ' "'    Paste Table here..." + Chr(13) + Chr(10) Just for ref. editBox
Editor1 = Editor_New      (20, 40, 800, 350, "",, Window_Main)
Editor2 = Editor_New      (20, 410, 800, 200, "",, Window_Main)

Var Label_txt1 = Label_New   (30, 20, 750, 20, Text1,, Window_Main)
Var Label_txt2 = Label_New   (30, 390, 150, 20, "Output:  Pointer Table",, Window_Main)

Btn_Paste = Button_New      (W1-180, 40, 100, 40, "Paste",, Window_Main)
Btn_Clear = Button_New      (W1-180, 100, 100, 40, "Clear",, Window_Main)
Btn_Build = Button_New      (W1-180, 320, 100, 40, "Build",, Window_Main)
Btn_Copy = Button_New      (W1-180, 550, 100, 40, "Copy",, Window_Main)
'                                    ^ Window resize event overides on form open

' Fonts
'hFont = Control_Createfont("Courier New",,, FW_THIN)
hFont = Control_Createfont("Courier New",,, FW_BOLD)   '< Create Font
Control_SetFont(Editor1), hFont                         '< Set Font


'------------------
'Event loop:
Do
   WaitEvent(Window_Main, msg)
   Select Case msg.hwnd
      Case Btn_Paste
         If msg.message = WM_LBUTTONUP Then
           EditBox_Paste(Editor1)
         End If
         
      Case Btn_Clear
         If msg.message = WM_LBUTTONUP Then
           EditBox_Clear(Editor1) ' This only clears selected text
           EditBox_SetText(Editor1,"")
         End If        
      
      Case Btn_Build
         If msg.message = WM_LBUTTONUP Then
           BuildPtrTabl(Editor2)
         End If
         
         
      Case Btn_Copy
         If msg.message = WM_LBUTTONUP Then
           EditBox_Copy(Editor2)
         End If
          
     Case Else   
       'Resize Controls x if window size change
       Window_GetSize(Window_Main, x0, y0, W1, H1)
       Control_Resize(Editor1, 20, 40, W1-Rpos, 350)
       Control_Resize(Editor2, 20, 410, W1-Rpos, 200)
       Control_Resize(Btn_Paste, W1-(Rpos-40), 40, 100, 40)
       Control_Resize(Btn_Clear, W1-(Rpos-40), 100, 100, 40)
       Control_Resize(Btn_Build, W1-(Rpos-40), 320, 100, 40)
       Control_Resize(Btn_Copy, W1-(Rpos-40), 550, 100, 40)         
   End Select
Loop Until Window_Event_Close(Window_Main, msg)

End

'Wait until window is closed:
Do
   WaitEvent(Window_Main, msg)
Loop Until Window_Event_Close(Window_Main, msg)

'Delete font:

   Control_DeleteFont(hFont)
End


Sub BuildPtrTabl (Editor2 As HWND)
               'Just for test
   Cls
   Print EditBox_GetText(Editor2)
End Sub


jj2007
Posts: 2144
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: SelectAll with WinGUI Editor_New

Postby jj2007 » Mar 17, 2021 10:31

Hi Tonigau,

EM_SETSEL is a simple message:

Code: Select all

      Case Btn_Copy
         If msg.message = WM_LBUTTONUP Then
            SetWindowText(Editor2, "Copy sets a little text, so that we have something to select")
            SetFocus(Editor2)
            SendMessage(Editor2, EM_SETSEL, 0, -1)
         End If

I've misused your copy button for this little test.
Tonigau
Posts: 14
Joined: Feb 25, 2021 20:19

Re: SelectAll with WinGUI Editor_New

Postby Tonigau » Mar 17, 2021 21:08

Than works perfectly !,

Thank you :-)

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 1 guest