找回密码
 加入
搜索
查看: 2743|回复: 14

[网络通信] 月历控件如何显示指定年月?(己解决)

  [复制链接]
发表于 2016-11-29 21:08:37 | 显示全部楼层 |阅读模式
本帖最后由 xulinghai 于 2016-12-1 23:51 编辑

用GUICtrlCreateMonthCal()建立的月历控件,用_GUICtrlMonthCal_SetCurSel()可以显示指定的年和月,但是......
使用_GUICtrlMonthCal_Create()建立的月历控件,用_GUICtrlMonthCal_SetCurSel()无效,如要立即显示2015年3月的月历,请教大神,如何指定显示年和月?


感 谢afan版主修改的函数,己成功解决!
发表于 2016-11-29 23:39:37 | 显示全部楼层
改造下,看看适用否
Func _GUICtrlMonthCal_SetCurSel_Test($hWnd, $iYear, $iMonth, $iDay)
        Local $tBuffer = DllStructCreate($tagSYSTEMTIME)
        DllStructSetData($tBuffer, "Month", $iMonth)
        DllStructSetData($tBuffer, "Day", $iDay)
        DllStructSetData($tBuffer, "Year", $iYear)
        If IsHWnd($hWnd) Then
                Local $iBuffer = DllStructGetSize($tBuffer)
                Local $tMemMap
                Local $pMemory = _MemInit($hWnd, $iBuffer, $tMemMap)
                _MemWrite($tMemMap, $tBuffer)
                Local $iRet = _SendMessage($hWnd, $MCM_SETCURSEL, 0, $pMemory, 0, "wparam", "ptr")
                _MemFree($tMemMap)
        Else
                $iRet = GUICtrlSendMsg($hWnd, $MCM_SETCURSEL, 0, DllStructGetPtr($tBuffer))
        EndIf
        Return $iRet <> 0
EndFunc   ;==>_GUICtrlMonthCal_SetCurSel_Test
发表于 2016-11-30 00:42:20 | 显示全部楼层
回复 1# xulinghai

是我理解錯誤嗎??

用 說明的範例  只加了一行 不就可以??

_GUICtrlMonthCal_SetCurSel($hMonthCal, 2015, 3, @MDAY)


#include <GuiConstantsEx.au3>
#include <GuiMonthCal.au3>
#include <WindowsConstants.au3>

$Debug_MC = False ; 檢查傳遞給 MonthCal 函數的控制項類名, 設置為 True,並使用另一個控制項控制碼, 查看它的工作

Global $hMonthCal

_Main()

