Jump to content
bobsyuruncle

Problem with Pop Up Gui and _GUICtrlRichEdit_Create

Recommended Posts

Good day to the autoit community.

I am having an issue with the _GUICtrlRichEdit on a pop-up gui box. I have cobbled a short script together that replicates the issue. Simply run the script and click the button for the pop-up gui with the richedit box. If you close the pop-up gui and re-click the button, the richedit box fails to load on subsequent pop-up gui launches.
 

#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
$Form1_1 = GUICreate("hubconsole", 655, 697)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1_1Close")
$gethubbutton = GUICtrlCreateButton("Get Info", 501, 129, 81, 25)
GUICtrlSetOnEvent(-1, "Main")
GUISetState(@SW_SHOW)

Func Form1_1Close()
exit
EndFunc

While 1
    Sleep(100)
WEnd

Func Main()
    Local $hGui, $hRichEdit, $iMsg
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
    global $richgui = $hGui
    GUISetOnEvent($GUI_EVENT_CLOSE, "Form2_1Close")
    global $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit, @CR & "This is more text")
    GUISetState()

EndFunc

    Func Form2_1Close()
        _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
        GUIDelete($richgui)
    EndFunc

 

Some further information from diagnostic:
The first cycle around shows no @error's for the deconstructor Form2_1Close().. so the richedit destroy and guidelete both happen.
When I click the button for the second launch, I see the pop-up gui has a new HWnd.. example: 1st click (0x00514B6) 2nd click (0x000614B6)
on the line    " global $hRichEdit = _GUICtrlRichEdit_Create($hGui...  " I see value to @error of 1 which isn't detailed in the helpfile of the function, but if I dig into the include I see error 1 gets set when:  If Not _WinAPI_IsClassName($hWnd, $_GRE_sRTFClassName) Then Return SetError(1, 0, 0) ; Invalid Window handle for _GUICtrlRichEdit_Create 1st parameter

I'm stuck at this point as I can't figure why "_WinAPI_IsClassName($hWnd, $_GRE_sRTFClassName" comes back with a failure on subsequent launches of the popup.

Share this post


Link to post
Share on other sites

Maybe try to remove the Local and Global declarations of $hRichEdit and then declare it as global at the top of the script, outside a func

Share this post


Link to post
Share on other sites

Thanks for the suggestion. No luck unfortunately:

Pasting partial sample showing the modified code. Everything else is same as example in 1st post:

Opt("GUIOnEventMode", 1)
$Form1_1 = GUICreate("hubconsole", 655, 697)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1_1Close")
$gethubbutton = GUICtrlCreateButton("Get Hub Info", 501, 129, 81, 25)
GUICtrlSetOnEvent(-1, "Main")
GUISetState(@SW_SHOW)
global $richgui, $hRichEdit

Func Form1_1Close()
exit
EndFunc

While 1
    Sleep(100)
WEnd

Func Main()
    Local $hGui, $hRichEdit, $iMsg
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
    $richgui = $hGui
    GUISetOnEvent($GUI_EVENT_CLOSE, "Form2_1Close")
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit, @CR & "This is more text")
    GUISetState()

EndFunc

 

Share this post


Link to post
Share on other sites

Thanks, I removed the line "Local $hGui, $hRichEdit, $iMsg" from the script.

Same Behavior unfortunately

Func Main()
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
    $richgui = $hGui
    GUISetOnEvent($GUI_EVENT_CLOSE, "Form2_1Close")
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit, @CR & "This is more text")
    GUISetState()

EndFunc

 

Share this post


Link to post
Share on other sites

Is this a bug with _GUICtrlRichEdit_Create?
Can anybody shed some light on what maybe "_WinAPI_IsClassName($hWnd, $_GRE_sRTFClassName"  is doing or why the gui somehow changes that value on multiple launch?

Thanks

Share this post


Link to post
Share on other sites

No bug, this works for me without issue :

#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $hGui, $hRichEdit

$Form1_1 = GUICreate("hubconsole", 655, 697)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1_1Close")
$gethubbutton = GUICtrlCreateButton("Get Info", 501, 129, 81, 25)
GUICtrlSetOnEvent(-1, "Main")
GUISetState()

While 1
    Sleep(100)
WEnd

