Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/15/2024 in all areas

  1. Nine

    AutoIt Snippets

    Owner Draw Combo Box with default $CBS_DROPDOWN. Not so obvious as it seems. #include <WinAPIConv.au3> #include <WinAPIGdi.au3> #include <GUIConstants.au3> #include <Constants.au3> #include <GuiComboBox.au3> Opt("MustDeclareVars", True) Global Const $tagDRAWITEMSTRUCT = "uint CtlType;uint CtlID;uint itemID;uint itemAction;uint itemState;hwnd hwndItem;handle hDC;dword rcItem[4];ptr itemData" Global Const $ODA_DRAWENTIRE = 1 Global Const $ODS_SELECTED = 1 Global $idCombo Example() Func Example() GUICreate("Owner Draw", 300, 200) $idCombo = GUICtrlCreateCombo("", 10, 10, 185, 20, BitOR($CBS_HASSTRINGS, $CBS_OWNERDRAWFIXED, $GUI_SS_DEFAULT_COMBO)) Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25) GUICtrlSetData($idCombo, "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17") GUISetState() Local $aAccelKeys[1][2] = [["{ENTER}", $idCombo]] GUISetAccelerators($aAccelKeys) GUIRegisterMsg($WM_COMMAND, WM_COMMAND) GUIRegisterMsg($WM_DRAWITEM, WM_DRAWITEM) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop EndSwitch WEnd EndFunc ;==>Example Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $idCtrl = _WinAPI_LoWord($wParam), $iCode = _WinAPI_HiWord($wParam) If $idCtrl = $idCombo And ($iCode = $CBN_KILLFOCUS Or $iCode = $CBN_SELCHANGE) Then Validate($idCtrl) Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func Validate($idComboBox) Local Static $sSelection Local $sComboRead = GUICtrlRead($idComboBox) If $sSelection = $sComboRead Then Return Local $iList = _GUICtrlComboBox_FindStringExact($idComboBox, $sComboRead) If $iList = -1 Then GUICtrlSendMsg($idComboBox, $CB_SETCURSEL, -1, 0) $sSelection = "" ConsoleWrite("Invalid data" & @CRLF) Else $sSelection = $sComboRead ConsoleWrite("Currently displaying: " & $sComboRead & @CRLF) If _GUICtrlComboBox_GetCurSel($idComboBox) = -1 Then _GUICtrlComboBox_SetCurSel($idComboBox, $iList) EndIf EndFunc ;==>Validate Func WM_DRAWITEM($hWnd, $iMsg, $wParam, $lParam) If $wParam <> $idCombo Then Return $GUI_RUNDEFMSG Local $tDraw = DllStructCreate($tagDRAWITEMSTRUCT, $lParam), $sText If $tDraw.itemAction = $ODA_DRAWENTIRE Then Local $tRECT = DllStructCreate($tagRECT, DllStructGetPtr($tDraw, "rcItem")) Local $hBrush = _WinAPI_CreateSolidBrush(BitAND($tDraw.itemState, $ODS_SELECTED) ? 0xFFCDAD : Mod($tDraw.itemID, 2) ? 0xFFFFFF : 0xE0E0E0) _WinAPI_FillRect($tDraw.hDC, $tRECT, $hBrush) $tRECT.Left += 5 $tRECT.Top += 2 _GUICtrlComboBox_GetLBText($tDraw.hwndItem, $tDraw.itemID, $sText) _WinAPI_DrawText($tDraw.hDC, $sText, $tRECT, $DT_LEFT) _WinAPI_DeleteObject($hBrush) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_DRAWITEM Note : you can tab, enter, up arrow, down arrow to validate the combo input field.
    1 point
  2. ioa747

    Snowfall

    Thanks for sharing. Impressed by the simplicity. I played around with it a bit and came up with this variation. snowflake: flake2.ico
    1 point
  3. Or a little different approach : #include <GUIConstants.au3> #include <GuiComboBox.au3> Local $hGUI = GUICreate("Test") Local $cCombo = GUICtrlCreateCombo("", 10, 10, 200, 20) GUICtrlSetData($cCombo, "1|2|3") GUICtrlCreateLabel ("Edit :", 10, 50,50,20) Local $cEdit = GUICtrlCreateInput ("", 50, 50, 150, 20) Local $cButton = GUICtrlCreateButton("OK", 10, 100, 100, 25) Local $cDummy = GUICtrlCreateDummy() Local $aAccelKeys[1][2] = [["{ENTER}", $cDummy]] GUISetAccelerators($aAccelKeys) GUISetState() Local $tInfo _GUICtrlComboBox_GetComboBoxInfo($cCombo, $tInfo) Local $hCombo = DllStructGetData($tInfo, "hEdit") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $cButton ExitLoop Case $cDummy If ControlGetHandle($hGUI, "", ControlGetFocus ($hGUI)) = $hCombo Then ; put your code here ConsoleWrite(GUICtrlRead($cCombo) & @CRLF) EndIf EndSwitch WEnd
    1 point
  4. mike2003, I would see if the combo edit box has focus when Enter is pressed - like this: #include <GUIConstantsEx.au3> #include <WinAPISysWin.au3> #include <GuiComboBox.au3> #include <Misc.au3> Global $tInfo $hDLL = DllOpen("user32.dll") $hGUI = GUICreate("Test", 500, 500) $cCombo = GUICtrlCreateCombo("", 10, 10, 200, 20) GUICtrlSetData($cCombo, "1|2|3") GUISetState() ; Get handle of combo edit box If _GUICtrlComboBox_GetComboBoxInfo($cCombo, $tInfo) Then $hComboEdit = DllStructGetData($tInfo, "hEdit") Else ConsoleWrite("Fail" & @CRLF) Exit EndIf While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE DllClose($hDLL) Exit EndSwitch ; Check for Enter press If _IsPressed("0D", $hDLL) Then ; Check if combo edit box has focus If _WinAPI_GetFocus() = $hComboEdit Then ConsoleWrite(GUICtrlRead($cCombo) & @CRLF) EndIf EndIf ; Wait for Enter release - try without this to see why you need it! While _IsPressed("0D", $hDLL) Sleep(250) WEnd WEnd M23
    1 point
  5. Melba23

    UPDOWN help

    darklonerlv, It is not that difficult: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <UpDownConstants.au3> $hGUI = GUICreate("Test", 500, 500) $hInput = GUICtrlCreateInput("5000", 10, 10, 100, 20) $hUpDown = GUICtrlCreateUpdown($hInput, BitOR($UDS_WRAP, $UDS_NOTHOUSANDS)) GUICtrlSetLimit($hUpDown, 6000, 5000) GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; Is it from the UpDown? If BitAND($wParam, 0xFFFF) = $hUpDown Then ; Create NMUPDOWN structure Local $tStruct = DllStructCreate("hwnd;long;int;long;long", $lParam) ; Is it a change message? If DllStructGetData($tStruct, 3) = 0xFFFFFD2E Then ; $UDN_DELTAPOS ; Alter the change value DllStructSetData($tStruct, 5, 100 * DllStructGetData($tStruct, 5)) EndIf EndIf EndFuncThe NMUPDOWN structure holds: 1 - Handle of UpDown 2 - ControlID of UpDown 3 - Message type sent by UpDown 4 - Current value of UpDown 5 - Change to apply to input (+/-1)Once we intercept the change message all we have to do is set the change value to +/-100 and let Windows do the rest! M23
    1 point
×
×
  • Create New...