Jump to content

Combobox down arrow execute another function


Siwa
 Share

Recommended Posts

Hello autoit community, 

I want to execute a function when the combo box down arrow in clicked. I don't want it to show the dropdown list at all. I searched the forum, but I did not find any suitable source to work on.

I just want to show some text as the current date inside the combo box, and then when the dropdown arrow is pressed, I want it to show another GUI. I have created my own Data Picker calendar with JavaScript, and I want it to be displayed when the down arrow is clicked.

Is there a possibility perform this action ?

 

Link to comment
Share on other sites

  • Siwa changed the title to Combobox down arrow execute another function
53 minutes ago, Siwa said:

I don't want it to show the dropdown list at all

Isn't that an abnormal behavior for a Windows control ?  Why don't you simply use a Label box or something more appropriate ?  Just asking...

Link to comment
Share on other sites

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <WinAPI.au3>
#Include <Misc.au3>
#include <Date.au3>

Global $Persian_JS_Date
Local $hDLL = DllOpen("user32.dll")
Local $AlphaKey = 1 ; the transparent color of your choice


$Main_GUI = GUICreate(550,500)
$Show_Calendar = GUICtrlCreateButton("Show Calendar",350,150,100,50)
$Combo_Box = GUICtrlCreateCombo(_NowDate ( ),350,250,100,50)

$Date_GUI = GUICreate("Persian Calendar", 330, 255, -1, -1, $WS_POPUP+$WS_CLIPCHILDREN, $WS_EX_LAYERED)
GUISetBkColor($AlphaKey, $Date_GUI)
_WinAPI_SetLayeredWindowAttributes($Date_GUI, $AlphaKey , 0, $LWA_COLORKEY)

$Persian_Date_IE = _IECreateEmbedded()


$Persian_Calendar_Obect = GUICtrlCreateObj($Persian_Date_IE, -20, -63, 1000, 1000)
_IENavigate($Persian_Date_IE, @ScriptDir & "\ShamsiCalendar\jalali.html")
$Persian_Date_IE.document.body.style.backgroundColor = $AlphaKey


GUISetState(@SW_SHOW,$Main_GUI)

$Date_GUI_Close = GUICreate("Persian Calendar Close",200,200, 50, 24,$WS_POPUP+$WS_CLIPSIBLINGS ,$WS_EX_LAYERED,$Date_GUI)
GUISetBkColor($AlphaKey, $Date_GUI_Close)
GUISwitch($Date_GUI_Close)
_WinAPI_SetLayeredWindowAttributes($Date_GUI_Close, $AlphaKey , 0, $LWA_COLORKEY)
$Exit_Button_Calendar_GUI = GUICtrlCreateButton("Close", 0, 0, 50, 24)



While 1
    GUISwitch($Date_GUI)
    $msg = GUIGetMsg()

    Switch $msg
        Case $Exit_Button_Calendar_GUI
            GUISetState(@SW_HIDE,$Date_GUI)
            GUISetState(@SW_HIDE,$Date_GUI_Close)
            GUISwitch($Main_GUI)
        Case $Show_Calendar
            GUISetState(@SW_SHOW,$Date_GUI)
            GUISetState(@SW_SHOW,$Date_GUI_Close)

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch


    $Persian_JS_Date = 0
    $nLeftclicks = 0
    If _IsPressed("01", $hDLL) Then ;If left mouse button pressed
        $Pos = MouseGetPos() ;Get mouse position
        Do
            While (_IsPressed("01", $hDLL)) ;Wait until user releases button
                Sleep(10)
            WEnd
            $nLeftclicks += 1 ;Increment click count
            sleep(100) ;Wait for 100ms
            $aTemp = MouseGetPos() ;Get new mouse position again
        Until(Not ($aTemp[0] = $Pos[0] and $aTemp[1] = $Pos[1] and _IsPressed("01", $hDLL))) ;Loop until mouse is on a new position or it is not pushed again
    EndIf


    If  $nLeftclicks = "2" and $Persian_Date_IE.document.getElementById('display_area_1').innertext<> "1399" Then
        $Persian_JS_Date = $Persian_Date_IE.document.getElementById('display_area_1').innertext
        $cDate = $Persian_JS_Date
        MsgBox(0,"",$cDate)
        $Persian_Date_IE.document.getElementById('display_area_1').innertext = '1399';
        GUISetState(@SW_HIDE,$Date_GUI)
        Exit
    EndIf

    $winpos = WinGetPos($Date_GUI)
    WinMove("Persian Calendar Close", "", $winpos[0] + $winpos[2], $winpos[1])

WEnd

