刘
刘麻子
Unregistered / Unconfirmed
GUEST, unregistred user!
此乃修正后的DatePick单元, 原来那个, 某些结构定义有问题, 感谢lichengbin兄的指点.. ^^<br><br>unit DatePick;<br><br>interface<br><br>uses Windows;<br><br>function DatePick_GetCurSelect(hDatePick: HWND): Integer; // 读取当前选中区域<br>function DatePick_SetCurSelect(hDatePick: HWND; nCur: Integer): Bool; // 设置当前选中区域<br><br>implementation<br><br> // *************************<br>type<br> BitBool = Byte;<br> Calid = DWord;<br> HDPA = Pointer;<br><br> //<br> // common control info stuff<br> //<br>type<br> PControlInfo = ^TControlInfo;<br> TControlInfo = record<br> hWnd: DWord; // HWND<br> hWndParent: HWND;<br> Style: DWord;<br> dwCustom: DWord;<br><br> // BITBOOL bUnicode: 1;<br> // BITBOOL bInFakeCustomDraw: 1;<br> _BitBool: BitBool;<br><br> uiCodePage: uInt;<br> dwExStyle: DWord;<br> iVersion: lResult;<br> wUIState: Word;<br> end;<br><br><br> //<br> // SUBEDITCONTROL stuff<br> //<br>type<br> PSubEdit = ^TSubEdit;<br> TSubEdit = record<br> Id: Integer; // SE_ value above<br> Rc: TRect; // bounding box for display<br><br> pVal: PWord; // current value (in a SYSTEMTIME struct)<br> Min: uInt; // min value<br> Max: uInt; // max value<br> cIncrement: Integer; // increment value<br><br> cchMax: Integer; // max allowed chars<br> cchEdit: Integer; // current number chars entered so far<br> ValEdit: uInt; // value entered so far<br> flDrawText: uInt; // flags for DrawText<br><br> pv: PChar; // formatting string<br> fReadOnly: Bool; // can this subedit be edited (receive focus)?<br> end;<br><br>type<br> PCalendarType = ^TCalendarType;<br> TCalendarType = record<br> _Calid: Calid; // Calendar id number (CAL_GREGORIAN, etc.)<br> _Lcid: LCID; // Usually LOCALE_USER_DEFAULT, but forced to US for unsupported calendars<br> dyrOffset: Integer; // The calendar offset (0 for Gregorian and Era)<br> HdpaYears: HDPA; // If fEra, then array of year info<br> HdpaEras: HDPA; // If fEra, then array of era names<br> end;<br><br>type<br> PSubEditControl = ^TSubEditControl;<br> TSubEditControl = record<br> pCI: PControlInfo; // looks like this guy needs access to the hwnd<br> fNone: Bool; // allow scrolling into SUBEDIT_NONE<br> hFont: DWord; // font to draw text with, HFONT<br> Rc: TRect; // rect for subedits<br> xScroll: Integer; // amount pse array is scrolled<br> iSeCur: Integer; // subedit with current selection (SUBEDIT_NONE for no selection)<br> cse: Integer; // count of subedits in pse array<br> St: TSystemTime; // current time pse represents (pse points into this)<br> szFormat: PChar; // format string as parsed (pse points into this)<br> pSE: PSubEdit; // subedit array<br> cDelimeter: Char; // delimiter between subedits (parsed from fmt string)<br> szDelimeters: array[0..14] of Char; // delimiters between date/time fields (from resfile)<br> Ct: TCalendarType; // information about the calendar, **<br><br> // BITBOOL fMirrorSEC: 1; // Whether or not to mirror the SubEditControls<br> // BITBOOL fSwapTimeMarker: 1; // Whether we need to swap the AM/PM symbol around or not<br> _BitBool: BitBool;<br> end;<br><br><br> //<br> // DATEPICK stuff<br> //<br>const<br> MCSC_COLORCOUNT = 6;<br><br>type<br> PDatePick = ^TDatePick;<br> TDatePick = record<br> CI: TControlInfo; // all controls start with this<br><br> hWndUD: HWND;<br> hWndMC: HWND;<br> hFontMC: HFONT; // font for drop down cal<br><br> Clr: array[0..MCSC_COLORCOUNT-1] of ColorRef;<br><br> // HACK! stMin and stMax must remain in order and adjacent<br> StMin: TSystemTime; // minimum date we allow<br> StMax: TSystemTime; // maximum date we allow<br> StPrev: TSystemTime; // most recent date notified<br> Sec: TSubEditControl; // current date<br><br> RcCheck: TRect; // location of checkbox iff fShowNone<br> Rc: TRect; // size of SEC space<br> RcBtn: TRect; // location of dropdown or updown<br> iseLastActive: Integer; // which subedit was active when we were last active?<br> gdtr: wParam; // Did app set min and/or max? (GDTR_MIN|GDTR_MAX)<br><br> {<br> BITBOOL fEnabled: 1;<br> BITBOOL fUseUpDown: 1;<br> BITBOOL fFocus: 1;<br> BITBOOL fNoNotify: 1;<br> BITBOOL fCapture: 1;<br> BITBOOL fShow: 1; // TRUE iff we should continue to show MonthCal<br><br> BITBOOL fCheck: 1; // TRUE iff the checkbox is checked<br> BITBOOL fCheckFocus: 1; // TRUE iff the checkbox has focus<br><br> BITBOOL fLocale: 1; // TRUE iff the format string is LOCALE dependent<br> BITBOOL fHasMark: 1; // true iff has am/pm in current format<br> BITBOOL fFreeEditing: 1; // TRUE if in the middle of a free-format edit<br> }<br> _BitBool1: BitBool;<br> _BitBool2: BitBool;<br> end;<br><br> // 读取当前选中区域<br>function DatePick_GetCurSelect(hDatePick: HWND): Integer;<br>var<br> x: PDatePick;<br>begin<br> try<br> x := PDatePick(GetWindowLong(hDatePick, 0));<br> Result := x.Sec.iSeCur;<br> except<br> Result := -1;<br> end;<br>end;<br><br> // 设置当前选中区域<br>function DatePick_SetCurSelect(hDatePick: HWND; nCur: Integer): Bool;<br>var<br> x: PDatePick;<br>begin<br> try<br> x := PDatePick(GetWindowLong(hDatePick, 0));<br> x.Sec.iSeCur := nCur;<br> <br> InvalidateRect(hDatePick, nil, True); // 重绘<br><br> Result := True;<br> except<br> Result := False;<br> end;<br>end;<br><br>end.