//calendar 日历控件 import win.ui.ctrl.metaProperty;//导入控件属性元表支持 namespace win.ui.ctrl; class calendar{ ctor(parent,tParam){ if(tParam){ tParam.cls = "SysMonthCal32"; if(tParam.edge) tParam.exstyle |= 0x200/*_WS_EX_CLIENTEDGE*/; if(tParam.msel){ tParam.style |= 2/*_MCS_MULTISELECT*/ } this.pos2 = 0; } } _prenotify = { [0xFFFFFD13/*_MCN_SELCHANGE*/] = function(id,code,ptr,nmhdr){ if( owner.onDateTimeChanged ){ var nm = ..raw.convert(ptr,{ struct hdr = ::NMHDR(); struct selStart = ..time(,this.$setTimeFormat); struct selEnd = ..time(,this.$setTimeFormat); }); owner.onDateTimeChanged(nm. selStart,nm.selEnd,nm); } }; [0xFFFFFFF8/*_NM_KILLFOCUS*/] = function(id,code,ptr,nmhdr){ if( owner.onFocusLost )owner.onFocusLost(); }; [0xFFFFFFF9/*_NM_SETFOCUS*/] = function(id,code,ptr,nmhdr){ if( owner.onFocusGot )owner.onFocusGot(); }; } @_metaProperty; } calendar._metaProperty = metaProperty( getColor = function(ind){ ::SendMessageInt(owner.hwnd,0x100B/*_MCM_GETCOLOR*/,ind,0); }; setColor = function(ind,clr){ ::SendMessageInt(owner.hwnd,0x100A/*_MCM_SETCOLOR*/,ind,clr); }; bgcolor = { _get = function(){ return owner.getColor(0/*_MCSC_BACKGROUND*/) } _set = function(v){ owner.setColor(0/*_MCSC_BACKGROUND*/,v) } }; color = { _get = function(){ return owner.getColor(1/*_MCSC_TEXT*/) } _set = function(v){ owner.setColor(1/*_MCSC_TEXT*/,v) } }; time = { _get = function(){ var tm = ..time(,"%x") var hour,second,minute = tm.hour,tm.second,tm.minute var re,tm = ::SendMessageByStruct(owner.hwnd, 0x1001/*_MCM_GETCURSEL*/,0,..time(,owner.$setTimeFormat)); return ..table.assign(tm,{ hour = hour; second = second; minute = minute; } ) } _set = function( v ){ if(! ..time.istime(v)){ v = ..time(v); if(! ..time.istime(v)) error("无效的time对象",2); } owner.$setTimeFormat = v.format; ::SendMessageByStruct(owner.hwnd, 0x1002/*_MCM_SETCURSEL*/,0, v); } }; setRange = function(tmMin,tmMax){ var flag = 0; if( !tmMin ) tmMin = ..time(); elseif(! ..time.istime(tmMin) ) error("最小时间参数不正确",2) else flag |= 1/*_GDTR_MIN*/ if( !tmMax ) tmMax = ..time(); elseif(! ..time.istime(tmMax) ) error("最大时间参数不正确",2) else flag |= 2/*_GDTR_MAX*/ ::SendMessageByStruct(owner.hwnd,0x1012/*_MCM_SETRANGE*/,flag,{struct tm[2]={tmMin;tmMax} }); } getRange = function( ){ var tm = ..time(); var tmRange = {struct array[2]={ ..time() } } var tmMin,tmMax; var ret = ::SendMessageByStruct(owner.hwnd,0x1011/*_MCM_GETRANGE*/,0,tmRange); if( ret & 1/*_GDTR_MIN*/ ){ tmMin = tmRange.array[1]; } if( ret & 2/*_GDTR_MAX*/ ){ tmMax = tmRange.array[2]; } return tmMin,tmMax }; ) with calendar._metaProperty { value = time; } /***intellisense() ?win.ui.ctrl.calendar =!calendar. win.ui.ctrl.calendar() = 日历控件\n!calendar. !calendar.cls = 设计时类名 !calendar.className = 运行时类名 !calendar.time = 获取或设置时间,值为 time 对象。\n写入属性值时支持可使用 time 构造函数转换为时间对象的参数。\n在读取此属性值时,保留上次设置此属性的时间对象使用的 format 字段\n!time. !calendar.value = 获取或设置时间,值为 time 对象。\n写入属性值时支持可使用 time 构造函数转换为时间对象的参数。\n在读取此属性值时,保留上次设置此属性的时间对象使用的 format 字段\n!time. !calendar.setRange(.(时间下限,时间上限) = 设置时间范围,参数为time()对象\n可省略其中一个参数,仅指定下限或仅指定上限 !calendar.getRange() = 返回两个time()对象:时间范围下限,时间范围上限\n如果未调用setRange()指定上限或下限,相应值返回为空 !calendar.hwnd = 控件句柄 !calendar.id = 控件ID !calendar.text = 控件文本 !calendar._parentForm = 返回创建控件的容器窗口(win.form对象),所有窗口控件都拥有此只读属性。\n对于使用窗体设计器创建的窗口,也就是返回设计时窗体容器。\n\n即使子窗口移除子窗口样式、更改父子关系,或以 orphanWindow显示,\n控件的 _parentForm 始终都不会改变\n!winform. !calendar.getParent() = 返回父窗口\n!static. !calendar.setParent(__/*控件对象*/) = 改变父窗口 !calendar.hide = 控件是否隐藏 !calendar.disabled = 是否禁用 !calendar.left = 左侧坐标 !calendar.right = 右侧坐标 !calendar.top = 顶部坐标 !calendar.bottom = 底部坐标 !calendar.width = 宽度 !calendar.height = 高度 !calendar.redraw() = 刷新 !calendar.show(true__) = 显示控件 !calendar.getRect() = 控件区块位置(::RECT结构体) !calendar.getRect(true) = 控件屏幕区块位置(::RECT结构体) !calendar.setRect(rc) = 设置控件区块位置(::RECT结构体) !calendar.setRect(rc,true) = 设置控件屏幕区块位置(::RECT结构体) !calendar.getClientRect() = 控件客户区块位置(::RECT结构体)\n!rect. !calendar.getFont() = 控件字体(::LOGFONT结构体)\n!logfont. !calendar.setFont(__/*指定字体*/) = 指定LOGFONT字体对象,或逻辑字体句柄 !calendar.setFont(混入字体属性) = @.setFont(point=10;name="宋体"); !calendar.theme = 外观主题,例如\nwinform.button.theme = "Explorer"\nwinform.button.theme = false !calendar.modifyStyle(.(remove,add,swpFlags) = 修改窗口样式,所有参数都是可选参数,\n@remove 用数值指定要移除的样式,可使用 _WS_ 前缀的常量\n@add 用数值指定要添加的样式,可使用 _WS_ 前缀的常量\n@swpFlags 可选用数值指定调整窗口选项,可使用 _SWP_ 前缀的常量\n如果指定了 @swpFlag ,则使用该参数调用::SetWindowPos\n细节请参考 win.modifyStyle 函数源码 !calendar.modifyStyleEx(.(remove,add,swpFlags) = 修改窗口扩展样式,所有参数都是可选参数,\n@remove 用数值指定要移除的样式,可使用 _WS_EX_ 前缀的常量\n@add 用数值指定要添加的样式,可使用 _WS_EX_ 前缀的常量\n@swpFlags 可选用数值指定调整窗口选项,可使用 _SWP_ 前缀的常量\n如果指定了 @swpFlag ,则使用该参数调用::SetWindowPos\n细节请参考 win.modifyStyle 函数源码 !calendar.capture = 是否捕获全局鼠标消息 !calendar.close() = 关闭控件窗口 !calendar.invalidate(__/*可选使用::RECT()对象指定客户区*/) = 使窗口绘图区无效 !calendar.invalidate(__/*可选使用::RECT()对象指定客户区*/,0) = 使窗口绘图区无效\n不刷新背景 !calendar.update() = 重绘invalidate函数指定的区块 !calendar.setFocus() = 设置焦点 !calendar.setPos(.(x坐标,y坐标,宽,高,插入位置,参数) = 调整窗口位置或排序,所有参数可选\n同时指定x,y坐标则移动位置\n同时指定宽高则改变大小\n指定插入位置(句柄或_HWND前缀常量)则调整Z序 !calendar.getPos() = 返回相对坐标,宽,高\nx,y,cx,cy=win.getPos(hwnd) !calendar.sendMessage(.(msg,wParam,lParam) = 发送窗口消息\n此函数用法请参考 ::User32.SendMessage !calendar.postMessage(.(msg,wParam,lParam) = 投递窗口消息到消息队列中\n此函数用法请参考 ::User32.PostMessage !calendar.onDateTimeChanged = @.onDateTimeChanged = function(startTime,endTime){ __/*日期改变时触发此事件,\nstartTime 为开始日期,endTime 为结束日期。\n如果创建控件时指定了 msel 为 true 则允许多选时间范围(不超过一周)。*/ } !calendar.onFocusLost = @.onFocusLost = function(){ __/*控件失去焦点回调此函数*/ } !calendar.onFocusGot = @.onFocusGot = function(){ __/*控件得到焦点回调此函数*/ } _MCM_FIRST=@0x1000/*_MCM_FIRST*/ end intellisense***/