Func Main()
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Form2_1Close")
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
        BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit, @CR & "This is more text")
    GUISetState()
    ; msgbox(0,"", "gui : " & $hGui &@crlf& "richedit : " & $hRichEdit)
EndFunc

Func Form1_1Close()
    exit
EndFunc

Func Form2_1Close()
    _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
    GUIDelete($hGui)
    ; msgbox(0,"", "gui : " & $hGui &@crlf& "richedit : " & $hRichEdit)
EndFunc

 

Share this post


Link to post
Share on other sites

I ran the code Mikell posted and it works fine for me using AutoIt 3.3.12.0.

You're running an older version of AutoIt, you have probably run into a bug that was in the _GUICtrlRichEdit_Create function that was fixed in later versions.


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

Share this post


Link to post
Share on other sites

THANK YOU!!!!

I had searched the forums before but did not see the bug post the first scan through. This was in fact a problem with using an older autoit engine (Couldn't be helped in this project).
Relevant bug post found here: http://www.autoitscript.com/forum/topic/139788-unexpected-result-in-_guictrlrichedit_create/

Based on the information I found on that bug post I have modified _GUICtrlRichEdit_Create to manually resolve the issue for this project. 

 

Share this post


Link to post
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

  • Similar Content

    • By therks
      I'm trying to implement a scrolling list of controls. I have it sort of working using the GUIScrollBars_Ex UDF by @Melba23 found here. I also want to be able to tab through the controls, which I have accomplished by adding $WS_EX_CONTROLPARENT to the child GUI. The problem is that with that style applied, the scrollbar doesn't act like a scrollbar, instead it acts as a title bar to the child GUI letting you drag the it around (and you can even "maximize" it by double clicking).
      Any ideas?
      #include <GUIConstants.au3> #include "GUIScrollbars_Ex.au3" $iButtonCount = 30 $hParent = GUICreate('Example', 300, 230) $hChild = GUICreate('', 300, 200, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $hParent) For $i = 0 To $iButtonCount GUICtrlCreateButton('Button in list', 0, $i*30, 300, 30) Next GUISwitch($hParent) GUICtrlCreateButton('More Buttons', 0, 200, 150, 30) GUICtrlCreateButton('More Buttons', 150, 200, 150, 30) GUISetState(@SW_SHOW, $hParent) GUISetState(@SW_SHOW, $hChild) _GUIScrollbars_Generate($hChild, 100, $iButtonCount * 30+20) While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd  
    • By Saravanan2213
      Hi everyone,
      i just need your help. i have script for cleaning browsing history and other unwanted file but the problem is i don't want to see the GUI i have attached below. It should not show anything on the screen. is it possible to do it in autoit. thanks in advance.
       
      So for i have tried flag
      Run("rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 255", "", @SW_HIDE)
      @SW_DISABLE
       
      Looking forward your help.........

    • By Pickpocketz88
      First I would just like to say HELLO! to anyone reading. It has been a while since I've posted to the Forums but I'm always crawling around.
      Now to the matter at hand. I have been looking high and low for a simplistic answer my burned out brain can find but to no avail. I've only recently upped my AutoIt skill and only by a little bit such as ordering my script neatly with my own UDFs and using Global/Dim more often to make my GUI creation understandable and easy to keep things orderly. My current problem however is figuring out how to make my newest endeavor work which is my own "Debugger". I've made a GUI with an Edit Control to display what my Variables are holding and other information from a concurrently running Script. I have access to all of the scripts I'm attempting to connect but I'm dumbfounded on how I would separately read variable information from one running script into another. I'll provide my "Debugger" script that I want to read variables into and a "Meta Script" I'd want to pass info from.
      #Region Include Files #include <AutoItConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ColorConstantS.au3> #EndRegion #Region AutoIt Options ;Opt("TrayAutoPause", 0) ;Opt("TrayMenuMode", 3) #EndRegion #Region Hotkeys HotKeySet("{ESC}", "ExitProgram") HotKeySet("{PGDN}", "PauseProgram") HotKeySet("!1", "Snippet_1") HotKeySet("!2", "Snippet_2") HotKeySet("!3", "Snippet_3") HotKeySet("!4", "Snippet_4") HotKeySet("!5", "Snippet_5") HotKeySet("!6", "Snippet_6") HotKeySet("!7", "Snippet_7") HotKeySet("!8", "Snippet_8") HotKeySet("!9", "Snippet_9") #EndRegion #Region Global Variables #Region Globals Global $gMain, $ctrlEdit ;, $gParent #EndRegion #Region $gMain Params Dim $gMainW = @DesktopWidth / 2 Dim $gMainH = @DesktopHeight / 2 Dim $gMainX = (@DesktopWidth / 2) - ($gMainW / 2) Dim $gMainY = (@DesktopHeight / 2) - ($gMainH / 2) Dim $gMainStyle = $WS_POPUP Dim $gMainStyleEx = -1 ;Dim $gMainParent = $gParent #EndRegion #Region $ctrlEdit Params Dim $ctrlEditW = Round($gMainW * 0.98) Dim $ctrlEditH = Round($gMainH * 0.98) Dim $ctrlEditX = ($gMainW - $ctrlEditW) / 2 Dim $ctrlEditY = ($gMainH - $ctrlEditH) / 2 Dim $ctrlEditStyle = -1 Dim $ctrlEditStyleEx = -1 #EndRegion #EndRegion #Region GUI Initialization ;$gParent = GUICreate("", -1, -1, -1, -1, -1, $WS_EX_TOOLWINDOW) $gMain = GUICreate("", $gMainW, $gMainH, $gMainX, $gMainY, $gMainStyle, $gMainStyleEx) GUISetBkColor($COLOR_BLACK, $gMain) $ctrlEdit = GUICtrlCreateEdit("MainW: " & $gMainW & @CRLF & "MainH: " & $gMainH & @CRLF & "EditW: " & $ctrlEditW & @CRLF & "EditH: " & $ctrlEditH, $ctrlEditX, $ctrlEditY, $ctrlEditW, $ctrlEditH, $ctrlEditStyle, $ctrlEditStyleEx) GUISetState(@SW_SHOW, $gMain) #EndRegion MainFunction() #Region Main Function (GUI) Func MainFunction() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit EndIf WEnd EndFunc #EndRegion #Region Functions Func Functions() EndFunc #EndRegion #Region Program 1 Func Snippet_1() EndFunc #EndRegion #Region Program 2 Func Snippet_2() EndFunc #EndRegion #Region Program 3 Func Snippet_3() EndFunc #EndRegion #Region Program 4 Func Snippet_4() EndFunc #EndRegion #Region Program 5 Func Snippet_5() EndFunc #EndRegion #Region Program 6 Func Snippet_6() EndFunc #EndRegion #Region Program 7 Func Snippet_7() EndFunc #EndRegion #Region Program 8 Func Snippet_8() EndFunc #EndRegion #Region Program 9 Func Snippet_9() EndFunc #EndRegion #Region Pause/Exit Functions Func PauseProgram() While 1 Sleep(1000) WEnd EndFunc Func ExitProgram() Exit EndFunc #EndRegion Pause/Exit Functions #Region Snippets #CS #CE #EndRegion #Region Other Information #CS #CE #EndRegion That's the Debugger script. Please forgive anything ignorant but point it out if you will, I'll take any pointers to get better! (I usually use a Select to get $GUI_EVENT_CLOSE but this is early on)
      Now if I made another script with a basic GUI similar to this and wanted to read say the GUI Width ($gMainW) into the Debugger Edit Control could I do it? If so, could I do it for every variable I have in a script? I read something about the Run function and adding the variables as an option parameter I believe which I think I could do with an array to keep it from being super long and ugly but would that be the only way to do this? Any information is going to be appreciated and thank you in advance for your time!
       
      Edit: Sadly it just dawned on me that I could make a UDF that will create a child window that will do this instead of having a separate script trying to invade another... I'll still be keeping an eye on this for any comments but I apologize if I wasted your time!
    • By panlatv
      Hello everybody (and sorry for my bad english)

      I try to get the position of a contextmenu (GUICtrlCreateContextMenu) on a TreeView, with ControlGetPos, but i can't.
      Someone can help me ? Thank you :)

      PS: I need the position to select item wtih rightclick before read the text of the item, because rightclick don't select item (only leftclick).
       
    • By coronatuss
      Hello eveyone,
      I installed the latest version of Autoit (x86 - for greater compatibility) and SciTE.
      Every time I want to generate the GUI code designed in Koda, the program freezes (only Koda, not SciTE).
      Have you ever had this problem? Do you know how to fix it?
      Thanks!
×
×
  • Create New...