Sorry for the mess, it is a part of another log code.

I want to show the GUI when the down arrow of the combo box is clicked instead of the button. 

Link to comment
Share on other sites

It doesn't work well for me.  Calendar is cropped and overlaps other controls.  But this is not important for your issue.  I would think that my first impression of using a label box would work far better than a pseudo-combo-box. 

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <WinAPI.au3>
#include <Misc.au3>
#include <Date.au3>

Global $Persian_JS_Date
Local $hDLL = DllOpen("user32.dll")
Local $AlphaKey = 0xFFFF00 ; the transparent color of your choice


$Main_GUI = GUICreate("", 550, 500)
$Show_Calendar = GUICtrlCreateButton("Show Calendar", 350, 150, 100, 50)
$idBox = GUICtrlCreateLabel(_NowDate(), 350, 250, 100, 50, $SS_SUNKEN + $SS_CENTER + $SS_CENTERIMAGE)

$Date_GUI = GUICreate("Persian Calendar", 330, 255, -1, -1, $WS_POPUP + $WS_CLIPCHILDREN, $WS_EX_LAYERED)
GUISetBkColor($AlphaKey, $Date_GUI)
_WinAPI_SetLayeredWindowAttributes($Date_GUI, $AlphaKey, 0, $LWA_COLORKEY)

$Persian_Date_IE = _IECreateEmbedded()


$Persian_Calendar_Obect = GUICtrlCreateObj($Persian_Date_IE, -20, -63, 1000, 1000)
_IENavigate($Persian_Date_IE, @ScriptDir & "\jalali.html")
$Persian_Date_IE.document.body.style.backgroundColor = $AlphaKey


GUISetState(@SW_SHOW, $Main_GUI)

$Date_GUI_Close = GUICreate("Persian Calendar Close", 200, 200, 50, 24, $WS_POPUP + $WS_CLIPSIBLINGS, $WS_EX_LAYERED, $Date_GUI)
GUISetBkColor($AlphaKey, $Date_GUI_Close)
GUISwitch($Date_GUI_Close)
_WinAPI_SetLayeredWindowAttributes($Date_GUI_Close, $AlphaKey, 0, $LWA_COLORKEY)
$Exit_Button_Calendar_GUI = GUICtrlCreateButton("Close", 0, 0, 50, 24)



While 1
  GUISwitch($Date_GUI)
  $msg = GUIGetMsg()

  Switch $msg
    Case $Exit_Button_Calendar_GUI
      GUISetState(@SW_HIDE, $Date_GUI)
      GUISetState(@SW_HIDE, $Date_GUI_Close)
      GUISwitch($Main_GUI)
    Case $Show_Calendar
      GUISetState(@SW_SHOW, $Date_GUI)
      GUISetState(@SW_SHOW, $Date_GUI_Close)

    Case $GUI_EVENT_CLOSE
      Exit
    Case $idBox
      ConsoleWrite("Box has been clicked" & @CRLF)
      ; do your stuff here

  EndSwitch


  $Persian_JS_Date = 0
  $nLeftclicks = 0
  If _IsPressed("01", $hDLL) Then   ;If left mouse button pressed
    $Pos = MouseGetPos()     ;Get mouse position
    Do
      While (_IsPressed("01", $hDLL))       ;Wait until user releases button
        Sleep(10)
      WEnd
      $nLeftclicks += 1       ;Increment click count
      Sleep(100)       ;Wait for 100ms
      $aTemp = MouseGetPos()       ;Get new mouse position again
    Until (Not ($aTemp[0] = $Pos[0] And $aTemp[1] = $Pos[1] And _IsPressed("01", $hDLL)))    ;Loop until mouse is on a new position or it is not pushed again
  EndIf


  If $nLeftclicks = "2" And $Persian_Date_IE.document.getElementById('display_area_1').innertext <> "1399" Then
    $Persian_JS_Date = $Persian_Date_IE.document.getElementById('display_area_1').innertext
    $cDate = $Persian_JS_Date
    MsgBox(0, "", $cDate)
    $Persian_Date_IE.document.getElementById('display_area_1').innertext = '1399'    ;
    GUISetState(@SW_HIDE, $Date_GUI)
    Exit
  EndIf

  $winpos = WinGetPos($Date_GUI)
  WinMove("Persian Calendar Close", "", $winpos[0] + $winpos[2], $winpos[1])

WEnd

Also I would personally write an autoit calendar instead of using the JS code. 

Link to comment
Share on other sites

I recently created a calendar with small effort, I know it is not perfect for you but I suppose it can get you a start up :

 

The displayed picture is now wrong but I do not have the ability to change it.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...