Jump to content

[Solved] Need help with context cursor for RichEdits


Recommended Posts

A few days ago, I set out to build a GUI with multiple RichEdit controls that have different context menus.  But the way the I've implemented the menus causes the cursor to disappear over the controls.  What I would like is to retain the vertical I-bar cursor that appears in normal RichEdit controls (... and not just have the tiny character position cursor, as this example currently has).

I'll admit that when I gathered the pieces for this example script, I wasn't at all sure of whether it was a proper way to define different context menus.  But the menus do work ... even though the cursor disappears.  There's also the issue of the magic number in the code segment I picked.  What does 516 represent?

Thanks in advance for any suggestions.

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

$in = _WinAPI_GetModuleHandle(0)
$cur = _WinAPI_LoadCursor($in, 100)
OnAutoItExitRegister("_Quit")

$Form = GUICreate("Rich Edit Panel", 411, 371, 275, 160)
GUISetFont(16)
$Edit1 = _GUICtrlRichEdit_Create($Form, "First RichEdit Control", 0, 20, 201, 200) ; , BitOR($WS_HSCROLL, $ES_AUTOVSCROLL, $ES_MULTILINE, $WS_VSCROLL))
$Edit2 = _GUICtrlRichEdit_Create($Form, "Second RichEdit Control", 208, 20, 201, 200) ; , BitOR($WS_HSCROLL, $ES_AUTOVSCROLL, $ES_MULTILINE, $WS_VSCROLL))

$menu1 = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
$hmenu1 = GUICtrlGetHandle(-1)
$copymenu1 = GUICtrlCreateMenuItem("Menu Option for Left", $menu1)

$menu2 = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
$hmenu2 = GUICtrlGetHandle(-1)
$copymenu2 = GUICtrlCreateMenuItem("Menu Option for Right", $menu2)

GUIRegisterMsg($wm_setcursor, "cursor")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $copymenu1
            MsgBox(0,'Left-side Option',"YES!!!")
        Case $copymenu2
            MsgBox(0,'Right-side Option',"YES!!!")
    EndSwitch
WEnd

Func cursor($win, $msg, $wparam, $lparam)
Local $s = BitShift($lParam, 16)
    Switch $wparam
        Case $Edit1
            If $s = 516 Then            ; what does 516 represent?
                $pos = MouseGetPos()
                _GUICtrlMenu_TrackPopupMenu($hmenu1, $Form, $pos[0], $pos[1], 1)
                _WinAPI_SetCursor($cur)
                Return 1
            Else
                _WinAPI_SetCursor($cur)
                Return 1
            EndIf
        Case $Edit2
            If $s = 516 Then
                $pos = MouseGetPos()
                _GUICtrlMenu_TrackPopupMenu($hmenu2, $Form, $pos[0], $pos[1], 1)
                _WinAPI_SetCursor($cur)
                Return 1
            Else
                _WinAPI_SetCursor($cur)
                Return 1
            EndIf
    EndSwitch
EndFunc

Func _Quit()
    _GUICtrlRichEdit_Destroy($Edit1)
    _GUICtrlRichEdit_Destroy($Edit2)
EndFunc

 

Edited by qwert
Link to comment
Share on other sites

516 = 0x204 =  $WM_RBUTTONDOWN ( that is in #include <WindowsConstants.au3>)

And try this:-

If $s = 516 Then ; Right mouse button down
                ;$pos = MouseGetPos()
                _GUICtrlMenu_TrackPopupMenu($hmenu2, $Form);, $pos[0], $pos[1], 1)
                ;_WinAPI_SetCursor($cur)
                Return 1
            Else
                ;_WinAPI_SetCursor($cur)
                Return $GUI_RUNDEFMSG ; <- see cursor
            EndIf
    EndSwitch

 

Link to comment
Share on other sites

Malkey, thanks very much for your response.  (And please pardon my pause in getting back to this.  Priorities!)

It does seem clear—now!—that the SetCursor statements were affecting the "natural order" of cursor processing.

The two menus now work like I expected they should.

I appreciate your help with this.

 

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