Jump to content
Sign in to follow this  
khongthethichnghi9896

Hướng dẫn thêm chức năng Select All (Ctrl+A) EditBox GUI AutoIt

Recommended Posts

Mặc định Control Edit của GUI AutoIt không có chức năng Select All (Ctrl + A) nên ta phải thêm code vào.

1. Code khi chế độ GUI là GUIGetMsg()

$GUI = GUICreate("Ctrl + A để select all text trong Edit", 310, 210)
$Edit1 = GUICtrlCreateEdit("test1", 2, 2, 300, 100)
$Edit2 = GUICtrlCreateEdit("test2", 2, 104, 300, 100)
GUISetState(@SW_SHOWNOACTIVATE)

#Region <Thêm 3 dòng code này>
  $Ctrl_A = GUICtrlCreateDummy()
  Local $DefButton[1][2] = [["^a", $Ctrl_A]]
  GUISetAccelerators($DefButton)
#EndRegion

While Sleep(40)
	Switch GUIGetMsg()
 		#region <Thêm 2 dòng code này>
		Case $Ctrl_A
			GUICtrlSendMsg(DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", ControlGetHandle("", "", "[CLASSNN:" & ControlGetFocus("") & "]"))[0], 0xB1, 0, -1)
		#EndRegion
		Case -3
			Exit
	EndSwitch
WEnd

 

2. Code khi chế độ GUI là SetOnEvent:

Opt("GUIOnEventMode", 1)

$GUI = GUICreate("Ctrl + A để select all text trong Edit", 310, 210)
GUISetOnEvent(-3, "_Exit")
$Edit1 = GUICtrlCreateEdit("test1", 2, 2, 300, 100)
$Edit2 = GUICtrlCreateEdit("test2", 2, 104, 300, 100)
GUISetState(@SW_SHOWNOACTIVATE)

#Region <Thêm 3 dòng code này>
  $Ctrl_A = GUICtrlCreateDummy()
  GUICtrlSetOnEvent($Ctrl_A, "_SelectAll")
  Local $DefButton[1][2] = [["^a", $Ctrl_A]]
  GUISetAccelerators($DefButton)
#EndRegion

While Sleep(30)
WEnd

Func _SelectAll()
	GUICtrlSendMsg(DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", ControlGetHandle("", "", "[CLASSNN:" & ControlGetFocus("") & "]"))[0], 0xB1, 0, -1)
EndFunc

Func _Exit()
	Exit
EndFunc

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...