Jump to content

Calendar Select


Deye
 Share

Recommended Posts

 
Thanks to a function called  GUICtrlGetBkColor  by guinness

I have managed to accomplish what I had requested for - Here

#include <GuiConstantsEx.au3>
#include <GuiConstants.au3>
#include <WinAPI.au3>
#include <WinAPIGdi.au3>


Global  $icontrol, $iNumber
$hGUI = GUICreate("Select days of the month", 290, 240, -1, -1)
GUISetFont(9, 0, 4, "Comic Sans MS", 2)
$Button1 = GUICtrlCreateButton("Return", 55, 180, 80, 40)
$Button2 = GUICtrlCreateButton("Cancel", 160, 180, 80, 40)

Local $IX = 10
Local $IY = 10
Dim $iRcntrls[29][3]

For $i = 1 To 28
    If $IX = 290 Then
        $IX = 10
        $IY += 40
    EndIf
    $iRcntrls[$i][0] = GUICtrlCreateGraphic($IX, $IY, 30, 30)
    $iRcntrls[$i][1] = GUICtrlGetHandle($iRcntrls[$i][0])
    GUICtrlSetBkColor(-1, 0xffffff)

    GUICtrlCreateLabel($i, $IX + 4, $IY + 4, 22, 22)
    GUICtrlSetBkColor(-1, 0xffffff)
    $IX += 40
Next

GUISetState()


_demo()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $Button1
            $icontrol = ""
            For $i = 1 To 28
                If $iRcntrls[$i][2] Then
                    $icontrol &= $i & ","
                EndIf
            Next
            MsgBox(0, "", StringTrimRight($icontrol, 1))

        Case $Button2
            $iRcntrls = 0
            ExitLoop

        Case $iRcntrls[1][0] To $iRcntrls[28][0]
            For $i = 1 To 28
                If $msg = $iRcntrls[$i][0] Then
                    If GUICtrlGetBkColor($iRcntrls[$i][0]) = 0X1BDC8 Then
                        $iRcntrls[$iNumber][2] = ""
                        GUICtrlSetBkColor($iRcntrls[$iNumber][0], 0xffffff)
                        GUICtrlSetBkColor($iRcntrls[$iNumber][0] + 1, 0xffffff)
                    Else
                        GUICtrlSetBkColor($iRcntrls[$iNumber][0], 0X1BDC8)
                        GUICtrlSetBkColor($iRcntrls[$iNumber][0] + 1, 0X1BDC8)
                        $iRcntrls[$iNumber][2] = True
                    EndIf
                EndIf
            Next
    EndSwitch
WEnd

Func _demo()
    For $i = 1 To 28
        ControlClick("", "", $iRcntrls[$i][1])
        $i += 2
    Next
EndFunc   ;==>_demo

Func GUICtrlGetBkColor($hWnd) ; by guinness (moded)
    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
    EndIf
    For $i = 1 To 28; mod =>
        If $hWnd = $iRcntrls[$i][1] Then
            $iNumber = $i
        EndIf
    Next;  mod <=
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $iColor = _WinAPI_GetPixel($hDC, 0, 0)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $iColor
EndFunc   ;==>GUICtrlGetBkColor

 

Edited by Deye
Link to comment
Share on other sites

No need to get the ctrl bkground color ! ;)

#Region    ;************ Includes ************
#include <GuiConstantsEx.au3>
#include <WinAPIGdi.au3>
#EndRegion ;************ Includes ************

Opt ( 'MustDeclareVars', 1 )

Global  $icontrol, $iNumber, $hGUI, $Button1, $Button2, $msg, $iDayCount = 31

$hGUI = GUICreate("Select days of the month", 290, 260, -1, -1)
GUISetFont(9, 0, 4, "Comic Sans MS", 2)
$Button1 = GUICtrlCreateButton("Return", 55, 210, 80, 40)
$Button2 = GUICtrlCreateButton("Cancel", 160, 210, 80, 40)
Local $IX = 10, $IY = 10
Dim $aRcntrls[$iDayCount+1][3]
For $i = 1 To $iDayCount
    If $IX = 290 Then
        $IX = 10
        $IY += 40
    EndIf
    $aRcntrls[$i][0] = GUICtrlCreateGraphic($IX, $IY, 30, 30)
    $aRcntrls[$i][1] = GUICtrlGetHandle($aRcntrls[$i][0])
    GUICtrlSetBkColor(-1, 0xffffff)
    GUICtrlCreateLabel($i, $IX + 4, $IY + 4, 22, 22)
    GUICtrlSetBkColor(-1, 0xffffff)
    If Mod ( $i -1, 3 ) = 0 Then
        GUICtrlSetBkColor ( $aRcntrls[$i][0], 0X1BDC8 )
        GUICtrlSetBkColor ( $aRcntrls[$i][0] +1, 0X1BDC8 )
        $aRcntrls[$i][2] = True
    EndIf
    $IX += 40
Next
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE, $Button2
            $aRcntrls = 0
            Exit
        Case $Button1
            $icontrol = ""
            For $i = 1 To $iDayCount
                If $aRcntrls[$i][2] Then $icontrol &= $i & ","
            Next
            MsgBox(0, "", StringTrimRight($icontrol, 1))
        Case $aRcntrls[1][0] To $aRcntrls[$iDayCount][0]
            For $i = 1 To $iDayCount
                If $msg = $aRcntrls[$i][0] Then
                    If $aRcntrls[$i][2] = True Then
                        $aRcntrls[$i][2] = ""
                        GUICtrlSetBkColor($aRcntrls[$i][0], 0xffffff)
                        GUICtrlSetBkColor($aRcntrls[$i][0] + 1, 0xffffff)
                    Else
                        GUICtrlSetBkColor($aRcntrls[$i][0], 0X1BDC8)
                        GUICtrlSetBkColor($aRcntrls[$i][0] + 1, 0X1BDC8)
                        $aRcntrls[$i][2] = True
                    EndIf
                EndIf
            Next
    EndSwitch
    Sleep ( 10 )
WEnd

 

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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...