1stPK Posted November 4 Share Posted November 4 (edited) my code is mainly for every time user clicks on input box it will automatically black out all the content in it. The "Reset" button is just a button to reset the content in the box back to its original state so I can try clicking on the input box again. please help. Thanks #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> ; Khởi tạo GUI GUICreate("Demo Input", 300, 100) Local $inputBox = GUICtrlCreateInput("Nhập văn bản ở đây", 50, 30, 200, 20) Local $resetButton = GUICtrlCreateButton("Reset", 110, 60, 80, 25) ; Đăng ký sự kiện cho ô nhập liệu GUIRegisterMsg($WM_LBUTTONDOWN, "OnLButtonDown") ; Hiển thị GUI GUISetState(@SW_SHOW) ; Vòng lặp chính While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $resetButton ; Khi nhấn nút Reset, đặt lại nội dung trong ô nhập liệu GUICtrlSetData($inputBox, "Nhập văn bản ở đây") EndSwitch WEnd GUIDelete() ; Hàm xử lý sự kiện nhấp chuột trái Func OnLButtonDown($hWnd, $Msg, $wParam, $lParam) ; Kiểm tra nếu ô nhập liệu được nhấp vào If GUIGetCursorInfo($inputBox) = 1 Then GUICtrlSetState($inputBox, $GUI_FOCUS) GUICtrlSendMsg($inputBox, $EM_SETSEL, 0, -1) EndIf EndFunc Edited November 4 by 1stPK Link to comment Share on other sites More sharing options...
Dan_555 Posted November 4 Share Posted November 4 (edited) Sorry, what help do you need ? (p.s. the code posted is not runable, it is missing an #include <GuiEdit.au3> ) if you need a predefined text in the input box, which disappears when you want to type something then it is the _GUICtrlEdit_SetCueBanner($inputBox,"Predefined text") expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <GuiEdit.au3> ; Kh?i t?o GUI GUICreate("Demo Input", 300, 100) Global $inputBox = GUICtrlCreateInput("", 50, 30, 200, 20) Local $resetButton = GUICtrlCreateButton("Reset", 110, 60, 80, 25) ; Ðang ký s? ki?n cho ô nh?p li?u GUIRegisterMsg($WM_LBUTTONDOWN, "OnLButtonDown") ; Hi?n th? GUI GUISetState(@SW_SHOW) _GUICtrlEdit_SetCueBanner($inputBox,"Predefined text") GUICtrlSetState($resetButton, $GUI_FOCUS) ; Vòng l?p chính While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $resetButton ; When the Reset button is pressed, reset the content in the input box GUICtrlSetData ( $inputBox , "" ) EndSwitch WEnd GUIDelete() ; Hàm x? lý s? ki?n nh?p chu?t trái Func OnLButtonDown($hWnd, $Msg, $wParam, $lParam) ; Ki?m tra n?u ô nh?p li?u du?c nh?p vào If GUIGetCursorInfo($inputBox) = 1 Then GUICtrlSetState($inputBox, $GUI_FOCUS) GUICtrlSendMsg($inputBox, $EM_SETSEL, 0, -1) EndIf EndFunc Edited November 4 by Dan_555 1stPK 1 Some of my script sourcecode Link to comment Share on other sites More sharing options...
1stPK Posted November 4 Author Share Posted November 4 3 hours ago, Dan_555 said: Sorry, what help do you need ? (p.s. the code posted is not runable, it is missing an #include <GuiEdit.au3> ) if you need a predefined text in the input box, which disappears when you want to type something then it is the _GUICtrlEdit_SetCueBanner($inputBox,"Predefined text") expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <GuiEdit.au3> ; Kh?i t?o GUI GUICreate("Demo Input", 300, 100) Global $inputBox = GUICtrlCreateInput("", 50, 30, 200, 20) Local $resetButton = GUICtrlCreateButton("Reset", 110, 60, 80, 25) ; Ðang ký s? ki?n cho ô nh?p li?u GUIRegisterMsg($WM_LBUTTONDOWN, "OnLButtonDown") ; Hi?n th? GUI GUISetState(@SW_SHOW) _GUICtrlEdit_SetCueBanner($inputBox,"Predefined text") GUICtrlSetState($resetButton, $GUI_FOCUS) ; Vòng l?p chính While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $resetButton ; When the Reset button is pressed, reset the content in the input box GUICtrlSetData ( $inputBox , "" ) EndSwitch WEnd GUIDelete() ; Hàm x? lý s? ki?n nh?p chu?t trái Func OnLButtonDown($hWnd, $Msg, $wParam, $lParam) ; Ki?m tra n?u ô nh?p li?u du?c nh?p vào If GUIGetCursorInfo($inputBox) = 1 Then GUICtrlSetState($inputBox, $GUI_FOCUS) GUICtrlSendMsg($inputBox, $EM_SETSEL, 0, -1) EndIf EndFunc I mean when we click on the input box, all the content in that box will be colored black. And when we click anywhere on the GUI, the input box content will return to its original state. Thank you! Link to comment Share on other sites More sharing options...
Nine Posted November 4 Share Posted November 4 3 hours ago, 1stPK said: all the content in that box will be colored black I don't understand what you mean. What is your intent with this ? Background becomes black ? Foreground becomes black ? 1stPK 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
1stPK Posted November 5 Author Share Posted November 5 5 hours ago, Nine said: I don't understand what you mean. What is your intent with this ? Background becomes black ? Foreground becomes black ? simple example for you to understand. in the input box there is a line of text (test text). And I want, every time I click on it. it will automatically scan the entire line of text in black like the picture i attached to the post Link to comment Share on other sites More sharing options...
MojoeB Posted November 5 Share Posted November 5 Do you mean that all the text in the input field is selected (focused) when you click on it, so that it is highlighted in black/blue on your image? 1stPK 1 Link to comment Share on other sites More sharing options...
Dan_555 Posted November 5 Share Posted November 5 (edited) Is this what you want ? expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <GuiEdit.au3> ; Kh?i t?o GUI $Hgui=GUICreate("Demo Input", 300, 100) Global $inputBox = GUICtrlCreateInput("", 50, 30, 200, 20) Local $resetButton = GUICtrlCreateButton("Reset", 110, 60, 80, 25) GUICtrlCreateButton("abc",2,60,60,20) ; Ðang ký s? ki?n cho ô nh?p li?u GUIRegisterMsg($WM_LBUTTONDOWN, "OnLButtonDown") ; Hi?n th? GUI GUISetState(@SW_SHOW) _GUICtrlEdit_SetCueBanner($inputBox,"Predefined text") GUICtrlSetState($resetButton, $GUI_FOCUS) Global $confocus=0,$confocusold=-2 ; Vòng l?p chính While 1 $confocus=ControlGetFocus($Hgui) if $confocus<>$confocusold Then $confocusold=$confocus if $confocus<>$inputBox then _GUICtrlEdit_SetSel($inputBox,0,-1) EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $resetButton ; When the Reset button is pressed, reset the content in the input box GUICtrlSetData ( $inputBox , "" ) EndSwitch WEnd GUIDelete() ; Hàm x? lý s? ki?n nh?p chu?t trái Func OnLButtonDown($hWnd, $Msg, $wParam, $lParam) ; Ki?m tra n?u ô nh?p li?u du?c nh?p vào If GUIGetCursorInfo($inputBox) = 1 Then GUICtrlSetState($inputBox, $GUI_FOCUS) GUICtrlSendMsg($inputBox, $EM_SETSEL, 0, -1) EndIf EndFunc Edited November 5 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
1stPK Posted November 5 Author Share Posted November 5 (edited) 6 hours ago, MojoeB said: Do you mean that all the text in the input field is selected (focused) when you click on it, so that it is highlighted in black/blue on your image? yes sir. it's like when we want to copy a text on a web page. but only when we click on it. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("Demo Input Selection on Click", 300, 200) ; Create input field $input = GUICtrlCreateInput("left click here", 50, 50, 200, 20) $input1 = GUICtrlCreateInput("left click here", 50, 100, 200, 20) ; Register the WM_LBUTTONDOWN event to handle left clicks GUIRegisterMsg($WM_LBUTTONDOWN, "_OnLeftClick") GUISetState(@SW_SHOW) Global $bFirstClick = True ; Change flag to control only select on first click While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ; Left click event handler function Func _OnLeftClick($hWnd, $iMsg, $wParam, $lParam) Local $ctrlID = GUIGetCursorInfo()[4] ; Check if click on input box If $ctrlID = $input And $bFirstClick Then ; Select all text in the input box GUICtrlSendMsg($input, 0x00B1, 0, -1) ; EM_SETSEL to select all text $bFirstClick = False ; Set a flag to prevent re-selecting on next click EndIf EndFunc Edited November 5 by 1stPK Link to comment Share on other sites More sharing options...
MojoeB Posted November 5 Share Posted November 5 (edited) expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> GUICreate("Demo Input Selection on Click", 300, 200) ; Create input fields $input1 = GUICtrlCreateInput("left click here", 50, 50, 200, 20) $input2 = GUICtrlCreateInput("left click here", 50, 100, 200, 20) ; Get handles for the input controls $hInput1 = GUICtrlGetHandle($input1) $hInput2 = GUICtrlGetHandle($input2) ; Register the WM_COMMAND message to handle control notifications GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUISetState(@SW_SHOW) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ; Function to handle WM_COMMAND messages Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) Local $hCtrl = $lParam Switch $hCtrl Case $hInput1, $hInput2 Switch $nNotifyCode Case $EN_SETFOCUS ; Select all text in the inputbox1 _GUICtrlEdit_SetSel($hCtrl, 0, -1) Case $input2;$EN_KILLFOCUS ; Unselect text in the inputbox1 _GUICtrlEdit_SetSel($hCtrl, 0, -1) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc this? forget it i tested it there it worked and the 2nd time i tested it it didn't work anymore o.o Edited November 5 by MojoeB Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now