► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <staticconstants.au3>
#include <StructureConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
#include <Array.au3>
$gui = GUICreate("Tableau", 1080, 500,-1,-1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX))
GUISetBkColor(0xcccccc)
GUICtrlCreateLabel("Exemple de Tableau",440,20,400,30)
GUICtrlSetFont(-1,16,600)
$fillehaut=360
$fille = GUICreate("fille", 1040, $fillehaut, 15, 70, $WS_CHILD, $WS_EX_CLIENTEDGE, $gui)
GUISetState()
GUICtrlSetResizing($fille, $GUI_DOCKALL)
$larg = 30
$haut = 30
$ajout = 60
$marge = 20
$top = 80
$nblig = 64
$nbcol = 31
$vlabs = StringSplit("Janvier Février Mars Avril Mai Juin Juillet Août Septembre Octobre Novembre Décembre ", " ")
Dim $vlabs[$nblig+2]
For $i=1 To $nblig
$vlabs[$i]="L"& ($i-1)
Next
$hlabs = StringSplit("01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ", " ")
For $n = 1 To $nblig+1
GUICtrlCreateLabel("", $marge, $top+$n*$haut, $larg*$nbcol+$ajout, 2)
GUICtrlSetBkColor(-1, 0xaaaaaa)
If $n<=$nblig Then
GUICtrlCreateLabel($vlabs[$n], $marge+2, $top+9+$n*$haut)
EndIf
Next
For $n = 1 To $nbcol+1
GUICtrlCreateLabel("", $marge+($n-1)*$larg+$ajout, $top, 1, ($nblig+1)*$haut)
GUICtrlSetBkColor(-1, 0xaaaaaa)
GUICtrlCreateLabel($hlabs[$n], $marge+11+($n+1)*$larg, $top+8)
Next
$nbcellules=$nbcol*$nblig+1
Dim $lab[$nbcellules]
$index = 1
For $n = 1 To $nblig
For $p = 1 To $nbcol
$lab[$index] = GUICtrlCreateLabel("", $marge+($p-1)*$larg+$ajout+2, $top+2+$n*$haut, $larg-3, $haut-3, BitOR($SS_NOTIFY,$SS_CENTER))
$index+=1;
GUICtrlSetBkColor(-1, 0xffffff)
Next
Next
For $n = 1 To 30
GUICtrlSetBkColor($lab[Random(0, $nbcol*$nblig, 1)], 0x0000ff)
Next
For $n = 1 To 30
GUICtrlSetBkColor($lab[Random(0, $nbcol*$nblig, 1)], 0x8888ff)
Next
For $n = 1 To 30
$tmp=Random(0, $nbcol*$nblig, 1)
GUICtrlSetData($lab[$tmp], "ABC" &@CRLF& "123")
GUICtrlSetFont($lab[$tmp],8)
GUICtrlSetBkColor($lab[$tmp], 0x88ff88)
Next
For $n = 1 To 30
$tmp=Random(0, $nbcol*$nblig, 1)
GUICtrlSetBkColor($lab[$tmp], 0xffff00)
$ta=getlc($tmp)
GUICtrlSetData($lab[$tmp], 'L'& $ta[0] &@CRLF& 'C'& $ta[1])
GUICtrlSetFont($lab[$tmp],8,800,4)
GUICtrlSetColor($lab[$tmp],0xff0000)
Next
For $n = 1 To 30
GUICtrlSetBkColor($lab[Random(0, $nbcol*$nblig, 1)], 0xffff77)
Next
For $n = 1 To 30
$tmp=Random(0, $nbcol*$nblig, 1)
GUICtrlSetBkColor($lab[$tmp], 0xff8888)
Next
GUISwitch($gui)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")
GUISetState()
$tmp = Int((($nblig+1)*$haut+$top)/$fillehaut*22)
_GUIScrollBars_Init($fille,-1,$tmp)
;_GUIScrollBars_Init($gui)
While 1
$Msg = GUIGetMsg()
If $Msg = -3 Then Exit
If $Msg=0 Then
Sleep(12)
ContinueLoop
EndIf
Switch $Msg
Case $lab[1] To $lab[$nbcellules-1]
$labNo = 0
For $n = 1 To $nbcellules
If $Msg = $lab[$n] Then
$labNo = $n
ExitLoop
EndIf
Next
If $labNo <> 0 Then
$ta=getlc($labNo)
$lig=$ta[0]
$col=$ta[1]
MsgBox(262144, "Vous avez cliqué sur", " Lig "& $lig &" - Col "& $col &" "&$hlabs[$col] &" "& $vlabs[$lig+1] &" ",2)
GUICtrlSetBkColor($Msg, 0x00FF00)
EndIf
EndSwitch
Sleep(12)
WEnd
GUIDelete($gui)
Exit
Func getlc($num, $nbc=$nbcol)
$lig = Int(($num-1)/$nbc)
$col = $num-($lig*$nbc)
Local $aret[2]=[$lig,$col]
return $aret
EndFunc
Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
#forceref $Msg, $wParam
Local $index = -1, $yChar, $xChar, $xClientMax, $xClient, $yClient, $ivMax
For $x = 0 To UBound($aSB_WindowInfo) - 1
If $aSB_WindowInfo[$x][0] = $hWnd Then
$index = $x
$xClientMax = $aSB_WindowInfo[$index][1]
$xChar = $aSB_WindowInfo[$index][2]
$yChar = $aSB_WindowInfo[$index][3]
$ivMax = $aSB_WindowInfo[$index][7]
ExitLoop
EndIf
Next
If $index = -1 Then Return 0
Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)
; Retrieve the dimensions of the client area.
$xClient = BitAND($lParam, 0x0000FFFF)
$yClient = BitShift($lParam, 16)
$aSB_WindowInfo[$index][4] = $xClient
$aSB_WindowInfo[$index][5] = $yClient
; Set the vertical scrolling range and page size
DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
DllStructSetData($tSCROLLINFO, "nMin", 0)
DllStructSetData($tSCROLLINFO, "nMax", $ivMax)
DllStructSetData($tSCROLLINFO, "nPage", $yClient / $yChar)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
; Set the horizontal scrolling range and page size
DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
DllStructSetData($tSCROLLINFO, "nMin", 0)
DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar)
DllStructSetData($tSCROLLINFO, "nPage", $xClient / $xChar)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
Return $GUI_RUNDEFMSG
EndFunc
Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam)
#forceref $Msg, $lParam
Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
Local $index = -1, $xChar, $xPos
Local $Min, $Max, $Page, $Pos, $TrackPos
For $x = 0 To UBound($aSB_WindowInfo) - 1
If $aSB_WindowInfo[$x][0] = $hWnd Then
$index = $x
$xChar = $aSB_WindowInfo[$index][2]
ExitLoop
EndIf
Next
If $index = -1 Then Return 0
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ)
$Min = DllStructGetData($tSCROLLINFO, "nMin")
$Max = DllStructGetData($tSCROLLINFO, "nMax")
$Page = DllStructGetData($tSCROLLINFO, "nPage")
; Save the position for comparison later on
$xPos = DllStructGetData($tSCROLLINFO, "nPos")
$Pos = $xPos
$TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
#forceref $Min, $Max
Switch $nScrollCode
Case $SB_LINELEFT ; user clicked left arrow
DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
Case $SB_LINERIGHT ; user clicked right arrow
DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
Case $SB_THUMBTRACK ; user dragged the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
EndSwitch
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
;// If the position has changed, scroll the window and update it
$Pos = DllStructGetData($tSCROLLINFO, "nPos")
If ($Pos <> $xPos) Then _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0)
Return $GUI_RUNDEFMSG
EndFunc
Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
#forceref $Msg, $wParam, $lParam
Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
Local $index = -1, $yChar, $yPos
Local $Min, $Max, $Page, $Pos, $TrackPos
For $x = 0 To UBound($aSB_WindowInfo) - 1
If $aSB_WindowInfo[$x][0] = $hWnd Then
$index = $x
$yChar = $aSB_WindowInfo[$index][3]
ExitLoop
EndIf
Next
If $index = -1 Then Return 0
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
$Min = DllStructGetData($tSCROLLINFO, "nMin")
$Max = DllStructGetData($tSCROLLINFO, "nMax")
$Page = DllStructGetData($tSCROLLINFO, "nPage")
; Save the position for comparison later on
$yPos = DllStructGetData($tSCROLLINFO, "nPos")
$Pos = $yPos
$TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
Switch $nScrollCode
Case $SB_TOP ; user clicked the HOME keyboard key
DllStructSetData($tSCROLLINFO, "nPos", $Min)
Case $SB_BOTTOM ; user clicked the END keyboard key
DllStructSetData($tSCROLLINFO, "nPos", $Max)
Case $SB_LINEUP ; user clicked the top arrow
DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
Case $SB_LINEDOWN ; user clicked the bottom arrow
DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
Case $SB_THUMBTRACK ; user dragged the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
EndSwitch
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
;// If the position has changed, scroll the window and update it
$Pos = DllStructGetData($tSCROLLINFO, "nPos")
If ($Pos <> $yPos) Then
_GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
$yPos = $Pos
EndIf
Return $GUI_RUNDEFMSG
EndFunc
- - il n'y a pas 8 lignes, mais 64, numérotées de 0 à 63 ; cela explique que l'on ne peut pas utiliser les noms des mois, vu qu'il n'y a pas 64 mois dans l'année.
- - ce n'est pas un calendrier, mais un tableau.
- - il y a deux fenêtres (GUI) ; une globale, l'autre "fille" (child) ; cela explique les deux GUISetState et l'utilisation de GUIswitch
- - le tableau n'est qu'une partie de l'exemple ; la gestion de l'ascenceur dans une partie du GUI (fenêtre fille) est une autre partie.
- - la prise en compte du clic sur une case, et le changement de couleur à la volée font aussi partie de l'exemple.
- - ce n'est qu'un exemple, et surtout pas une application.