Page 1 of 1

A few questions with regards to RichEdit

PostPosted: Wed Jun 10, 2009 8:03 am
by hua
Hi guys,

These questions uses a reduced, self-contained example that'll appear way below as point of reference. Just copy it to \fwh\samples and compile and run it from there.

So here's the question:
1. When I click on File -> Edit, the dialogue box appear but the second RTF control (oEdit) doesn't appear. Why and how to solve this?

2. If user run this program and selects File -> Exit, the program terminates normally. However, if user runs File -> Edit prior to that, this error message appears:
Image

Same question, why and how to solve it?

TIA

p.s. I think this post is basically asking the same issue.

Code: Select all  Expand view

#include "FiveWin.ch"
#include "richedit.ch"

static oWnd, oRtf, cRtf, oEdit, cVar
function main()
  local o
  local hDll := LoadLibrary( "Riched20.dll" )


  define window oWnd menu oMenu() color "w/b"

  cRtf := memoread("fiveodbc.rtf")
  @ 10, 20 RICHEDIT oRtf VAR cRtf of oWnd
  oRtf:setReadOnly(.t.)

  activate window oWnd ;
    on init adjustRtf() ;
    maximized

  freeLibrary(hDll)
return nil
//----------------------------------------------------------------------
function adjustRtf()
  // position at lower-half and make full use of screen width
  local nTop, nLeft, nHorRes, aRect, nHeight, nWidth
  nTop    := 600
  nLeft   := 10
  nHorRes := GetSysMetrics( 0 )
  aRect := GetClientRect(oWnd:hWnd)
  nHeight  := aRect[3] - nTop - 10
  nWidth := aRect[4] - aRect[2] - 20
  oRtf:move(nTop, nLeft, nWidth, nHeight , .t. )

return nil
//----------------------------------------------------------------------
function oMenu()
  LOCAL oMenu

  MENU oMenu 2007
     MENUITEM "&File "
        MENU
           MENUITEM "Edit"  ACTION edit()
           MENUITEM "E&xit" ACTION oWnd:end()
        ENDMENU
  ENDMENU

RETURN oMenu
//----------------------------------------------------------------------
function edit()
  local aRect := GetCoors(oRtf:hWnd)
  local oDlg

  DEFINE DIALOG oDlg of oWnd ;
    FROM aRect[1]-33, aRect[2]-10 TO aRect[3]+33+10, aRect[4]+10 ;
    STYLE nOr( DS_MODALFRAME, WS_POPUP, WS_VISIBLE) ;
    PIXEL

  cVar := cRtf
  @ aRect[1], aRect[2] RICHEDIT oEdit VAR cVar of oDlg ;
     SIZE oRtf:nWidth, oRtf:nHeight                    ;
     PIXEL

  ACTIVATE DIALOG oDlg  ;
    on init (                ;
              RtfBar(oDlg) ;
            )

return nil
//----------------------------------------------------------------------
function rtfBar(oDlg)
  local oBar, oBtns := array(10)


  DEFINE BUTTONBAR oBar OF oDlg SIZE 30,33 3DLOOK 2007

  DEFINE BUTTON oBtns[1] FILE "..\bitmaps\save.bmp" OF oBar ;
    ACTION (oRtf:setText(cVar), oDlg:end() )                    ;
    TOOLTIP "Save"

return nil
 

Re: A few questions with regards to RichEdit

PostPosted: Thu Jun 11, 2009 6:36 am
by hua
Antonio,
Any idea?

Re: A few questions with regards to RichEdit

PostPosted: Thu Jun 11, 2009 9:33 am
by Antonio Linares
Hua,

Please try it this way:
Code: Select all  Expand view


#include "FiveWin.ch"
#include "richedit.ch"

static oWnd, oRtf, cRtf, oEdit, cVar
function main()
  local o
  local hDll := LoadLibrary( "Riched20.dll" )


  define window oWnd menu oMenu() color "w/b"

  cRtf := memoread("fiveodbc.rtf")
  @ 10, 20 RICHEDIT oRtf VAR cRtf of oWnd
  oRtf:setReadOnly(.t.)

  activate window oWnd ;
    on init adjustRtf() ;
    maximized

  // freeLibrary(hDll)
return nil
//----------------------------------------------------------------------
function adjustRtf()
  // position at lower-half and make full use of screen width
  local nTop, nLeft, nHorRes, aRect, nHeight, nWidth
  nTop    := 600
  nLeft   := 10
  nHorRes := GetSysMetrics( 0 )
  aRect := GetClientRect(oWnd:hWnd)
  nHeight  := aRect[3] - nTop - 10
  nWidth := aRect[4] - aRect[2] - 20
  oRtf:move(nTop, nLeft, nWidth, nHeight , .t. )

return nil
//----------------------------------------------------------------------
function oMenu()
  LOCAL oMenu

  MENU oMenu 2007
     MENUITEM "&File "
        MENU
           MENUITEM "Edit"  ACTION edit()
           MENUITEM "E&xit" ACTION oWnd:end()
        ENDMENU
  ENDMENU

RETURN oMenu
//----------------------------------------------------------------------
function edit()
  local aRect := GetCoors(oRtf:hWnd)
  local oDlg, oEdit

  DEFINE DIALOG oDlg of oWnd ;
    FROM aRect[1]-33, aRect[2]-10 TO aRect[3]+33+10, aRect[4]+10 ;
    STYLE nOr( DS_MODALFRAME, WS_POPUP, WS_VISIBLE) ;
    PIXEL

  cVar := cRtf
  @ 6, 0 RICHEDIT oEdit VAR cVar of oDlg ;
     SIZE oRtf:nWidth, oRtf:nHeight                    ;
     PIXEL
     
  oDlg:oClient = oEdit
     
  ACTIVATE DIALOG oDlg  ;
    on init ( RtfBar(oDlg), oDlg:ReSize() )

return nil
//----------------------------------------------------------------------
function rtfBar(oDlg)
  local oBar, oBtns := array(10)


  DEFINE BUTTONBAR oBar OF oDlg SIZE 30,33 3DLOOK 2007

  DEFINE BUTTON oBtns[1] FILE "..\bitmaps\save.bmp" OF oBar ;
    ACTION (oRtf:setText(cVar), oDlg:end() )                    ;
    TOOLTIP "Save"

return nil

function ResetOleUninit()

return nil
 

Re: A few questions with regards to RichEdit

PostPosted: Fri Jun 12, 2009 1:15 am
by hua
Thanks Antonio! The program is now working as expected and the error message after exiting the program is gone.

I don't actually understands what ResetOleUninit() is for though :)

Re: A few questions with regards to RichEdit

PostPosted: Fri Jun 12, 2009 6:15 am
by Antonio Linares
Hua,

You are not using OLE there, so that change is fine :-)

Re: A few questions with regards to RichEdit

PostPosted: Fri Jun 12, 2009 8:13 am
by nageswaragunupudi
Mr Antonio

Antonio Linares wrote:Hua,

You are not using OLE there, so that change is fine :-)


Does this interfere with an application extensively using TOleAuto() in other modules ?
How about making this a static function inside TRichEdi.Prg ?

Re: A few questions with regards to RichEdit

PostPosted: Fri Jun 12, 2009 10:30 am
by Antonio Linares
Dear Rao,

I have been reviewing the source code of RESETOLEUNINIT() and there is no conflict with TOleAuto() except that a call to OleUninitialize() is done.

We need to check if OleInitialize() works like a DLL (using an internal counter). If yes, there should be no conflict at all with TOleAuto().