Leaderboard
Popular Content
Showing content with the highest reputation on 11/04/2017 in all areas
-
Good coding practices in AutoIt
argumentum and one other reacted to mLipok for a topic
hm... as I remember here (in this topic/thread) was not discused about: "variable meaningful titles/names" Also on AutoIt Wiki: https://www.autoitscript.com/wiki/Best_coding_practices#Names_of_Variables There is no mention about "variable meaningful titles/names". For example in this Wiki page there is: For $i = 1 To 10 $g_vVariableThatIsGlobal &= $i ; This will return 12345678910 totally wiping the previous contents of $g_vVariableThatIsGlobal Next And for this little "for to next" loop I do not see any needs to change it, especially that in this example the loop is inside a small function. But for some time, I have tried in my UDF's to make the variables "significant titles". ; my old coding habbits For $i =1 To $aUsers[0][0] ...... ...... ...... ...... ...... ...... ...... ...... ...... $aUsers[$i][....] ...... ...... ...... ...... ...... ...... ...... ...... ...... Next ; my current coding style For $iUser_idx =1 To $aUsersList[0][0] ...... ...... ...... ...... ...... ...... ...... ...... ...... $aUsersList[$iUser_idx][...] ...... ...... ...... ...... ...... ...... ...... ...... ...... Next ; my old coding habbits For $oUser In $oUsers.count ...... ...... ...... ...... ...... ...... ...... ...... ...... $oUser.value ...... ...... ...... ...... ...... ...... ...... ...... ...... Next ; my current coding style For $oUserNode_enum In $oUserNodes_coll.count ...... ...... ...... ...... ...... ...... ...... ...... ...... $oUserNode_enum.value ...... ...... ...... ...... ...... ...... ...... ...... ...... Next Thanks to them, I avoid many problems with analizing old code. Even when I try to understand my own old code (older then 3 years), I start with rewriting variable names. And then I use Au3Check, and finally i start to understand what is going on in this code. What you think about such convention - I do not mean exactly about the suffix _coll, _enum and _idx but generally about the concept to use "variable meaningful titles/names" ?2 points -
hello I'm not a too good in coding practices. But I try to use variable meaningful titles/names when I think Its required. ;~ If Its for some Internal array manipulation I use something like this ;Also When things are too obviously For $i = 1 To $aArray[0][0] ...... ...... ...... ...... ...... ...... ...... ...... ...... $aArray[$i][....]...... ...... ...... ...... ...... ...... ...... ...... ...... Next ;~ If Is something of the main script where I know I use many For statements in a function ;if Is a 2D Array I use some meaningful const Index Local Const Enum $eNAME, $eEMAIL, $eADDRESS For $iIndex = 1 To $aUserInfo[0][0] ...... ...... ...... ...... ...... ...... ...... ...... ...... $aUserInfo[$iIndex][$eNAME]...... ...... ...... ...... ...... ...... ...... ...... ...... Next ;when I work with many GUIs I use something like this for may globals #Region GUI Main ;here some relevant information Global $g_MIdListViewUsers, $g_MhListViewUsers, $g_MIdtxtClientName, $g_MIdbtnAccept #EndRegion GUI Main #Region GUI Report ;here some relevant information Global $g_RIdListViewUsers, $g_RhListViewUsers, $g_RIdtxtClientName, $g_RIdbtnAccept #EndRegion GUI Report ;I think when I use object is enough somethig like this For $oUser In $oUsers.count ...... ...... ...... ...... ...... ...... ...... ...... $oUserCredentials = $oUser.GetCredentials ...... ...... ...... ...... ...... ...... ...... ...... For $oUserCredential In $oUserCredentials ...... ...... ...... ...... ...... ...... ...... ...... Next ...... ...... ...... ...... ...... ...... ...... ...... Next ;basically I denote is a list just pluralizing my variable's name Of course everyone gets used to their own style. I try to get a better coding practices each day reading around the web. Saludos1 point
-
ComboBox Set DROPDOWNLIST Colors/size UDF
argumentum reacted to Danyfirex for a topic
Hello. For set color to that you need some owen drawn handling. something like this. #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <GUIComboBox.au3> #include <ColorConstants.au3> #include <WinAPI.au3> #include <FontConstants.au3> Global Const $ODA_DRAWENTIRE = 1 Global Const $ODA_SELECT = 2 Global Const $ODS_SELECTED = 1 Global Const $ODT_COMBOBOX = 3 Global Const $sTagDRAWITEMSTRUCT = "uint CtlType;uint CtlID;uint itemID;uint itemAction;uint itemState;" & _ "hwnd hwndItem;hwnd hDC;long Left;long Top;long Right;long Bottom;ulong_ptr itmData" ;for custom Font ;~ Global $g_hFont = _WinAPI_CreateFont(15, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _ ;~ $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Segoe UI') Global $idComboBox = 0 Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 300, 200) ; Create a combobox control. $idComboBox = GUICtrlCreateCombo("Item 1", 10, 10, 185, 25, BitOR($CBS_OWNERDRAWFIXED, $CBS_HASSTRINGS, $CBS_DROPDOWNLIST)) Local $idClose = GUICtrlCreateButton("Exit", 210, 170, 85, 25) ; Add additional items to the combobox. GUICtrlSetData($idComboBox, "Item 2|Item 3", "Item 1") GUIRegisterMsg($WM_DRAWITEM, "_WM_DRAWITEM") GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func _WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) Local $tRawItem = DllStructCreate($sTagDRAWITEMSTRUCT, $lParam) Local $iCtlType = DllStructGetData($tRawItem, 'CtlType') Local $iCtlID = DllStructGetData($tRawItem, 'CtlID') Local $iItemID = DllStructGetData($tRawItem, 'itemID') Local $iItemAction = DllStructGetData($tRawItem, 'itemAction') Local $iItemState = DllStructGetData($tRawItem, 'itemState') Local $hWndItem = DllStructGetData($tRawItem, 'hwndItem') Local $hDC = DllStructGetData($tRawItem, 'hDC') Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tRawItem, "Left")) Local $sText = "" Local $sDummyString = " " ;just for fill the whole rect this can be avoid using some fillrect APIs Local $iBackColor = 0xFFFFFF ;White Local $iFontColor = 0x000000 ;Black ;~ Local $g_hOldFont = _WinAPI_SelectObject($hDC, $g_hFont) If $iCtlType = $ODT_COMBOBOX And $iCtlID = $idComboBox Then Switch $iItemAction Case $ODA_DRAWENTIRE _GUICtrlComboBox_GetLBText($hWndItem, $iItemID, $sText) If BitAND($iItemState, $ODS_SELECTED) Then $iBackColor = 0x8000FF ;Pink _WinAPI_SetTextColor($hDC, $iFontColor) _WinAPI_SetBkColor($hDC, $iBackColor) _WinAPI_DrawText($hDC, $sText & $sDummyString, $tRect, $DT_LEFT) Case $ODA_SELECT _GUICtrlComboBox_GetLBText($hWndItem, $iItemID, $sText) If BitAND($iItemState, $ODS_SELECTED) Then $iBackColor = 0x8000FF ;Pink _WinAPI_SetTextColor($hDC, $iFontColor) _WinAPI_SetBkColor($hDC, $iBackColor) _WinAPI_DrawText($hDC, $sText & $sDummyString, $tRect, $DT_LEFT) EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_DRAWITEM Saludos1 point -
Date/Time Pick coloring
robertocm reacted to argumentum for a topic
I really want to have this, so, it's a head start ( and example ) of coloring this control ( or part of it so far ) So don't be shy and pitch in #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiDateTimePicker.au3> #include <WindowsConstants.au3> #include <WinAPITheme.au3> #include <GuiMonthCal.au3> Global $g_hDTP1, $g_hDTP2, $g_idMemo Example() Func Example() Local $hGUI ; Create GUI $hGUI = GUICreate("DateTimePick coloring test", 500, 300) $g_idMemo = GUICtrlCreateEdit("", 2, 62, 496, 266, BitOR($GUI_SS_DEFAULT_EDIT,$ES_READONLY)) GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") GUICtrlSetData($g_idMemo, "MonthCal child handle will be created each time it pops up." & @CRLF & @CRLF, 1) $g_hDTP1 = GUICtrlGetHandle(GUICtrlCreateDate("", 2, 6, 185, 20)) $g_hDTP2 = _GUICtrlDTP_Create($hGUI, 2, 32, 240) GUICtrlCreateLabel("<-- now we need to find how to color", 195, 5, 500, 20) GUICtrlSetFont(-1, 9, 400, 0, "Courier New") GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel("this part of the control", 280, 30, 500, 20) GUICtrlSetFont(-1, 9, 400, 0, "Courier New") GUICtrlSetState(-1, $GUI_FOCUS) GUISetState(@SW_SHOW) ; Set the display format _GUICtrlDTP_SetFormat($g_hDTP1, "ddd MMM dd, yyyy hh:mm ttt") _GUICtrlDTP_SetFormat($g_hDTP2, "ddd MMM dd, yyyy hh:mm ttt") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") WinActivate("DateTimePick coloring test") ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $tBuffer, $tBuffer2, $iCtrl $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $g_hDTP1, $g_hDTP2 Switch $iCode Case $NM_SETFOCUS _WinAPI_SetThemeAppProperties(0) _DebugPrint("$NM_SETFOCUS" & @CRLF & "-->hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) Case $NM_KILLFOCUS _WinAPI_SetThemeAppProperties(3) _DebugPrint("$NM_KILLFOCUS" & @CRLF & "-->hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) Case $DTN_DROPDOWN ; Sent by a date and time picker (DTP) control when the user activates the drop-down month calendar _DebugPrint("$DTN_DROPDOWN" & @CRLF & "-->hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; The return value for this notification is not used ; Get month control child handle $iCtrl = _GUICtrlDTP_GetMonthCal($hWndFrom) ;~ _WinAPI_SetWindowTheme($iCtrl, "", "") ; setting this here, does not change the size of the original canvas ;~ ; instead, for my simplicity, use _WinAPI_SetThemeAppProperties() OnFocus GUICtrlSetData($g_idMemo, "MonthCal child Handle: " & "0x" & Hex($iCtrl) & @CRLF, 1) _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TEXT, 0x8BD4DF) _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TITLEBK, 0xA9D7E4) _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TITLETEXT, 0x005894) _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_MONTHBK, 0x3F3F3F) _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TRAILINGTEXT, 0xB2C2A9) Case $DTN_CLOSEUP ; Sent by a date and time picker (DTP) control when the user closes the drop-down month calendar _DebugPrint("$DTN_CLOSEUP" & @CRLF & "-->hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; The return value for this notification is not used Case $DTN_DATETIMECHANGE ; Sent by a date and time picker (DTP) control whenever a change occurs $tInfo = DllStructCreate($tagNMDATETIMECHANGE, $lParam) _DebugPrint("$DTN_DATETIMECHANGE" & @CRLF & "-->hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _ "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _ "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _ "-->Flag:" & @TAB & DllStructGetData($tInfo, "Flag") & @CRLF & _ "-->Year:" & @TAB & DllStructGetData($tInfo, "Year") & @CRLF & _ "-->Month:" & @TAB & DllStructGetData($tInfo, "Month") & @CRLF & _ "-->DOW:" & @TAB & DllStructGetData($tInfo, "DOW") & @CRLF & _ "-->Day:" & @TAB & DllStructGetData($tInfo, "Day") & @CRLF & _ "-->Hour:" & @TAB & DllStructGetData($tInfo, "Hour") & @CRLF & _ "-->Minute:" & @TAB & DllStructGetData($tInfo, "Minute") & @CRLF & _ "-->Second:" & @TAB & DllStructGetData($tInfo, "Second") & @CRLF & _ "-->MSecond:" & @TAB & DllStructGetData($tInfo, "MSecond")) Return 0 Case $DTN_FORMAT ; Sent by a date and time picker (DTP) control to request text to be displayed in a callback field $tInfo = DllStructCreate($tagNMDATETIMEFORMAT, $lParam) $tBuffer = DllStructCreate("char Format[128]", DllStructGetData($tInfo, "Format")) $tBuffer2 = DllStructCreate("char Display[64]", DllStructGetData($tInfo, "pDisplay")) _DebugPrint("$DTN_FORMAT" & @CRLF & "-->hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _ "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _ "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _ "-->Format:" & @TAB & DllStructGetData($tBuffer, "Format") & @CRLF & _ "-->Year:" & @TAB & DllStructGetData($tInfo, "Year") & @CRLF & _ "-->Month:" & @TAB & DllStructGetData($tInfo, "Month") & @CRLF & _ "-->DOW:" & @TAB & DllStructGetData($tInfo, "DOW") & @CRLF & _ "-->Day:" & @TAB & DllStructGetData($tInfo, "Day") & @CRLF & _ "-->Hour:" & @TAB & DllStructGetData($tInfo, "Hour") & @CRLF & _ "-->Minute:" & @TAB & DllStructGetData($tInfo, "Minute") & @CRLF & _ "-->Second:" & @TAB & DllStructGetData($tInfo, "Second") & @CRLF & _ "-->MSecond:" & @TAB & DllStructGetData($tInfo, "MSecond") & @CRLF & _ "-->Display:" & @TAB & DllStructGetData($tBuffer2, "Display")) Return 0 Case $DTN_FORMATQUERY ; Sent by a date and time picker (DTP) control to retrieve the maximum allowable size of the string that will be displayed in a callback field $tInfo = DllStructCreate($tagNMDATETIMEFORMATQUERY, $lParam) $tBuffer = DllStructCreate("char Format[128]", DllStructGetData($tInfo, "Format")) _DebugPrint("$DTN_FORMATQUERY" & @CRLF & "-->hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _ "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _ "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _ "-->Format:" & @TAB & DllStructGetData($tBuffer, "Format") & @CRLF & _ "-->SizeX:" & @TAB & DllStructGetData($tInfo, "SizeX") & @CRLF & _ "-->SizeY:" & @TAB & DllStructGetData($tBuffer2, "SizeY")) DllStructSetData($tInfo, "SizeX", 64) DllStructSetData($tInfo, "SizeY", 10) Return 0 Case $DTN_USERSTRING ; Sent by a date and time picker (DTP) control when a user finishes editing a string in the control $tInfo = DllStructCreate($tagNMDATETIMESTRING, $lParam) $tBuffer = DllStructCreate("char UserString[128]", DllStructGetData($tInfo, "UserString")) _DebugPrint("$DTN_USERSTRING" & @CRLF & "-->hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _ "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _ "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _ "-->UserString:" & @TAB & DllStructGetData($tBuffer, "UserString") & @CRLF & _ "-->Year:" & @TAB & DllStructGetData($tInfo, "Year") & @CRLF & _ "-->Month:" & @TAB & DllStructGetData($tInfo, "Month") & @CRLF & _ "-->DOW:" & @TAB & DllStructGetData($tInfo, "DOW") & @CRLF & _ "-->Day:" & @TAB & DllStructGetData($tInfo, "Day") & @CRLF & _ "-->Hour:" & @TAB & DllStructGetData($tInfo, "Hour") & @CRLF & _ "-->Minute:" & @TAB & DllStructGetData($tInfo, "Minute") & @CRLF & _ "-->Second:" & @TAB & DllStructGetData($tInfo, "Second") & @CRLF & _ "-->MSecond:" & @TAB & DllStructGetData($tInfo, "MSecond") & @CRLF & _ "-->Flags:" & @TAB & DllStructGetData($tInfo, "Flags")) Return 0 Case $DTN_WMKEYDOWN ; Sent by a date and time picker (DTP) control when the user types in a callback field $tInfo = DllStructCreate($tagNMDATETIMEFORMATQUERY, $lParam) $tBuffer = DllStructCreate("char Format[128]", DllStructGetData($tInfo, "Format")) _DebugPrint("$DTN_WMKEYDOWN" & @CRLF & "-->hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _ "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _ "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _ "-->VirtKey:" & @TAB & DllStructGetData($tInfo, "VirtKey") & @CRLF & _ "-->Format:" & @TAB & DllStructGetData($tBuffer, "Format") & @CRLF & _ "-->Year:" & @TAB & DllStructGetData($tInfo, "Year") & @CRLF & _ "-->Month:" & @TAB & DllStructGetData($tInfo, "Month") & @CRLF & _ "-->DOW:" & @TAB & DllStructGetData($tInfo, "DOW") & @CRLF & _ "-->Day:" & @TAB & DllStructGetData($tInfo, "Day") & @CRLF & _ "-->Hour:" & @TAB & DllStructGetData($tInfo, "Hour") & @CRLF & _ "-->Minute:" & @TAB & DllStructGetData($tInfo, "Minute") & @CRLF & _ "-->Second:" & @TAB & DllStructGetData($tInfo, "Second") & @CRLF & _ "-->MSecond:" & @TAB & DllStructGetData($tInfo, "MSecond")) Return 0 Case Else _DebugPrint("$DTN_?????" & @CRLF & "-->hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @CRLF & _ "+======================================================" & @CRLF & _ "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _ "+======================================================" & @CRLF) EndFunc ;==>_DebugPrint Hopefully it'll turn into a UDF1 point -
This is can be another way #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Window_0 = GUICreate("My Window", 800, 500, -1, -1, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX)) $btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50) $cmb1 = GUICtrlCreateCombo("Sample1", 50, 150, 300, 50) $cmb2 = GUICtrlCreateCombo("Sample2", 50, 200, 300, 50) GUISetState(@SW_SHOW) Do $event = GUIGetMsg() Switch $event Case $GUI_EVENT_PRIMARYDOWN If MouseGetCursor() = 5 Then ConsoleWrite(ControlGetFocus($Window_0) & @CRLF) EndSwitch Sleep(50) Until $event = $GUI_EVENT_CLOSE1 point
-
Another way. #include <GUIConstantsEx.au3> #include <GuiComboBox.au3> #include <WinAPI.au3> #include <Array.au3> #include <WinAPIGdi.au3> Global $tInfo Global $Window_0 = GUICreate("My Window", 800, 500) $btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50) Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50) Global $lstbx = GUICtrlCreateList("FirstItem", 400, 50, 200, 300) GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2") GUICtrlSetData($lstbx, "Apple|Orange|Pineapple|Grape|Lemon") GUISetState(@SW_SHOW) _GUICtrlComboBox_GetComboBoxInfo($cmb, $tInfo) Global $hComboEdit = DllStructGetData($tInfo, "hEdit") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN _CheckComBoxClickTextArea() EndSwitch WEnd Func _CheckComBoxClickTextArea() Local $iX = MouseGetPos(0) Local $iY = MouseGetPos(1) Local $tRect = _WinAPI_GetWindowRect($hComboEdit) Local $iLeft = DllStructGetData($tRect, 1) Local $iTop = DllStructGetData($tRect, 2) Local $iRight = DllStructGetData($tRect, 3) Local $iBottom = DllStructGetData($tRect, 4) If _WinAPI_PtInRectEx($iX, $iY, $iLeft, $iTop, $iRight, $iBottom) Then ConsoleWrite("Clicked" & @CRLF) EndIf EndFunc ;==>_CheckComBoxClickTextArea Saludos1 point
-
Et voila! #include <GUIConstantsEx.au3> #include <GuiComboBox.au3> #include <WinAPI.au3> Global $tInfo Global $Window_0 = GUICreate("My Window", 800, 500) $btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50) Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50) Global $lstbx = GUICtrlCreateList("FirstItem", 400,50, 200, 300) GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2") GUICtrlSetData($lstbx, "Apple|Orange|Pineapple|Grape|Lemon") GUISetState(@SW_SHOW) _GUICtrlComboBox_GetComboBoxInfo($cmb, $tInfo) $hComboEdit = DllStructGetData($tInfo, "hEdit") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN If _WinAPI_GetFocus() = DllStructGetData($tInfo, "hEdit") And _GUICtrlComboBox_GetDroppedState($cmb) = False Then ConsoleWrite("Hit" & @CRLF) EndIf EndSwitch WEnd M231 point
-
M32 when you open and close the drop down the event is raised too Also when you select alList Item. Saludos1 point
-
kcvinu, Then try this: #include <GUIConstantsEx.au3> #include <GuiComboBox.au3> #include <WinAPI.au3> Global $tInfo Global $Window_0 = GUICreate("My Window", 800, 500) $btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50) Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50) Global $lstbx = GUICtrlCreateList("FirstItem", 400,50, 200, 300) GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2") GUICtrlSetData($lstbx, "Apple|Orange|Pineapple|Grape|Lemon") GUISetState(@SW_SHOW) _GUICtrlComboBox_GetComboBoxInfo($cmb, $tInfo) $hComboEdit = DllStructGetData($tInfo, "hEdit") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN If _WinAPI_GetFocus() = DllStructGetData($tInfo, "hEdit") Then ConsoleWrite("Hit" & @CRLF) EndIf EndSwitch WEnd M231 point
-
Not know before sharing, he tried to run the code yet? I had to take one moment to run it Code_Screen_Pattern.zip1 point
-
Hello. Another way... #include <GUIConstantsEx.au3> #include <GuiComboBox.au3> #include <WinAPI.au3> Global $tInfo Global $Window_0 = GUICreate("My Window", 800, 500) $btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50) Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50) Global $lstbx = GUICtrlCreateList("FirstItem", 400, 50, 200, 300) GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2") GUICtrlSetData($lstbx, "Apple|Orange|Pineapple|Grape|Lemon") GUISetState(@SW_SHOW) _GUICtrlComboBox_GetComboBoxInfo($cmb, $tInfo) Global $hComboEdit = DllStructGetData($tInfo, "hEdit") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN _CheckComBoxClickTextArea() EndSwitch WEnd Func _CheckComBoxClickTextArea() Local $g_tStruct = DllStructCreate($tagPOINT) DllStructSetData($g_tStruct, "x", MouseGetPos(0)) DllStructSetData($g_tStruct, "y", MouseGetPos(1)) Local $hHandleFromPoint=_WinAPI_WindowFromPoint($g_tStruct) If $hHandleFromPoint = $hComboEdit Then ConsoleWrite("Clicked" & @CRLF) EndIf EndFunc Saludos1 point
-
Create gradient from 2 colors
argumentum reacted to BrewManNH for a topic
http://bfy.tw/EakR Enjoy the dozens of other threads about the same thing.1 point -
I know. "Why do you say that" is just a phrase/expression that means where did that question come from? I am just surprised that's all. But if it makes you feel better then perhaps I should have said why do you ask that?1 point
-
Is this a better example to what I suggested in post >#297? The idea of what the functions do is really not the point I'm making, it's the concept and design I'm interested in. #include <Array.au3> #include <Constants.au3> ; This enumeration starts from 0 to 3. Global Enum $AU3SCRIPT_FILEPATH, $AU3SCRIPT_FILEDATA, $AU3SCRIPT_FUNCTIONS, $AU3SCRIPT_MAX ; These could be inside the functions as Local Enum if you don't want Global variables. Example() Func Example() ; Create a constant variable with the filepath we wish to pass to Au3Script_Start. Local Const $sFilePath = @ScriptFullPath ; Create an "Au3Script" object/api to pass to functions that can manipulate with this variable only. Local $hAu3Script = Au3Script_Start($sFilePath) ; Read and display function(s) in the script file. Local $aFunctions = Au3Script_Functions($hAu3Script) _ArrayDisplay($aFunctions, 'Functions') ; Read and display the script file data. Local $sData = Au3Script_Read($hAu3Script) MsgBox($MB_SYSTEMMODAL, '', $sData) ; Display the object/api to show it is indeed an array. Item 2 is blank as this is an array. ; Note: The end-user shouldn't really see this, but this is purely for demonstration purposes. _ArrayDisplay($hAu3Script, 'INTERNAL_ONLY') ; Clear the object/api. Au3Script_Shutdown($hAu3Script) EndFunc ;==>Example Func Au3Script_Functions(ByRef $aAPI) ; Display function(s) in a script file. Local $aFunctions = 0 If __Au3Script_IsObject($aAPI) Then ; Check if the variable passed is a valid array with the correct number of dimensions. If UBound($aAPI[$AU3SCRIPT_FUNCTIONS]) = 0 Then ; Check if the variable is not an array already. $aFunctions = StringRegExp('Func Count(' & @CRLF & $aAPI[$AU3SCRIPT_FILEDATA], '(?im)^Func\h+(\w+)\h*\(', 3) ; Retrieve function(s) in the script. $aFunctions[0] = UBound($aFunctions) - 1 ; Set the 0th index to the total count. $aAPI[$AU3SCRIPT_FUNCTIONS] = $aFunctions ; Assign the object/api "function" with the function(s) array. Else $aFunctions = $aAPI[$AU3SCRIPT_FUNCTIONS] ; If the object/api "function" is already an array, then assign the return variable with that function. EndIf EndIf Return $aFunctions EndFunc ;==>Au3Script_Functions Func Au3Script_Read(ByRef $aAPI) ; Read a script file. Local $sFileData = '' If __Au3Script_IsObject($aAPI) Then ; Check if the variable passed is a valid array with the correct number of dimensions. If $aAPI[$AU3SCRIPT_FILEDATA] = '' Then ; Check if the variable is blank/empty. $aAPI[$AU3SCRIPT_FILEDATA] = FileRead($aAPI[$AU3SCRIPT_FILEPATH]) ; Assign the object/api "data" with the script file data. EndIf $sFileData = $aAPI[$AU3SCRIPT_FILEDATA] ; Assign the return variable with the the object/api "data" content. EndIf Return $sFileData ; Return the read data. EndFunc ;==>Au3Script_Read Func Au3Script_Start($sFilePath) Local $aAPI[$AU3SCRIPT_MAX] ; Create an array with 3 elements. $aAPI[$AU3SCRIPT_FILEPATH] = $sFilePath ; Assign the object/api "filepath" with the script file path. Au3Script_Read($aAPI) ; Read the script file using the Au3Script_Read function. Return $aAPI ; Return the newly created object/api handle. EndFunc ;==>Au3Script_Start Func Au3Script_Shutdown(ByRef $aAPI) Local $fReturn = __Au3Script_IsObject($aAPI) ; Check if the variable passed is a valid array with the correct number of dimensions. If $fReturn Then ; If is an object/api then continue... $aAPI = 0 ; Clear the array of all data. EndIf Return $fReturn ; True or False depending on the return value of __Au3Script_IsObject. EndFunc ;==>Au3Script_Shutdown Func __Au3Script_IsObject(ByRef $aAPI) ; Internal function to check if the number of items is equal to 3 or the enum variable $AU3SCRIPT_MAX. Return UBound($aAPI) = $AU3SCRIPT_MAX EndFunc ;==>__Au3Script_IsObject1 point
-
Good coding practices in AutoIt
pixelsearch reacted to guinness for a topic
Someone who cares about learning and incidentally my first post is called "Why using Dim over Local/Global is not always a good option:".1 point