SkellySoul Posted August 13, 2012 Share Posted August 13, 2012 Hello It has been quite awhile since I posted but thought I would share an interesting script that I am using in one of my projects. This script allows a user to quickly edit a label control and and relock it. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $Data, $Label GUICreate("Example", 500, 500) $Data = GUICtrlCreateEdit("Write something in here and hit lock.", 0, 0, 500, 480) $State = GUICtrlCreateButton("Lock", 0, 480, 500, 20) GUISetState(@SW_SHOW) $Set = 0 While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $State If $Set = 0 Then $Label = GUICtrlCreateLabel(GUICtrlRead($Data), 0, 0, 500, 480) GUICtrlSetState($Label, $GUI_HIDE) GUICtrlDelete($Data) GUICtrlSetState($Label, $GUI_SHOW) GUICtrlSetData($State, "Unlock") $Set = 1 ElseIf $Set = 1 Then $Data = GUICtrlCreateEdit(GUICtrlRead($Label), 0, 0, 500, 480) GUICtrlSetState($Data, $GUI_HIDE) GUICtrlDelete($Label) GUICtrlSetState($Data, $GUI_SHOW) GUICtrlSetData($State, "Lock") $Set = 0 Else ; _Error() Exit EndIf EndSwitch WEnd JScript 1 Link to comment Share on other sites More sharing options...
czardas Posted August 13, 2012 Share Posted August 13, 2012 I like the concept. I was also thinking it might be an idea to make the label clickable - just a thought! operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
SkellySoul Posted August 13, 2012 Author Share Posted August 13, 2012 (edited) I like the concept. I was also thinking it might be an idea to make the label clickable - just a thought!That is actually a good idea, but would need a way of making the client aware of that. Edited August 13, 2012 by SkellySoul Link to comment Share on other sites More sharing options...
czardas Posted August 13, 2012 Share Posted August 13, 2012 Tooltips maybe? ==> "Click to edit" operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
JScript Posted August 13, 2012 Share Posted August 13, 2012 (edited) My version: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> _Example() Func _Example() Local $iMsg, $iPseudoLabel, $iBtn_State, $iFlag = 0 GUICreate("Edit as Label example.", 320, 240) $iPseudoLabel = GUICtrlCreateEdit("Write something in here and hit lock.", 10, 100, 300, 20, $ES_MULTILINE, $WS_EX_STATICEDGE) $State = GUICtrlCreateButton("Lock", 110, 200, 100, 25) GUISetState(@SW_SHOW) While 1 $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE Exit Case $iMsg = $State And $iFlag GUICtrlSetStyle($iPseudoLabel, $ES_MULTILINE, $WS_EX_STATICEDGE) GUICtrlSetState($iPseudoLabel, $GUI_FOCUS) GUICtrlSetCursor($iPseudoLabel, 5) GUICtrlSetData($State, "Lock") $iFlag = 0 Case $iMsg = $State And Not $iFlag GUICtrlSetStyle($iPseudoLabel, $ES_READONLY, $WS_EX_TRANSPARENT) GUICtrlSetCursor($iPseudoLabel, 2) GUICtrlSetData($State, "Unlock") $iFlag = 1 EndSelect WEnd EndFunc ;==>_Example Regards, João Carlos. Edited August 13, 2012 by JScript SkellySoul 1 http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
MrCreatoR Posted August 13, 2012 Share Posted August 13, 2012 (edited) I thought it would be something like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <WinAPI.au3> $hGUI = GUICreate("Example", 500, 500) $iLabel = GUICtrlCreateLabel("Some data, right click to show the menu.", 20, 20, 460, 40) $iMenu = GUICtrlCreateContextMenu($iLabel) $iRename_MItem = GUICtrlCreateMenuItem("Rename", $iMenu) GUISetState(@SW_SHOW) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $iRename_MItem GUICtrlSetState($iLabel, $GUI_HIDE) $aCtrlPos = ControlGetPos($hGUI, '', $iLabel) $iEdit = GUICtrlCreateEdit(GUICtrlRead($iLabel), $aCtrlPos[0], $aCtrlPos[1], $aCtrlPos[2]+5, $aCtrlPos[3]+5, BitOR($ES_WANTRETURN, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL)) $hEdit = GUICtrlGetHandle($iEdit) While 1 Sleep(10) $tPoint = _WinAPI_GetMousePos() If _WinAPI_WindowFromPoint($tPoint) <> $hEdit And (_IsPressed('01') Or _IsPressed('1B')) Then ExitLoop EndIf WEnd GUICtrlSetData($iLabel, GUICtrlRead($iEdit)) GUICtrlDelete($iEdit) GUICtrlSetState($iLabel, $GUI_SHOW) EndSwitch WEnd Edited August 13, 2012 by MrCreatoR GerrOrneq and SkellySoul 2 Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
JScript Posted August 13, 2012 Share Posted August 13, 2012 Very nice. Much better, no doubt! Regards, João Carlos. http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
SkellySoul Posted August 13, 2012 Author Share Posted August 13, 2012 They were both very nice and thanks for sharing. Link to comment Share on other sites More sharing options...
JScript Posted August 13, 2012 Share Posted August 13, 2012 (edited) In the UDF format to make life easier for noobs ... expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <WinAPI.au3> $hGUI = GUICreate("Example", 500, 500) $iLabel = GUICtrlCreateLabel("Some data, right click to show the menu.", 20, 20, 460, 40) $iMenu = GUICtrlCreateContextMenu($iLabel) $iRename_MItem = GUICtrlCreateMenuItem("Rename", $iMenu) GUISetState(@SW_SHOW) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $iRename_MItem _GUICtrlLabel_Edit($iLabel) EndSwitch WEnd ; @MrCreatoR Func _GUICtrlLabel_Edit($iCtrlID) Local $hCtrlID, $aCtrlPos, $hWndForm, $iEditID, $hEditID, $tPoint $hCtrlID = GUICtrlGetHandle($iCtrlID) If Not $iCtrlID Then Return SetError(0, 0, 0) $hWndForm = _WinAPI_GetParent($hCtrlID) If Not $iCtrlID Then Return SetError(0, 0, 0) GUICtrlSetState($iCtrlID, $GUI_HIDE) $aCtrlPos = ControlGetPos($hWndForm, '', $iCtrlID) If @error Then Return SetError(0, 0, 0) $iEditID = GUICtrlCreateEdit(GUICtrlRead($iCtrlID), $aCtrlPos[0], $aCtrlPos[1], $aCtrlPos[2] + 5, $aCtrlPos[3] + 5, _ BitOR($ES_WANTRETURN, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL)) $hEditID = GUICtrlGetHandle($iEditID) While 1 Sleep(10) $tPoint = _WinAPI_GetMousePos() If _WinAPI_WindowFromPoint($tPoint) <> $hEditID And (_IsPressed('01') Or _IsPressed('1B')) Then ExitLoop EndIf WEnd GUICtrlSetData($iCtrlID, GUICtrlRead($iEditID)) GUICtrlDelete($iEditID) GUICtrlSetState($iCtrlID, $GUI_SHOW) EndFunc ;==>_GUICtrlLabel_Edit Regards, João Carlos. Edited August 13, 2012 by JScript SkellySoul 1 http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
SkellySoul Posted August 13, 2012 Author Share Posted August 13, 2012 Replacing $iRename_MItem with $iLabel also works great. Link to comment Share on other sites More sharing options...
UEZ Posted August 13, 2012 Share Posted August 13, 2012 (edited) Here another approach: expandcollapse popup#include <WindowsConstants.au3> #include <Constants.au3> #include <EditConstants.au3> #include <WinAPI.au3> #include <GUIConstantsEx.au3> Global $Data, $Label, $sData, $iExStyle, $iStyle, $hGUI, $hData, $State, $Set $hGUI = GUICreate("Example", 500, 500) $Data = GUICtrlCreateEdit("Write something in here and hit lock.", 0, 0, 500, 480) $hData = GUICtrlGetHandle($Data) $State = GUICtrlCreateButton("Lock", 0, 480, 500, 20) GUISetState(@SW_SHOW) $iStyle = _WinAPI_GetWindowLong($hData, $GWL_STYLE ) $iExStyle = _WinAPI_GetWindowLong($hData, $GWL_EXSTYLE) $Set = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $State If $Set = 0 Then _WinAPI_SetWindowLong($hData, $GWL_STYLE , BitXOR($iStyle, 0x3118C0)) ;this is unfortunately not working properly thus the GUIRegisterMsg() below GUICtrlSetData($State, "Unlock") _WinAPI_RedrawWindow($hGUI) $sData = GUICtrlRead($Data) GUIRegisterMsg($WM_COMMAND, '_WM_COMMAND') $Set = 1 ElseIf $Set = 1 Then _WinAPI_SetWindowLong($hData, $GWL_STYLE , $iStyle) GUICtrlSetData($State, "Lock") _WinAPI_RedrawWindow($hGUI) GUIRegisterMsg($WM_COMMAND, '') $Set = 0 Else ; _Error() Exit EndIf EndSwitch WEnd Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Switch BitAND($wParam, 0x0000FFFF) Case $Data GUICtrlSetData($Data, $sData) EndSwitch Return "GUI_RUNDEFMSG" EndFunc Or even easier: #include <WindowsConstants.au3> #include <Constants.au3> #include <EditConstants.au3> #include <WinAPI.au3> #include <GUIConstantsEx.au3> Global $Data, $Label, $hGUI, $hData, $State, $Set $hGUI = GUICreate("Example", 500, 500) $Data = GUICtrlCreateEdit("Write something in here and hit lock.", 0, 0, 500, 480) $State = GUICtrlCreateButton("Lock", 0, 480, 500, 20) GUISetState(@SW_SHOW) $Set = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $State If $Set = 0 Then GUICtrlSetState($Data, $GUI_DISABLE) GUICtrlSetData($State, "Unlock") $Set = 1 ElseIf $Set = 1 Then GUICtrlSetState($Data, $GUI_ENABLE) GUICtrlSetData($State, "Lock") $Set = 0 Else ; _Error() Exit EndIf EndSwitch WEnd Br, UEZ Edited August 13, 2012 by UEZ SkellySoul 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
SkellySoul Posted August 13, 2012 Author Share Posted August 13, 2012 I honestly didn't expect so many people to reply to this thread or be interested. I really enjoyed seeing everyone else's take on the idea and will be sure to use them. Link to comment Share on other sites More sharing options...
JScript Posted August 13, 2012 Share Posted August 13, 2012 @UEZ The first example is too complex for so little, but the second is great! Regards, João Carlos. http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
MrCreatoR Posted August 14, 2012 Share Posted August 14, 2012 (edited) this is unfortunately not working properly thus the GUIRegisterMsg() below What wrong with GUICtrlSetStyle($Data, BitOR($iStyle, $ES_READONLY))? #include <GUIConstantsEx.au3> #include <EditConstants.au3> $hGUI = GUICreate("Example", 500, 500) $iData = GUICtrlCreateEdit("Write something in here and hit lock.", 0, 0, 500, 480) $iState = GUICtrlCreateButton("Lock", 0, 480, 500, 20) GUISetState(@SW_SHOW) $iSet = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $iState Local $aData[2][2] = [[$ES_READONLY, 0], ["Unlock", "Lock"]] GUICtrlSetStyle($iData, BitOR($GUI_SS_DEFAULT_EDIT, $aData[0][$iSet])) GUICtrlSetData($iState, $aData[1][$iSet]) $iSet = Number(Not $iSet) EndSwitch WEnd Edited August 14, 2012 by MrCreatoR SkellySoul 1 Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
UEZ Posted August 14, 2012 Share Posted August 14, 2012 (edited) Thanks MrCreatoR, I searched for something like GUICtrlSetStyle() but found first _WinAPI_SetWindowLong()... Here the code with GUICtrlSetStyle(): expandcollapse popup#include <Constants.au3> #include <EditConstants.au3> #include <WinAPI.au3> #include <GUIConstantsEx.au3> Global $Data, $Label, $sData, $iExStyle, $iStyle, $hGUI, $hData, $State, $Set $hGUI = GUICreate("Example", 500, 500) $Data = GUICtrlCreateEdit("Write something in here and hit lock.", 0, 0, 500, 480) $hData = GUICtrlGetHandle($Data) $State = GUICtrlCreateButton("Lock", 0, 480, 500, 20) GUISetState(@SW_SHOW) $iStyle = _WinAPI_GetWindowLong($hData, $GWL_STYLE ) $iExStyle = _WinAPI_GetWindowLong($hData, $GWL_EXSTYLE) $Set = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $State If $Set = 0 Then GUICtrlSetStyle($Data, $iStyle + $ES_READONLY) GUICtrlSetData($State, "Unlock") $sData = GUICtrlRead($Data) $Set = 1 ElseIf $Set = 1 Then GUICtrlSetStyle($Data, $iStyle) GUICtrlSetData($State, "Lock") $Set = 0 Else ; _Error() Exit EndIf EndSwitch WEnd Br, UEZ Edited August 14, 2012 by UEZ SkellySoul 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
GerrOrneq Posted August 14, 2012 Share Posted August 14, 2012 (edited) @skellysoulThank you for raising this subject it's been interesting and informative seeing everyones approach to the task.@MrCreatoRMy favourite was your solution, in fact I think it is so good that it should be placed into the Snippets section.EDIT: (To clarify which one, )Thanks @allRegards,DeMo. Edited August 14, 2012 by GerrOrneq Quote of the week:"BASIC programmers never die, they GOSUB and don't RETURN." -- UnknownWisdom of the ages: I'd be unstoppable... if not for law enforcement and physics. Marriage, the number 1 cause of divorce. Don't steal... the government hates competition. Irish Government Motto: We’ve got what it takes to take what you’ve got. Birthdays are good for you. Statistics show that the people who have the most live the longest. Failure is not an option. It comes bundled with your Microsoft product.-- Ferenc Mantfeld If you learn from your mistakes, then why ain't I a genius?! -- Anonymous Remember, live every day as if it was your last day! one day you will be right. How is it one careless match can start a forest fire, but it takes a whole box to start a campfire? Sure my system is secure, it just locked up again. I haven't lost my mind; I have a tape back-up somewhere. ~Author Unknown Link to comment Share on other sites More sharing options...
MrCreatoR Posted August 14, 2012 Share Posted August 14, 2012 @MrCreatoRMy favourite was your solution, in fact I think it is so good that it should be placed into the Snippets section.EDIT: (To clarify which one, )It's need more polishing, for example, while you select the editable text and drag the mouse outside the control borders the edit is done. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
MrCreatoR Posted August 14, 2012 Share Posted August 14, 2012 (edited) Here it's in UDF style: expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> Global $hEL_Wnd, $iEL_Label, $iEL_Edit $hGUI = GUICreate("Example", 500, 100) $aEditLabel = _EditableLabel_Create($hGUI, "Some data, left click (and wait few moments) to edit.", 20, 20, 460, 30) Dim $aAccellKeys[1][2] = [['{ESC}', $aEditLabel[1]]] GUISetAccelerators($aAccellKeys, $hGUI) GUISetState(@SW_SHOW) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $aEditLabel[0] _EditableLabel_Show($aEditLabel) Case $aEditLabel[1] _EditableLabel_Hide($aEditLabel, False) EndSwitch WEnd Func _EditableLabel_Create($hWnd, $sData, $iLeft, $iTop, $iWidth = -1, $iHeight = -1) Local $aRet[2] $aRet[0] = GUICtrlCreateLabel($sData, $iLeft, $iTop, $iWidth, $iHeight) $aRet[1] = GUICtrlCreateEdit($sData, $iLeft, $iTop, $iWidth + 5, $iHeight + 5, BitOR($ES_WANTRETURN, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL)) GUICtrlSetState($aRet[1], $GUI_HIDE) $hEL_Wnd = $hWnd Return $aRet EndFunc Func _EditableLabel_Show($aEditLabel = 0) If @NumParams > 0 Then $iEL_Label = $aEditLabel[0] $iEL_Edit = $aEditLabel[1] AdlibRegister('_EditableLabel_Show', 800) Return EndIf AdlibUnRegister('_EditableLabel_Show') GUIRegisterMsg($WM_LBUTTONUP, '__EL_WM_LBUTTONUP') Local $aPos = ControlGetPos($hEL_Wnd, '', $iEL_Label) Local $aWinPos = WinGetClientSize($hEL_Wnd) If ($aPos[1] + ($aPos[3] - 10)) > $aWinPos[1] Then $aPos[3] = $aWinPos[1] - ($aPos[1] + 10) EndIf GUICtrlSetData($iEL_Edit, GUICtrlRead($iEL_Label)) GUICtrlSetPos($iEL_Edit, $aPos[0], $aPos[1], $aPos[2] + 5, $aPos[3] + 5) GUICtrlSetState($iEL_Edit, $GUI_SHOW) GUICtrlSetState($iEL_Label, $GUI_HIDE) EndFunc Func _EditableLabel_Hide($aEditLabel, $bUpdate = True) GUIRegisterMsg($WM_LBUTTONUP, '') If IsArray($aEditLabel) Then $iEL_Label = $aEditLabel[0] $iEL_Edit = $aEditLabel[1] EndIf GUICtrlSetState($iEL_Edit, $GUI_HIDE) GUICtrlSetState($iEL_Label, $GUI_SHOW) If $bUpdate Then Local $aPos = ControlGetPos($hEL_Wnd, '', $iEL_Label) Local $sData = GUICtrlRead($iEL_Edit) StringReplace($sData, @CRLF, '') Local $iLines = @extended - 1 GUICtrlSetData($iEL_Label, $sData) GUICtrlSetPos($iEL_Label, $aPos[0], $aPos[1], $aPos[2], $aPos[3] + (22 * $iLines)) EndIf EndFunc Func __EL_WM_LBUTTONUP($hWnd, $iMsg, $wParam, $lParam) _EditableLabel_Hide(0, True) EndFunc Edited August 14, 2012 by MrCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
skin27 Posted August 26, 2012 Share Posted August 26, 2012 Very nice feature to edit labels. I had some issues with the above example in UDF style though. When there is only one line on the label @extended returns 0 and so the label is made one line (22) smaller. For example by clicking on the text and then outside the label without changing anything. Also the label doesn't resize back when lines are removed. I also would like that style/exstyle parameters can be set on the label. This code works for me (v3.3.8.1) expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> Global $hEL_Wnd, $iEL_Label, $iEL_Edit $hGUI = GUICreate("Example", 500, 200) $aEditLabel = _EditableLabel_Create($hGUI, "Some data, left click (and wait few moments) to edit.", 20, 20, 280, 22,-1,$WS_EX_DLGMODALFRAME) Dim $aAccellKeys[1][2] = [['{ESC}', $aEditLabel[1]]] GUISetAccelerators($aAccellKeys, $hGUI) GUISetState(@SW_SHOW) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $aEditLabel[0] _EditableLabel_Show($aEditLabel) Case $aEditLabel[1] _EditableLabel_Hide($aEditLabel, False) EndSwitch WEnd Func _EditableLabel_Create($hWnd, $sData, $iLeft, $iTop, $iWidth = -1, $iHeight = -1,$sStyle= -1, $sExStyle =-1) Local $aRet[2] $aRet[0] = GUICtrlCreateLabel($sData, $iLeft, $iTop, $iWidth, $iHeight, $sStyle, $sExStyle) $aRet[1] = GUICtrlCreateEdit($sData, $iLeft, $iTop, $iWidth + 5, $iHeight + 5, BitOR($ES_WANTRETURN, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL)) GUICtrlSetState($aRet[1], $GUI_HIDE) $hEL_Wnd = $hWnd Return $aRet EndFunc Func _EditableLabel_Show($aEditLabel = 0) If @NumParams > 0 Then $iEL_Label = $aEditLabel[0] $iEL_Edit = $aEditLabel[1] AdlibRegister('_EditableLabel_Show', 800) Return EndIf AdlibUnRegister('_EditableLabel_Show') GUIRegisterMsg($WM_LBUTTONUP, '__EL_WM_LBUTTONUP') Local $aPos = ControlGetPos($hEL_Wnd, '', $iEL_Label) Local $aWinPos = WinGetClientSize($hEL_Wnd) If ($aPos[1] + ($aPos[3] - 10)) > $aWinPos[1] Then $aPos[3] = $aWinPos[1] - ($aPos[1] + 10) EndIf GUICtrlSetData($iEL_Edit, GUICtrlRead($iEL_Label)) GUICtrlSetPos($iEL_Edit, $aPos[0], $aPos[1], $aPos[2], $aPos[3]) GUICtrlSetState($iEL_Edit, $GUI_SHOW) GUICtrlSetState($iEL_Label, $GUI_HIDE) EndFunc Func _EditableLabel_Hide($aEditLabel, $bUpdate = True) GUIRegisterMsg($WM_LBUTTONUP, '') If IsArray($aEditLabel) Then $iEL_Label = $aEditLabel[0] $iEL_Edit = $aEditLabel[1] EndIf GUICtrlSetState($iEL_Edit, $GUI_HIDE) GUICtrlSetState($iEL_Label, $GUI_SHOW) If $bUpdate Then Local $aPos = ControlGetPos($hEL_Wnd, '', $iEL_Label) Local $sData = GUICtrlRead($iEL_Edit) StringReplace($sData, @CRLF, '') Local $iLines = @extended + 1 GUICtrlSetData($iEL_Label, $sData) GUICtrlSetPos($iEL_Label, $aPos[0], $aPos[1], $aPos[2], 22 * $iLines) EndIf EndFunc Func __EL_WM_LBUTTONUP($hWnd, $iMsg, $wParam, $lParam) _EditableLabel_Hide(0, True) EndFunc I also mixed the UDF with an example of Melba23 so the label can be dragged as well: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> ; Mouse coords relative to GUI client area Opt("MouseCoordMode", 2) Global $hEL_Wnd, $iEL_Label, $iEL_Edit,$fDblClk ; Create GUI $hGUI = GUICreate("Left click to drag/Right click to edit", 300, 200) $cLabel = _EditableLabel_Create($hGUI, "Flexible label", 10, 150, 100, 22) GUICtrlSetBkColor(-1, 0xD4D0C8) ;Sets the accelerator table Dim $aAccellKeys[1][2] = [['{ESC}', $cLabel[1]]] GUISetAccelerators($aAccellKeys, $hGUI) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_SECONDARYUP $cInfo = GUIGetCursorInfo($hGUI) $iControl = $cInfo[4] If $iControl = $cLabel[0] then _EditableLabel_Show($cLabel) Case $GUI_EVENT_PRIMARYDOWN $cInfo = GUIGetCursorInfo($hGUI) $iControl = $cInfo[4] Switch $iControl Case $cLabel[0] $bPos = ControlGetPos($hGUI, "", $iControl) $iSubtractX = $cInfo[0] - $bPos[0] $iSubtractY = $cInfo[1] - $bPos[1] ; Move the control until the mouse button is released Do $cInfo = GUIGetCursorInfo($hGUI) ControlMove($hGUI, "", $iControl, $cInfo[0] - $iSubtractX, $cInfo[1] - $iSubtractY) Until Not $cInfo[2] EndSwitch Case $cLabel[1] _EditableLabel_Hide($cLabel, False) EndSwitch WEnd Func _EditableLabel_Create($hWnd, $sData, $iLeft, $iTop, $iWidth = -1, $iHeight = -1,$sStyle= -1, $sExStyle =-1) Local $aRet[2] $aRet[0] = GUICtrlCreateLabel($sData, $iLeft, $iTop, $iWidth, $iHeight, $sStyle, $sExStyle) $aRet[1] = GUICtrlCreateEdit($sData, $iLeft, $iTop, $iWidth + 5, $iHeight + 5, BitOR($ES_WANTRETURN, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL)) GUICtrlSetState($aRet[1], $GUI_HIDE) $hEL_Wnd = $hWnd Return $aRet EndFunc Func _EditableLabel_Show($aEditLabel = 0) If @NumParams > 0 Then $iEL_Label = $aEditLabel[0] $iEL_Edit = $aEditLabel[1] AdlibRegister('_EditableLabel_Show', 800) Return EndIf AdlibUnRegister('_EditableLabel_Show') GUIRegisterMsg($WM_LBUTTONUP, '__EL_WM_LBUTTONUP') Local $aPos = ControlGetPos($hEL_Wnd, '', $iEL_Label) Local $aWinPos = WinGetClientSize($hEL_Wnd) If ($aPos[1] + ($aPos[3] - 10)) > $aWinPos[1] Then $aPos[3] = $aWinPos[1] - ($aPos[1] + 10) EndIf GUICtrlSetData($iEL_Edit, GUICtrlRead($iEL_Label)) GUICtrlSetPos($iEL_Edit, $aPos[0], $aPos[1], $aPos[2], $aPos[3]) GUICtrlSetState($iEL_Edit, $GUI_SHOW) GUICtrlSetState($iEL_Label, $GUI_HIDE) EndFunc Func _EditableLabel_Hide($aEditLabel, $bUpdate = True) GUIRegisterMsg($WM_LBUTTONUP, '') If IsArray($aEditLabel) Then $iEL_Label = $aEditLabel[0] $iEL_Edit = $aEditLabel[1] EndIf GUICtrlSetState($iEL_Edit, $GUI_HIDE) GUICtrlSetState($iEL_Label, $GUI_SHOW) If $bUpdate Then Local $aPos = ControlGetPos($hEL_Wnd, '', $iEL_Label) Local $sData = GUICtrlRead($iEL_Edit) StringReplace($sData, @CRLF, '') Local $iLines = @extended + 1 GUICtrlSetData($iEL_Label, $sData) GUICtrlSetPos($iEL_Label, $aPos[0], $aPos[1], $aPos[2], 22 * $iLines) EndIf EndFunc Func __EL_WM_LBUTTONUP($hWnd, $iMsg, $wParam, $lParam) _EditableLabel_Hide(0, True) EndFunc This works quite ok, though I think it would be nicer to just use GUICtrlCreateLabel and set the style to $SS_DRAGANDDROP and $SS_EDIT. 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