FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour A few questions with regards to RichEdit
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
A few questions with regards to RichEdit
Posted: Wed Jun 10, 2009 08:03 AM
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:


Same question, why and how to solve it?

TIA

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

Code (fw): Select all Collapse
#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
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: A few questions with regards to RichEdit
Posted: Thu Jun 11, 2009 06:36 AM

Antonio,
Any idea?

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: A few questions with regards to RichEdit
Posted: Thu Jun 11, 2009 09:33 AM
Hua,

Please try it this way:
Code (fw): Select all Collapse
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: A few questions with regards to RichEdit
Posted: Fri Jun 12, 2009 01:15 AM

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 :)

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: A few questions with regards to RichEdit
Posted: Fri Jun 12, 2009 06:15 AM

Hua,

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: A few questions with regards to RichEdit
Posted: Fri Jun 12, 2009 08:13 AM
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 ?
Regards



G. N. Rao.

Hyderabad, India
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: A few questions with regards to RichEdit
Posted: Fri Jun 12, 2009 10:30 AM

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().

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion