Jump to content
Sign in to follow this  

edit box with vertical box selection

Recommended Posts


I am trying to select a rectangle of text when the alt key is down on a AutoIt edit box, instead of doing the regular kind of selection. Of course this can only work if I use a fixed pitch font (constant character width such as Courier New)

To make it look like I am doing a box selection, I want to create and update a bitmap while the mouse button is pressed and the alt key is down, put the bitmap on top of the selected box, write the text that is covered by the bitmap to the bitmap, change the bitmap text color to white, and the background to blue, to give it the look of a selection.

But I need help to make that bitmap system work. I appreciate any help I can get.

Here is what I have so far:

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <Misc.au3>


Func Main()
    Local $bMouseDown = False
    Local $aPos[2]
    Local $arMouseStart[2] = [-1,-1]
    Local $arMouseEnd[2] = [-1,-1]
    Local $GuiID = GUICreate("test", 500, 400, 200, 200)
    Local $bmpID
    GUICtrlCreateEdit("", 5, 5, 490, 390)
    Local $msg
    while 1
        $msg = GUIGetMsg()
            case $GUI_EVENT_CLOSE
            case $GUI_EVENT_PRIMARYDOWN
                $bMouseDown = True
            case $GUI_EVENT_PRIMARYUP
                $bMouseDown = False
            case $GUI_EVENT_MOUSEMOVE
                if bAltIsDown() Then
                    if $bMouseDown Then
                        $aPos = MouseGetPos()
                        if $arMouseStart[0] = -1 And $arMouseStart[1] = -1 Then
                            $arMouseStart[0] = $aPos[0]
                            $arMouseStart[1] = $aPos[1]
                            $arMouseEnd[0] = $aPos[0]
                            $arMouseEnd[1] = $aPos[1]
                    Elseif $arMouseStart[0] > -1 And $arMouseStart[1] > -1 Then
                        $arMouseEnd[0] = $aPos[0]
                        $arMouseEnd[1] = $aPos[1]
                        $bmpID = ShowVerticalSelectionTest($arMouseStart, $arMouseEnd, $GuiID)

Func bAltIsDown()
    Local $hDLL = DllOpen("user32.dll")
    Local $bIsDown = _IsPressed("12")
    Return $bIsDown

Func ShowVerticalSelectionTest($arMouseStart, $arMouseEnd, $GuiID)
    ;Create a memory DC compatible with the current GUI and create a bitmap compatible with the Edit control's device
    Local $m_processedDC = _WinAPI_CreateCompatibleDC(Null)
    Local $bmpEdit = _WinAPI_CreateCompatibleBitmap ( $m_processedDC, $arMouseStart[0], $arMouseEnd[1])
    ;Create a solid brush with current highlight color of system and fill destination DC's background with currently created brush
    _winapi_SelectObject($m_processedDC, $bmpEdit);
    ;Create a solid brush with current highlight color of system and fill destination DC's background with currently created brush
    Local $COLOR_HIGHLIGHT = 13
    Local $clrHilite = _WinAPI_GetSysColor($COLOR_HIGHLIGHT)
    Local $brHilite = _WinAPI_CreateSolidBrush($clrHilite)
    Local $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, "Left", $arMouseStart[0])
    DllStructSetData($tRect, "Top", $arMouseStart[1])
    DllStructSetData($tRect, "Right", $arMouseEnd[0] - $arMouseStart[0])
    DllStructSetData($tRect, "Bottom", $arMouseEnd[1] - $arMouseStart[1])
    _WinAPI_FillRect($m_processedDC, $tRect, $brHilite)
    ;Create a bitmap with the specified width and height but its contents is undefined (as NULL)
    Local $hMemBmp = _WinAPI_CreateBitmap($arMouseEnd[0] - $arMouseStart[0], $arMouseEnd[1] - $arMouseStart[1], 1, 1)   ;4th parameter assigns # of bits per pixel, set to "1", so the resulted Bitmap will be a Black & White bitmap
    ;Copy RichEdit's DC to 'm_hSelectionDC'
    Local $m_hSelectionDC = _WinAPI_CreateCompatibleDC(Null)
    Local $SRCCOPY = 0xCC0020
    _WinAPI_BitBlt($m_hSelectionDC, 0, 0, $arMouseEnd[0] - $arMouseStart[0], $arMouseEnd[1] - $arMouseStart[1], $m_processedDC, 0, 0, $SRCCOPY)


Edited by rodent1

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

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.