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:
AutoIt
#include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <Misc.au3> Main() 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 = _GDIPlus_BitmapCreateFromScan0(1, 1) GUICtrlCreateEdit("", 5, 5, 490, 390) GUISetState(@SW_SHOW) Local $msg while 1 $msg = GUIGetMsg() Switch($msg) case $GUI_EVENT_CLOSE GUIDelete($GuiID) Return 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] Else $arMouseEnd[0] = $aPos[0] $arMouseEnd[1] = $aPos[1] EndIf Elseif $arMouseStart[0] > -1 And $arMouseStart[1] > -1 Then $arMouseEnd[0] = $aPos[0] $arMouseEnd[1] = $aPos[1] ShowVerticalSelection($arMouseStart, $arMouseEnd, $bmpID) EndIf EndIf EndSwitch WEnd EndFunc Func bAltIsDown() Local $hDLL = DllOpen("user32.dll") Local $bIsDown = _IsPressed("12") DllClose($hDLL) Return $bIsDown EndFunc Func ShowVerticalSelection($arMouseStart, $arMouseEnd, $bmpID) _GDIPlus_Startup() Local $Capture = _ScreenCapture_Capture("", $arMouseStart[0], $arMouseStart[1], $arMouseEnd[1], $arMouseEnd[0], False) Local $hImg = _GDIPlus_BitmapCreateFromHBITMAP($Capture) Local $hDesktop = _WinAPI_GetDesktopWindow() Local $hDC = _WinAPI_GetDC($hDesktop) Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $arMouseStart[0], $arMouseEnd[1] - $arMouseStart[1]) _WinAPI_ReleaseDC($hDesktop, $hDC) Local $hImg1 = _GDIPlus_BitmapCreateFromHBITMAP($hBmp) Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImg1) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImg, $arMouseStart[0], $arMouseStart[1], $arMouseEnd[0] - $arMouseStart[0], $arMouseEnd[1] - $arMouseStart[1]) _GDIPlus_BitmapDispose($bmpID) $bmpID = _GDIPlus_BitmapCreateFromScan0($arMouseEnd[0] - $arMouseStart[0], $arMouseEnd[1] - $arMouseStart[1]) _GDIPlus_GraphicsClear($hGraphic, 0x000FFFFF) Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($bmpID) GUISetState(@SW_SHOW) EndFunc
Thanks!