Jump to content

Disable RichEdit control and get click-through capability?


qwert
 Share

Recommended Posts

This may seem like an odd GUI behavior to attempt, but I'd like to be able to "click though" an inactive field so that the GUI behaves as if it wasn't there ... yet still displays the field's contents.

 

I have a situation where a RichEdit field is initially activated to receive input. But after an entry is made, it can be disabled to lock in its contents. Once it's disabled, I’d like it to work as a ParentDrag element for the Main GUI. So far, nothing has given that result.

 

Here’s my basic GUI structure

[Main GUI] ... $WS_POPUP, but draggable using WM_NCHITTEST

[Child GUI] ... contains a single field:

              <RichEdit> ... which can be disabled by a user action

 

Some of the things I’ve tried:

> I can disable <RichEdit> with SetReadOnly ... but the field is still active for actions like highlighting text.

> I can disable [Child GUI] with $GUI_Disable ... but that completely removes access.

> I’ve added $GUI_WS_EX_PARENTDRAG to <RichEdit> ... but there’s no difference if it’s set or not ... or whether the field is active or not.

 

Would anyone have a suggestion of how to go about obtaining the drag capability?

 

Thanks in advance for any help.

 

 

 

Link to comment
Share on other sites

Here is my attempt. Try it out by clicking the options icon (wrench) in the top right corner of the gui and then click and drag on the rich edit control.

#Region ### includes ###
#include-once
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GuiRichEdit.au3>
#include <Misc.au3>
#EndRegion ### includes ###

Global $topLabel, $hButtonX, $hMinimize, $maingui, $iHeight, $iWidth, $iHeight = 700, $iWidth = 850, $appver = '1.0', $appname = 'TestApp', $dTitleBarColor = 0xD8DDE8, _
       $optionsgui, $optionsgui_W = 450, $optionsgui_H = 185, $hButtonX_optionsgui, $h_RichEdit

#Region ### $maingui ###
$maingui = GUICreate($appname & ' ' & $appver, $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2, BitOR($WS_POPUP, $WS_BORDER))
GUISetBkColor(0xFFFFFF, $maingui)

GUICtrlCreateLabel(' ' & $appname & ' ' & $appver, 0, 0, $iWidth - 69, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 11, 500, Default, "Arial")
GUICtrlSetBkColor(-1, $dTitleBarColor)

$hButtonX = GUICtrlCreateLabel(" X", $iWidth - 22, 0, 22, 21, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 12, 800, -1)
GUICtrlSetBkColor(-1, $dTitleBarColor)
GUICtrlSetTip(-1, "Close")

$hMinimize = GUICtrlCreateLabel("__", $iWidth - 43, 0, 21, 21, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 8, 600, 4, "Comic Sans MS")
GUICtrlSetBkColor(-1, $dTitleBarColor)
GUICtrlSetTip(-1, "Minimize")

$hConfig = GUICtrlCreateLabel('@', $iWidth - 69, 0, 26, 21, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 14, 400, 0, "Webdings")
GUICtrlSetBkColor(-1, $dTitleBarColor)

$topLabel = GUICtrlCreateLabel('Welcome to ' & $appname, 10, 45, $iWidth - 350, 21)
GUICtrlSetFont(-1, 11, 400, -1)

$mainguicover = GUICreate('', $iWidth + 1, $iHeight + 1, 0, 0, $WS_POPUP, Default, $maingui)
GUISetBkColor(0x000000, $mainguicover)
GUISetState(@SW_DISABLE, $mainguicover)
WinSetTrans($mainguicover,"",100)

GUISetState(@SW_SHOW, $maingui)
#EndRegion ### $maingui ###

#Region ### $optionsgui ###
$optionsgui = GUICreate('', $optionsgui_W, $optionsgui_H, 0, 0, BitOR($WS_POPUP, $WS_BORDER), Default, $maingui)
GUISetBkColor(0xFFFFFF, $optionsgui)

GUICtrlCreateLabel(' ' & $appname & ' ' & $appver & ' -  Options', 0, 0, $optionsgui_W - 22, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 11, 500, Default, "Arial")
GUICtrlSetBkColor(-1, $dTitleBarColor)

$hButtonX_optionsgui = GUICtrlCreateLabel(" X", $optionsgui_W - 22, 0, 22, 21, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 12, 600, -1)
GUICtrlSetBkColor(-1, $dTitleBarColor)
GUICtrlSetTip(-1, "Close")

$h_RichEdit = _GUICtrlRichEdit_Create($optionsgui, '', 10, 40, 250, 100)

$wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")
$wProcOld = _WinAPI_SetWindowLong($h_RichEdit, $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
#EndRegion ### $optionsgui ###

Func ShowOptionsGUI()
    $aPos = WinGetPos($maingui)
    WinMove($optionsgui, '', $aPos[0] + (($aPos[2]/2) - ($optionsgui_W/2)), $aPos[1] + (($aPos[3]/2) - ($optionsgui_H/2)))
    WinMove($mainguicover, '', $aPos[0], $aPos[1])
    GUISetState(@SW_DISABLE, $maingui)
    GUISetState(@SW_SHOW, $mainguicover)
    GUISetState(@SW_SHOW, $optionsgui)
EndFunc

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $maingui
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE, $hButtonX
                    GUIDelete($maingui)
                    Exit
                Case $hMinimize
                    GUISetState(@SW_MINIMIZE, $maingui)
                Case $hConfig
                    ShowOptionsGUI()
            EndSwitch
        Case $optionsgui
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE, $hButtonX_optionsgui
                    GUISetState(@SW_ENABLE, $maingui)
                    GUISetState(@SW_HIDE, $mainguicover)
                    GUISetState(@SW_HIDE, $optionsgui)
            EndSwitch
    EndSwitch
WEnd

Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
    Switch $hWnd
        Case $h_RichEdit
            Switch $Msg
                Case $WM_LBUTTONDOWN
                    $mp = MouseGetPos()
                    $gp = WinGetPos($optionsgui)
                    While _IsPressed(1)
                        $nm = MouseGetPos()
                        WinMove($optionsgui, '', $gp[0] - $mp[0] + $nm[0], $gp[1] - $mp[1] + $nm[1])
                    WEnd
                    Return 0
            EndSwitch
    EndSwitch

    Local $aRet = DllCall("user32.dll", "int", "CallWindowProc", "ptr", $wProcOld, _
            "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)

    Return $aRet[0]
EndFunc   ;==>_WindowProc

Sources are a combination of: ('?do=embed' frameborder='0' data-embedContent>>) and (), the gui is my own derived from ()

Of course the WinMove section can be modified to move the main parent GUI instead of the child as you see fit. For example, this will move the parent gui and the child together:

Case $WM_LBUTTONDOWN
                    $mp = MouseGetPos()
                    $op = WinGetPos($optionsgui)
                    $gp = WinGetPos($maingui)
                    $cp = WinGetPos($mainguicover)
                    While _IsPressed(1)
                        $nm = MouseGetPos()
                        WinMove($maingui, '', $gp[0] - $mp[0] + $nm[0], $gp[1] - $mp[1] + $nm[1])
                        WinMove($mainguicover, '', $cp[0] - $mp[0] + $nm[0], $cp[1] - $mp[1] + $nm[1])
                        WinMove($optionsgui, '', $op[0] - $mp[0] + $nm[0], $op[1] - $mp[1] + $nm[1])
                    WEnd
                    Return 0
Edited by mpower
Link to comment
Share on other sites

Thanks, mpower.

Case $WM_LBUTTONDOWN is an approach I hadn't thought of.

But where, exactly, does your alternate section drop in?  I got an error when I put it in the switch for Case $optionsgui.

 

 

No worries, you would replace it in the _WindowProc function, e.g. below:

Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
    Switch $hWnd
        Case $h_RichEdit
            Switch $Msg
                Case $WM_LBUTTONDOWN
                    $mp = MouseGetPos()
                    $op = WinGetPos($optionsgui)
                    $gp = WinGetPos($maingui)
                    $cp = WinGetPos($mainguicover)
                    While _IsPressed(1)
                        $nm = MouseGetPos()
                        WinMove($maingui, '', $gp[0] - $mp[0] + $nm[0], $gp[1] - $mp[1] + $nm[1])
                        WinMove($mainguicover, '', $cp[0] - $mp[0] + $nm[0], $cp[1] - $mp[1] + $nm[1])
                        WinMove($optionsgui, '', $op[0] - $mp[0] + $nm[0], $op[1] - $mp[1] + $nm[1])
                    WEnd
                    Return 0
            EndSwitch
    EndSwitch

    Local $aRet = DllCall("user32.dll", "int", "CallWindowProc", "ptr", $wProcOld, _
            "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)

    Return $aRet[0]
EndFunc   ;==>_WindowProc
Link to comment
Share on other sites

Thanks for that.

It's certainly an interesting effect.  As is, I takes away the capability to directly click to a specific point in the rich text field.  However, for my use I'll be able to enable/disable the move logic with my lock/unlock state.

Good example!

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