Jump to content

Rich edit control / tab problem


 Share

Recommended Posts

I have an application consisting two tabs, each of which contains an edit control. Works fine. However, I'm trying to replace the edit controls with rich edit controls, using the functions in GUIRichEdit.au3.

The code is as follows:

#include <GuiConstants.au3>
#include <GuiRichEdit.au3>
#include <File.au3>
#include <Array.au3>
#include <String.au3>
#include <Misc.au3>

Opt("GUIOnEventMode",1)

Global $dstr

$hWindow=GUICreate("",750,460,-1,-1,$WS_OVERLAPPEDWINDOW+$WS_MAXIMIZE)
GUISetOnEvent($GUI_EVENT_CLOSE,"CloseWindow",$hWindow)

GUISetState(@SW_SHOW,$hWindow)
GUISetState(@SW_ENABLE,$hWindow)

$winsize=WinGetClientSize($hWindow)
$winw=$winsize[0]
$winh=$winsize[1]

$tab=GUICtrlCreateTab(0,10,$winw,22)
GUICtrlSetResizing($tab,$GUI_DOCKTOP+$GUI_DOCKHEIGHT)
GUICtrlSetOnEvent($tab,"ToggleEdit")

$tab1=GUICtrlCreateTabItem ("Input")

$hEdit1=_GUICtrlRichEditCreate($hWindow,0,32,$winw,$winh-32,$ES_MULTILINE+$WS_VSCROLL+$ES_WANTRETURN)

; ORIGINALLY $hEdit1=GUICtrlCreateEdit("",0,32,$winw,$winh-32,$ES_MULTILINE+$WS_VSCROLL+$ES_WANTRETURN)

GUICtrlSendMsg($hEdit1,$EM_LIMITTEXT,4000000,0)

$tab2=GUICtrlCreateTabItem ("Output")
$hEdit2=_GUICtrlRichEditCreate($hWindow,0,32,$winw,$winh-32,$ES_MULTILINE+$WS_VSCROLL+$ES_WANTRETURN)

; ORIGINALLY $hEdit2=GUICtrlCreateEdit("",0,32,$winw,$winh-32,$ES_MULTILINE+$WS_VSCROLL+$ES_WANTRETURN)

GUICtrlSendMsg($hEdit2,$EM_LIMITTEXT,4000000,0)

GUICtrlCreateTabitem ("")
GUICtrlSetState($tab1,$GUI_SHOW)

$hEdit=$hEdit1
GUICtrlSetState($hEdit,$GUI_FOCUS)

$filemenu=GUICtrlCreateMenu("&File")
$fileopen=GUICtrlCreateMenuItem("Open",$filemenu)
GUICtrlSetOnEvent($fileopen,"FileOpenFile")


Func FileOpenFile()
  FileReadFile()
  If $dstr Then
    FileDisplayFile() 
  Else
    DisableReturn() 
    MsgBox(0,"","Unable to open file")
    EnableReturn()
  EndIf
EndFunc

Func FileReadFile()
  FileChangeDir("C:\")
  $file=FileOpenDialog("Open file...",@WorkingDir,"All (*.*)|Text (*.txt)|Html (*.html)",2)
  If @error<>1 Then
    $fileh=FileOpen($file,0)
    If $fileh<>-1 Then
      $dstr=FileRead($fileh)
      If StringInStr($dstr,@CRLF)=0 Then
        $dstr=StringAddCR($dstr)
      EndIf
      FileClose($fileh)
    EndIf
  Else
    $dstr=""
  EndIf
EndFunc

Func FileDisplayFile()

  _GUICtrlRichEditSetText($hEdit,$dstr)

 ; ORIGINALLY GUICtrlSetData($hEdit,$dstr)

  Send("^{HOME}")
EndFunc

Func ToggleEdit()
  If GUICtrlRead($tab)=0 Then
    $hEdit=$hEdit1
  Else  
    $hEdit=$hEdit2
  EndIf
  GUICtrlSetState($hEdit,$GUI_FOCUS)
EndFunc

Func CloseWindow()
  Exit
EndFunc

While 1
  Sleep(100)
WEnd

There are several problems, which don't happen when I use normal edit controls:

1. The top of the rich edit control is slightly over the tabs. I've tried lots of different values, but nothing seems to work (some values actually cause the program to crash). I want it to grow automatically to fill the available space.

2. When a file is opened, forcing vertical scrolling, the bottom of the control lies under the task bar at the bottom of the screen.

3. The topmost control isn't automatically focussed.

4. If I open a file, it appears in both controls - tabbing between them doesn't seem to do anything. I need to be able to read from / write to the control that is currently active. And copy / paste from one to the other.

I wondered if anyone could explain to me where I'm going wrong. Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...