Jump to content
Sign in to follow this  
roka

Determing state of checkbox in GUICtrlCreateDate w/ DTS_SHOWNONE

Recommended Posts

roka

Hi there,

I am trying to figure out how to determine the state of the checkbox of GUICtrlCreateDate() when using DTS_SHOWNONE.

Here's some code for testing purposes:

#include <DateTimeConstants.au3>
#include <GuiDateTimePicker.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>


Global $iExpiresOn,     $hExpiresOn

__startGUI()

Func __startGUI()
    $hGUI = GUICreate("GUICtrlCreateDate Test", 200, 100, -1, -1, $GUI_SS_DEFAULT_GUI)
    ; CreateDate CTRL
    $iExpiresOn = GUICtrlCreateDate("", 10, 10, 120, 22, $DTS_SHOWNONE)
    $hExpiresOn = GUICtrlGetHandle($iExpiresOn)
    _GUICtrlDTP_SetFormat($hExpiresOn, "yyyy/MM/dd")
    _GUICtrlDTP_SetSystemTimeEx($hExpiresOn, 0, True)
    GUISetState()
    ; buttons
    $bOK = GUICtrlCreateButton("OK", 10, 40, 40, 22, $BS_FLAT)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    $bClear = GUICtrlCreateButton("Clear", 60, 40, 40, 22, $BS_FLAT)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    
    
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $bClear
                GUICtrlSetState ($iExpiresOn,$GUI_FOCUS)
                Send("{SPACE}")
            Case $bOK
                _doSomething()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>__startGUI

Func _doSomething()
    $expiresOn = GUICtrlRead($iExpiresOn)
    MsgBox(0,"$expiresOn",$expiresOn) ; DEBUG MESSAGE
    
    $tmp = BitAnd(GUICtrlRead($iExpiresOn),$GUI_CHECKED)    
    MsgBox(0,"$tmp",$tmp) ; DEBUG MESSAGE
EndFunc

The conventional way of retrieving the checkbox state doesn't work. Also I searched the forum and couldn't find anything.

I found a way to uncheck the checkbox if needed, but no idea how to test its state.

Any help is much appreciated.

Thanks!

Share this post


Link to post
Share on other sites
guinness

Did this code work when you ran it? Because you're not passing a variable to _GUICtrlDTP_SetSystemTimeEx() correctly. I would also look at

Function:

Func _GUICtrlDTP_IsChecked($iControlID)
    Local $tStruct ; by martin.
    $tStruct = DllStructCreate("ushort[8]")
    Return GUICtrlSendMsg($iControlID, $DTM_GETSYSTEMTIME, 0, DllStructGetPtr($tStruct)) = 0
EndFunc   ;==>_GUICtrlDTP_IsChecked

Working code:

#include <DateTimeConstants.au3>
#include <GuiDateTimePicker.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>


Global $iExpiresOn, $hExpiresOn

__startGUI()

Func __startGUI()
    Local $iDate = 0
    $hGUI = GUICreate("GUICtrlCreateDate Test", 200, 100, -1, -1, $GUI_SS_DEFAULT_GUI)
    ; CreateDate CTRL
    $iExpiresOn = GUICtrlCreateDate("", 10, 10, 120, 22, $DTS_SHOWNONE)
    $hExpiresOn = GUICtrlGetHandle($iExpiresOn)
    _GUICtrlDTP_SetFormat($hExpiresOn, "yyyy/MM/dd")
    _GUICtrlDTP_SetSystemTimeEx($hExpiresOn, $iDate, True)
    GUISetState()
    ; buttons
    $bOK = GUICtrlCreateButton("OK", 10, 40, 40, 22, $BS_FLAT)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    $bClear = GUICtrlCreateButton("Clear", 60, 40, 40, 22, $BS_FLAT)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)


    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $bClear
                GUICtrlSetState($iExpiresOn, $GUI_FOCUS)
                Send("{SPACE}")
            Case $bOK
                _doSomething()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>__startGUI

Func _doSomething()
    $expiresOn = GUICtrlRead($iExpiresOn)
    MsgBox(0, "$expiresOn", $expiresOn) ; DEBUG MESSAGE

    MsgBox(0, "$tmp", _GUICtrlDTP_IsChecked($iExpiresOn)) ; DEBUG MESSAGE
EndFunc   ;==>_doSomething

Func _GUICtrlDTP_IsChecked($iControlID)
    Local $tStruct ; by martin.
    $tStruct = DllStructCreate("ushort[8]")
    Return GUICtrlSendMsg($iControlID, $DTM_GETSYSTEMTIME, 0, DllStructGetPtr($tStruct)) = 0
EndFunc   ;==>_GUICtrlDTP_IsChecked
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
roka

It works in the terms of I'm getting the selected date and I can also set it to a certain date when loading a date from presets for example.

I did try to use GetSystemTimeEx() yesterday, I just forgot to add it in here. Though, the topic you just mentioned is new to me. So I'll give a try with the struct now.

I really like this Date Control, that's why I want to get it to work.

Thanks!

Share this post


Link to post
Share on other sites
guinness

Weird because I'm using the latest beta and it says you're not passing a variable to _GUICtrlDTP_SetSystemTimeEx().

_GUICtrlDTP_SetSystemTimeEx($hWnd, ByRef $tDate[, $fFlag = False])

I updated my previous by creating a function called _GUICtrlDTP_IsChecked() & the information provided by martin.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
roka

I'm actually not using the beta yet. I'm still on latest stable release.

I think I didn't use the handle for the GUICtrlCreateDate yesterday. I only used the return value from _GUICtrlCreateDate which is just the ControlID.

This seems to return @error 0 when checked and @error 1 when unchecked:

#include <DateTimeConstants.au3>
#include <GuiDateTimePicker.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>


Global $iExpiresOn,     $hExpiresOn

__startGUI()

Func __startGUI()
    $hGUI = GUICreate("GUICtrlCreateDate Test", 200, 100, -1, -1, $GUI_SS_DEFAULT_GUI)
    ; CreateDate CTRL
    $iExpiresOn = GUICtrlCreateDate("", 10, 10, 120, 22, $DTS_SHOWNONE)
    $hExpiresOn = GUICtrlGetHandle($iExpiresOn)
    _GUICtrlDTP_SetFormat($hExpiresOn, "yyyy/MM/dd")
    _GUICtrlDTP_SetSystemTimeEx($hExpiresOn, 0, True)
    GUISetState()
    ; buttons
    $bOK = GUICtrlCreateButton("OK", 10, 40, 40, 22, $BS_FLAT)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    $bClear = GUICtrlCreateButton("Clear", 60, 40, 40, 22, $BS_FLAT)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    
    
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $bClear
                GUICtrlSetState ($iExpiresOn,$GUI_FOCUS)
                Send("{SPACE}")
            Case $bOK
                _doSomething()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>__startGUI




Func _doSomething()
    $tmp2 = _GUICtrlDTP_GetSystemTimeEx($hExpiresOn)
    MsgBox(0,"_GUICtrlDTP_GetSystemTimeEx",@Error) ; DEBUG MESSAGE
EndFunc

This might be even easier than using the struct.

I will try to use this in my script and see if it does what I need.

Thanks Guiness! I appreciate your time.

Share this post


Link to post
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
Sign in to follow this  

×