A few questions with regards to RichEdit

A few questions with regards to RichEdit

Postby hua » Wed Jun 10, 2009 8: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:
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
 
Last edited by hua on Fri Jun 12, 2009 6:49 am, edited 2 times in total.
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1059
Joined: Fri Oct 28, 2005 2:27 am

Re: A few questions with regards to RichEdit

Postby hua » Thu Jun 11, 2009 6:36 am

Antonio,
Any idea?
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1059
Joined: Fri Oct 28, 2005 2:27 am

Re: A few questions with regards to RichEdit

Postby Antonio Linares » Thu Jun 11, 2009 9:33 am

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
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41462
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: A few questions with regards to RichEdit

Postby hua » Fri Jun 12, 2009 1: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
hua
 
Posts: 1059
Joined: Fri Oct 28, 2005 2:27 am

Re: A few questions with regards to RichEdit

Postby Antonio Linares » Fri Jun 12, 2009 6:15 am

Hua,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41462
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: A few questions with regards to RichEdit

Postby nageswaragunupudi » Fri Jun 12, 2009 8: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
User avatar
nageswaragunupudi
 
Posts: 10326
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: A few questions with regards to RichEdit

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 41462
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 126 guests

cron