Func _Main()
    Local $hGUI

    ; 創建 GUI
    $hGUI = GUICreate("月(日)曆 UDF 函數演示", 400, 350)
    $hMonthCal = _GUICtrlMonthCal_Create($hGUI, 4, 4, $WS_BORDER)
        

        _GUICtrlMonthCal_SetCurSel($hMonthCal, 2015, 3, @MDAY)
        
    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; 迴圈到用戶退出
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hMonthCal
            Switch $iCode
                Case $MCN_GETDAYSTATE ; 控制項發送請求相關個別日子應該如何顯示的資訊
                    $tInfo = DllStructCreate($tagNMDAYSTATE, $ilParam)
                    _DebugPrint("$MCN_GETDAYSTATE" & @LF & "--> 控制項控制碼:" & @TAB & $hWndFrom & @LF & _
                            "--> 控制項 ID:" & @TAB & $iIDFrom & @LF & _
                            "--> 操作代碼:" & @TAB & $iCode & @LF & _
                            "--> 年:" & @TAB & DllStructGetData($tInfo, "Year") & @LF & _
                            "--> 月:" & @TAB & DllStructGetData($tInfo, "Month") & @LF & _
                            "--> 周:" & @TAB & DllStructGetData($tInfo, "DOW") & @LF & _
                            "--> 日:" & @TAB & DllStructGetData($tInfo, "Day") & @LF & _
                            "--> 時:" & @TAB & DllStructGetData($tInfo, "Hour") & @LF & _
                            "--> 分:" & @TAB & DllStructGetData($tInfo, "Minute") & @LF & _
                            "--> 秒:" & @TAB & DllStructGetData($tInfo, "Second") & @LF & _
                            "--> 毫秒:" & @TAB & DllStructGetData($tInfo, "MSecond") & @LF & _
                            "--> 日顯示狀態:" & @TAB & DllStructGetData($tInfo, "DayState") & @LF & _
                            "--> p日顯示狀態:" & @TAB & DllStructGetData($tInfo, "pDayState"))
                    ; 位址陣列的 MONTHDAYSTATE(DWORD的位欄位,保存一個月內每天的狀態)
                    ; 每個位數(1 到 31)代表一月內對應天的狀態
                    ; 如果有一個數位是啟動的,相應的天將顯示黑粗體,否則將不會重點顯示.
                    ; 沒有返回值
                Case $MCN_SELCHANGE ; 發送控制項當前選定的日期;或日期範圍的變化等消息
                    $tInfo = DllStructCreate($tagNMSELCHANGE, $ilParam)
                    _DebugPrint("$MCN_SELCHANGE" & @LF & "--> 控制項控制碼:" & @TAB & $hWndFrom & @LF & _
                            "--> 控制項 ID:" & @TAB & $iIDFrom & @LF & _
                            "--> 操作代碼:" & @TAB & $iCode & @LF & _
                            "--> 請求年:" & @TAB & DllStructGetData($tInfo, "BegYear") & @LF & _
                            "--> 請求月:" & @TAB & DllStructGetData($tInfo, "BegMonth") & @LF & _
                            "--> 請求周:" & @TAB & DllStructGetData($tInfo, "BegDOW") & @LF & _
                            "--> 請求日:" & @TAB & DllStructGetData($tInfo, "BegDay") & @LF & _
                            "--> 請求時:" & @TAB & DllStructGetData($tInfo, "BegHour") & @LF & _
                            "--> 請求分:" & @TAB & DllStructGetData($tInfo, "BegMinute") & @LF & _
                            "--> 請求秒:" & @TAB & DllStructGetData($tInfo, "BegSecond") & @LF & _
                            "--> 請求毫秒:" & @TAB & DllStructGetData($tInfo, "BegMSeconds") & @LF & _
                            "--> 終止年:" & @TAB & DllStructGetData($tInfo, "EndYear") & @LF & _
                            "--> 終止月:" & @TAB & DllStructGetData($tInfo, "EndMonth") & @LF & _
                            "--> 終止周:" & @TAB & DllStructGetData($tInfo, "EndDOW") & @LF & _
                            "--> 終止日:" & @TAB & DllStructGetData($tInfo, "EndDay") & @LF & _
                            "--> 終止時:" & @TAB & DllStructGetData($tInfo, "EndHour") & @LF & _
                            "--> 終止分:" & @TAB & DllStructGetData($tInfo, "EndMinute") & @LF & _
                            "--> 終止秒:" & @TAB & DllStructGetData($tInfo, "EndSecond") & @LF & _
                            "--> 終止毫秒:" & @TAB & DllStructGetData($tInfo, "EndMSeconds"))
                    ; 沒有返回值
                Case $MCN_SELECT ; 發送使用者在控制項內作出明確的選擇消息
                    $tInfo = DllStructCreate($tagNMSELCHANGE, $ilParam)
                    _DebugPrint("$MCN_SELECT" & @LF & "--> 控制項控制碼:" & @TAB & $hWndFrom & @LF & _
                            "--> 控制項 ID:" & @TAB & $iIDFrom & @LF & _
                            "--> 操作代碼:" & @TAB & $iCode & @LF & _
                            "--> 請求年:" & @TAB & DllStructGetData($tInfo, "BegYear") & @LF & _
                            "--> 請求月:" & @TAB & DllStructGetData($tInfo, "BegMonth") & @LF & _
                            "--> 請求周:" & @TAB & DllStructGetData($tInfo, "BegDOW") & @LF & _
                            "--> 請求日:" & @TAB & DllStructGetData($tInfo, "BegDay") & @LF & _
                            "--> 請求時:" & @TAB & DllStructGetData($tInfo, "BegHour") & @LF & _
                            "--> 請求分:" & @TAB & DllStructGetData($tInfo, "BegMinute") & @LF & _
                            "--> 請求秒:" & @TAB & DllStructGetData($tInfo, "BegSecond") & @LF & _
                            "--> 請求毫秒:" & @TAB & DllStructGetData($tInfo, "BegMSeconds") & @LF & _
                            "--> 終止年:" & @TAB & DllStructGetData($tInfo, "EndYear") & @LF & _
                            "--> 終止月:" & @TAB & DllStructGetData($tInfo, "EndMonth") & @LF & _
                            "--> 終止周:" & @TAB & DllStructGetData($tInfo, "EndDOW") & @LF & _
                            "--> 終止日:" & @TAB & DllStructGetData($tInfo, "EndDay") & @LF & _
                            "--> 終止時:" & @TAB & DllStructGetData($tInfo, "EndHour") & @LF & _
                            "--> 終止分:" & @TAB & DllStructGetData($tInfo, "EndMinute") & @LF & _
                            "--> 終止秒:" & @TAB & DllStructGetData($tInfo, "EndSecond") & @LF & _
                            "--> 終止毫秒:" & @TAB & DllStructGetData($tInfo, "EndMSeconds"))
                    ; 沒有返回值
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "--> 行(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint
发表于 2016-11-30 01:36:48 | 显示全部楼层
真是注重细节啊!
发表于 2016-11-30 10:49:13 | 显示全部楼层
用GUICtrlCreateMonthCal()建立的月历控件,用_GUICtrlMonthCal_SetCurSel()可以显示指定的年和月,但是... ...
xulinghai 发表于 2016-11-29 21:08


