Jump to content

Need help with _GUICtrlRichEdit_SetEventMask


qwert
 Share

Go to solution Solved by Melba23,

Recommended Posts

I'm attempting to implement an automatic process for text that's dropped into a RichEdit control.  The help file seems to describe a straightforward method.  But my simple test implementation isn't working.  The control accepts text, but I never receive the corresponding notification.

;
;       Simple Text Drag and Drop  ... attempt
;
#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

$hGui = GUICreate("Drag Drop", 400, 300, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
GUISetFont(12, 400, 0, "Arial")
$hEdit = _GUICtrlRichEdit_Create($hGui, "", 20, 30, 360, 120, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
GUICtrlSetState(-1, $GUI_DROPACCEPTED)              ; this didn't help
_GUICtrlRichEdit_SetFont($hEdit, 14, "Arial")
_GUICtrlRichEdit_SetEventMask ($hEdit, $ENM_DRAGDROPDONE)
GUICtrlCreateLabel("Drop text into above field", 24, 170, 200, 24)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            MsgBox(0, "Close", "... detected", 0, $hGui)
               _GUICtrlRichEdit_Destroy($hEdit) ; needed unless script crashes
            Exit
        Case $EN_DRAGDROPDONE
            MsgBox(0, "Edit/Change", "... detected", 0, $hGui)
    EndSwitch
    Sleep(20)
WEnd

I'll guess that I've left something out.  But I can't spot it.

Thanks in advance for any help.

 

Link to comment
Share on other sites

Your example is not complete.

Where is your 

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) 

declared ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

Short answer: sitting right there in the help file for _GUICtrlRichEdit_SetEventMask!

Longer answer:  I thought it was only needed in OnEvent mode.  Nonetheless, here's my example with WM_NOTIFY included:

;
;       Simple Text Drag and Drop  ... attempt
;
#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

$hGui = GUICreate("Drag Drop", 400, 300, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
GUISetFont(12, 400, 0, "Arial")
$hEdit = _GUICtrlRichEdit_Create($hGui, "", 20, 30, 360, 120, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
GUICtrlSetState(-1, $GUI_DROPACCEPTED)                          ; this didn't help
_GUICtrlRichEdit_SetFont($hEdit, 14, "Arial")
_GUICtrlRichEdit_SetEventMask ($hEdit, $ENM_DRAGDROPDONE)
GUICtrlCreateLabel("Drop text into above field", 24, 170, 200, 24)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            MsgBox(0, "Close", "... detected", 0, $hGui)
               _GUICtrlRichEdit_Destroy($hEdit) ; needed unless script crashes
            Exit
        Case $EN_DRAGDROPDONE
            MsgBox(0, "Edit/Change", "... detected", 0, $hGui)
    EndSwitch
    Sleep(20)
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR, $tMsgFilter, $hMenu
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hEdit
            MsgBox(0, "Notify", "... detected", 0, $hGui)
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

It has no effect.  Obviously, just including it isn't enough.  In any event, I don't understand why GUIGetMsg() doesn't receive the $EN_DRAGDROPDONE if it has occurred.  It receives the $GUI_EVENT_CLOSE just fine.  This all serves to highligh a rather significant point:

AutoIt users appear to operate in a general vacuum of understanding of WM_NOTIFY ... only that "it's needed" ... as exemplified by this thread from last year: 

It's an honest and well-researched attempt at determining an answer, but the answer isn't there.  The issue was left hanging ... with an example script that still didn't work.

Would someone who actually knows please write a paragraph on WM_NOTIFY from an AutoIt perspective?  A search of the help file brings up over 100 references and not one of them explains the function.  Yet, WM_NOTIFY occurs throughout the examples.

As a point of reference, here's msdn's offering:  "Sent by a common control to its parent window when an event has occurred or the control requires some information."  It's not the kind of explanation you can go build a script around.

Edited by qwert
Link to comment
Share on other sites

OK ... I've made a little headway ... after looking at code for hours, code that looked the same as code in examples, but that just sat there without doing anything.

 

First, I’ve found an overview of WM_NOTIFY in the AutoIt Wiki.

https://www.autoitscript.com/wiki/Tutorial_GUIRegisterMsg

But it doesn’t explain the crossover relationship between the realms of GUIGetMsg and WM_COMMAND/WM_NOTIFY, for example. I’ve read elsewhere that “WM_NOTIFY is WM_COMMAND on steriods!” But it’s difficult to appreciate that meaning without a foundation understanding.

 

And I found this nugget in the help file regarding $GUI_DROPACCEPTED and $GUI_EVENT_DROPPED

Only dragging a ListviewItem will start the drag & drop process. The @GUI_DragId will be the ListView controlID.

 

But I've yet to see anything close to “the ins and outs of drag and drop methods for GUIs—an overview”.

 

My test script now works (with WM_NOTIFY registered ... and with _GUICtrlRichEdit_SetEventMask ($hEdit, $ENM_DRAGDROPDONE))

 ... but only for dragging/dropping text within the richedit control.

 

;
;       Simple Text Drag and Drop (within RichEdit control)
;
#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

$hGui = GUICreate("Drag Drop", 400, 300, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
GUISetFont(12, 400, 0, "Arial")
$hEdit = _GUICtrlRichEdit_Create($hGui, "", 20, 30, 360, 120, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
GUICtrlSetState(-1, $GUI_DROPACCEPTED)                          ; this didn't help
_GUICtrlRichEdit_SetFont($hEdit, 14, "Arial")
_GUICtrlRichEdit_SetEventMask ($hEdit, $ENM_DRAGDROPDONE)
;_GUICtrlRichEdit_SetEventMask ($hEdit, $ENM_CHANGE)            ; << didn't help
;_GUICtrlRichEdit_SetEventMask($hEdit, BitOR($ENM_MOUSEEVENTS)  ; << didn't help
GUICtrlCreateLabel("Drop text into above field", 24, 170, 200, 24)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE                                       ; this works
            MsgBox(0, "Close", "... detected", 0, $hGui)
               _GUICtrlRichEdit_Destroy($hEdit) ; needed unless script crashes
            Exit
        Case $GUI_EVENT_SECONDARYUP                             ; this works
            MsgBox(0, "Click", "... detected", 0, $hGui)
        Case $EN_CHANGE                                         ; these didn't
            MsgBox(0, "Change", "... detected", 0, $hGui)       ;
        Case $GUI_EVENT_DROPPED                                 ;
            MsgBox(0, "Drop", "... detected", 0, $hGui)         ;
        Case $EN_DRAGDROPDONE                                   ;
            MsgBox(0, "Edit/Change", "... detected", 0, $hGui)
    EndSwitch
    Sleep(20)
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR, $tMsgFilter, $hMenu
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hEdit
            MsgBox(0, "Notify", $iCode & " ... detected", 0, $hGui)
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

.

I'm still lacking a way to know that text has been dropped in from a source outside the GUI. And when I enable mouse events ($ENM_MOUSEEVENTS), I get “1792” for the code any time the edit field is touched.  (Notifications Edit Control ... EN_ALIGN_LTR_EC = 1792

Sent when the user has changed the edit control direction to left-to-right. )

 

Any suggestions will be appreciated.

 

Link to comment
Share on other sites

  • Moderators
  • Solution

qwert,

You need to register WM_COMMAND, not WM_NOTIFY - then you get a response whenever the content is changed: :)

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

$hGui = GUICreate("Drag Drop", 400, 300, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
GUISetFont(12, 400, 0, "Arial")

$hEdit = _GUICtrlRichEdit_Create($hGui, "", 20, 30, 360, 120, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))

_GUICtrlRichEdit_SetFont($hEdit, 14, "Arial")
_GUICtrlRichEdit_SetEventMask($hEdit, $ENM_CHANGE)
GUICtrlCreateLabel("Drop text into above field", 24, 170, 200, 24)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE ;
            ConsoleWrite("Close" & @CRLF)
            _GUICtrlRichEdit_Destroy($hEdit) ;
            Exit
    EndSwitch
WEnd

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    If $lParam = $hEdit And _WinAPI_HiWord($wParam) = $EN_CHANGE Then
        ConsoleWrite("Edit content changed" & @CRLF)
    EndIf
EndFunc
I am sorry that you find the GUIRegisterMsg tutorial in the Wiki less than satisfactory. It was only ever intended as a brief overview - if you want the full explanation of how Windows messaging works, I recommend MSDN, although it is very detailed. ;)

As to the crossover between GUIGetMsg and needing to register the Windows messages directly - look at the Help file pages <GUI Reference - MessageLoop/OnEvent Mode>. You will see that GUIGetMsg and GUI/GUICtrlSetOnEvent only have a limited set of messages to which they will respond, plus the controls created by AutoIt's native functions. Anything over and above that limited set (such as looking for a change in a UDF-created control as here) requires you to intercept the relevant message yourself. To do that you need to look in MSDN (or search the forum for a suitable crib ;)) and determine which message is sent and how to intercept it - I looked on MSDN and found this page from which I devised the above code. :)

Does that make it any clearer? :huh:

M23

Edited by Melba23
Code modified - see below

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

kylomas,

Thanks - not sure how that happened as it appears in the version which I was running in SciTE. :wacko:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@Melba23,

Excellent. I can’t believe I was completely off track by something right in front of me. I recall trying it both ways, but I’ll suppose my ducks weren’t aligned (a technical term).

 

But even with your working example, it took me several tries to get the same result with mine. The difference is that I was expecting $hWndFrom = $hEdit, while you were using $iParam = $hEdit.  At this moment, I can’t fathom why that is so or where I got the idea. I’ll add it to my (long list) of “things to figure out why”. For now, it’s working and I’m glad to be unstuck.

 

The Wiki (you wrote?) is excellent at covering the topics it does. Its style is flowing and understandable ... sort of the opposite of msdn. My “disappointment” was only that it didn’t carry on and on. I always hope to find those clay tablets that will spell things out for me ... like travel guides written by someone who’s actually been there.

 

Thanks very much for helping me out with this.

 

 

 

 

Link to comment
Share on other sites

  • Moderators

qwert,

Glad I could help.

 

Its style is flowing and understandable ... sort of the opposite of msdn

Delighted you think so - although being less turgid than MSDN is not exactly hard! :D

 

“things to figure out why"

When it comes to Windows messaging it is sometimes best just accept that is the way things are - trying to understand WHY MS did things the way they did is just too much for any one brain. I suspect a lot of it has to do with backwards compatibility - we have enough problems in AutoIt with that, so heaven knows what it must be like for Windows itself! :ohmy:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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