Jump to content

[..] Unexpected Result in _GUICtrlRichEdit_Create


Recommended Posts

Hi,

I recently made a programme wich use multiple _GUICtrlRichEdit_Create, and i think there is a bug in "_GUICtrlRichEdit_Create" function.

With the actual UDF, only one RichEdit can be create in a script.

Because of :

If Not _WinAPI_IsClassName($hWnd, $_GRE_sRTFClassName) Then Return SetError(1, 0, 0) ; Invalid Window handle for _GUICtrlRichEdit_Create 1st parameter

Indeed, before 1st call of this function, $_GRE_sRTFClassName is equal to "", but few lines later in the function, we call :

__GCR_Init()

Wich set $_GRE_sRTFClassName equal to "RichEditX0W" (X change with version)

So, if we made a second call to _GUICtrlRichEdit_Create, _WinAPI_IsClassName must return false because the windows that contains the RichEdit is NOT a RichEdit (paradox ?)

That's why i think

If Not _WinAPI_IsClassName($hWnd, $_GRE_sRTFClassName) Then Return SetError(1, 0, 0) ; Invalid Window handle for _GUICtrlRichEdit_Create 1st parameter
must be deleted from this mothode

By the way, in the same function, there is :

If Not __GCR_IsNumeric($iLeft, ">=0") Then Return SetError(103, 0, 0)
If Not __GCR_IsNumeric($iTop, ">=0") Then Return SetError(104, 0, 0)

We CAN'T create a RichEdit at negative position !

That must be a "copy/past" mistake

There is my version of the function :

Func _GUICtrlRichEdit_Create($hWnd, $sText, $iLeft, $iTop, $iWidth = 150, $iHeight = 150, $iStyle = -1, $iExStyle = -1)
    If Not IsString($sText) Then Return SetError(2, 0, 0) ; 2nd parameter not a string for _GUICtrlRichEdit_Create

    If Not __GCR_IsNumeric($iLeft, "") Then Return SetError(103, 0, 0)
    If Not __GCR_IsNumeric($iTop, "") Then Return SetError(104, 0, 0)
    If Not __GCR_IsNumeric($iWidth, ">0,-1") Then Return SetError(105, 0, 0)
    If Not __GCR_IsNumeric($iHeight, ">0,-1") Then Return SetError(106, 0, 0)
    If Not __GCR_IsNumeric($iStyle, ">=0,-1") Then Return SetError(107, 0, 0)
    If Not __GCR_IsNumeric($iExStyle, ">=0,-1") Then Return SetError(108, 0, 0)

    If $iWidth = -1 Then $iWidth = 150
    If $iHeight = -1 Then $iHeight = 150
    If $iStyle = -1 Then $iStyle = BitOR($ES_WANTRETURN, $ES_MULTILINE)

    If BitAND($iStyle, $ES_MULTILINE) <> 0 Then $iStyle = BitOR($iStyle, $ES_WANTRETURN)
    If $iExStyle = -1 Then $iExStyle = 0x200 ;  $DS_FOREGROUND

    $iStyle = BitOR($iStyle, $__RICHEDITCONSTANT_WS_CHILD, $__RICHEDITCONSTANT_WS_VISIBLE)
    If BitAND($iStyle, $ES_READONLY) = 0 Then $iStyle = BitOR($iStyle, $__RICHEDITCONSTANT_WS_TABSTOP)

    Local $nCtrlID = __UDF_GetNextGlobalID($hWnd)
    If @error Then Return SetError(@error, @extended, 0)

    __GCR_Init()

    Local $hRichEdit = _WinAPI_CreateWindowEx($iExStyle, $_GRE_sRTFClassName, "", $iStyle, $iLeft, $iTop, $iWidth, _
            $iHeight, $hWnd, $nCtrlID)
    If $hRichEdit = 0 Then Return SetError(700, 0, False)

    __GCR_SetOLECallback($hRichEdit)
    _SendMessage($hRichEdit, $__RICHEDITCONSTANT_WM_SETFONT, _WinAPI_GetStockObject($DEFAULT_GUI_FONT), True)
    _GUICtrlRichEdit_AppendText($hRichEdit, $sText)
    Return $hRichEdit
EndFunc   ;==>_GUICtrlRichEdit_Create
_GUIRegisterMsg (Register more than 1 time the same Msg), _Resize_Window (GUICtrlSetResizing for children windows), _GUICtrlSetOnHover (Link a function when mouse go on, left, clic down, clic up, on a control), _InputHeure (Create an input for hour contain), _GUICtrlCalendar (Make a complete calendar), _GUICtrlCreateGraphic3D (Create a 3D graph), _ArrayEx.au3 (Array management), _GUIXViewEx.au3 (List/Tree View management).
Link to comment
Share on other sites

You'll find that line (If Not _WinAPI_IsClassName($hWnd, $_GRE_sRTFClassName) Then Return SetError(1, 0, 0) ) in every function in the GUICtrlRichEdit UDF. Unless you're only allowed one RE control per GUI for some unmentioned reason, that line shouldn't be there because the $hWnd you're passing it in the function is the GUI handle, and not the RE handle. You should probably open a Trac ticket on this in the Bug Tracker to have someone take a look at it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Done : http://www.autoitscript.com/trac/autoit/ticket/2187

_GUIRegisterMsg (Register more than 1 time the same Msg), _Resize_Window (GUICtrlSetResizing for children windows), _GUICtrlSetOnHover (Link a function when mouse go on, left, clic down, clic up, on a control), _InputHeure (Create an input for hour contain), _GUICtrlCalendar (Make a complete calendar), _GUICtrlCreateGraphic3D (Create a 3D graph), _ArrayEx.au3 (Array management), _GUIXViewEx.au3 (List/Tree View management).
Link to comment
Share on other sites

This seems like a duplicate of #2077 that was fixed in AutoIt 3.3.9.0.

Incidentally, the ticket guidelines tell you this when you create a ticket:

Test the reproduction script with both the latest stable and latest beta versions of AutoIt. Check the links to ensure you have the latest versions, AutoIt is updated frequently.

Which I suspect you missed/ignored.
Link to comment
Share on other sites

My mistake, i only check "Open bugs" not "fixed bugs" ;)

Sorry...

_GUIRegisterMsg (Register more than 1 time the same Msg), _Resize_Window (GUICtrlSetResizing for children windows), _GUICtrlSetOnHover (Link a function when mouse go on, left, clic down, clic up, on a control), _InputHeure (Create an input for hour contain), _GUICtrlCalendar (Make a complete calendar), _GUICtrlCreateGraphic3D (Create a 3D graph), _ArrayEx.au3 (Array management), _GUIXViewEx.au3 (List/Tree View management).
Link to comment
Share on other sites

My mistake, i only check "Open bugs" not "fixed bugs" ;)

Sorry...

I rather meant for you to download and run your code, or read the changelog, but whatever fits your fancy I guess.

Somebody close that bug report if it's not a bug.

I don't know. The positional check could be discussed (although it should probably be in it's own ticket, but people are already discussing it there).
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...