是这种效果?



#include <GUIConstantsEx.au3>
#include <GuiMonthCal.au3>
#include <WindowsConstants.au3>

Global $g_idMemo

Example()

Func Example()
    Local $tTime, $idMonthCal

    ; 创建 GUI
    GUICreate("设置选定的日期", 400, 300)
    $idMonthCal = GUICtrlCreateMonthCal("", 4, 4, -1, -1, $WS_BORDER, 0x00000000)

    ; 创建备忘录控件
    $g_idMemo = GUICtrlCreateEdit("", 4, 168, 392, 128)
    GUICtrlSetFont($g_idMemo, 12, 600, 0, "Courier New")
        GUICtrlSetColor(-1, 0x0000FF)
    GUISetState(@SW_SHOW)

    ; 获取/设置当前选择
    _GUICtrlMonthCal_SetCurSel($idMonthCal, 2015, 3, @MDAY)
    $tTime = _GUICtrlMonthCal_GetCurSel($idMonthCal)
    MemoWrite("当前选择 : " & StringFormat("%02d/%02d/%04d", DllStructGetData($tTime, "Month"), _
            DllStructGetData($tTime, "Day"), _
            DllStructGetData($tTime, "Year")))

    ; 循环到用户退出.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

; 写脚本运行消息到备忘录控件
Func MemoWrite($sMessage)
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2016-11-30 12:12:28 | 显示全部楼层
回复 5# chzj589

更换日期的显示才好玩

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2016-11-30 20:04:11 | 显示全部楼层
你们都大牛
 楼主| 发表于 2016-12-1 23:25:27 | 显示全部楼层
回复 3# kk_lee69

运行后还是显示当前年和月
 楼主| 发表于 2016-12-1 23:31:12 | 显示全部楼层
回复 5# chzj589

是需要这种效果,但月历控件是用  _GUICtrlMonthCal_Create()建立的.
 楼主| 发表于 2016-12-1 23:34:17 | 显示全部楼层
回复 2# afan

谢谢afan版主,测试成功,十分感谢。
发表于 2016-12-2 09:47:45 | 显示全部楼层
回复 8# xulinghai

我的不會  那可能要考慮 AU3版本問題 我用的是 3.3.8版 非 3.3.14版
发表于 2016-12-6 12:00:18 | 显示全部楼层
进来学习学习
发表于 2016-12-6 12:02:56 | 显示全部楼层
可以,很有用
发表于 2016-12-6 14:04:14 | 显示全部楼层
真是注重细节啊!
发表于 2019-7-2 15:38:57 | 显示全部楼层
慢慢學習 讓我越來越強大
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-24 11:09 , Processed in 0.082483 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表