dtpicker and empty date
dtpicker and empty date
I cannot get the control to start with an empty date.
dBegDate := ctod('')
REDEFINE DTPicker oBegDate VAR dBegDate ID 101 UPDATE OF oDlg
It always shows the checkbox checked when starting.
It is the same in the sample program "datetime.prg".
dBegDate := ctod('')
REDEFINE DTPicker oBegDate VAR dBegDate ID 101 UPDATE OF oDlg
It always shows the checkbox checked when starting.
It is the same in the sample program "datetime.prg".
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Ok, I created a prg with the code included in that conversation. Linked it into the sample program datetime.prg.
Still did not work. When the control with the empty date ( 3rd control ) is initialized it has the check mark.
It will not start with it unchecked (blank).
It does not work right.
By the way, I had already tried that code in my program with no luck but I thought I would try it again with the sample program.
Still did not work. When the control with the empty date ( 3rd control ) is initialized it has the check mark.
It will not start with it unchecked (blank).
It does not work right.
By the way, I had already tried that code in my program with no luck but I thought I would try it again with the sample program.
I noticed that the code used in the conversation that you linked to refers to a function called setdatepic().
The code calls setdatepic() with 5 parameters, with the 5th one a 0 or 1 depending on whether the date is empty or not.
When I look at the source code for the setdatepic() function it does not make use of the 5th parameter.
Is there an update for this function or other code that I do not have access to that would allow the control to start with no date?
The code calls setdatepic() with 5 parameters, with the 5th one a 0 or 1 depending on whether the date is empty or not.
When I look at the source code for the setdatepic() function it does not make use of the 5th parameter.
Is there an update for this function or other code that I do not have access to that would allow the control to start with no date?
-
- Posts: 824
- Joined: Thu Oct 13, 2005 7:39 am
- Location: Germany
Gale,
here is the updated function in datepick.c
Stefan
here is the updated function in datepick.c
Code: Select all
HB_FUNC( SETDATEPICK ) // ( hWnd, wYear, wMonth, wDay, GTD_NONE )
{
SYSTEMTIME sysTime;
sysTime.wYear = _parni( 2 );
sysTime.wMonth = _parni( 3 );
sysTime.wDay = _parni( 4 );
sysTime.wDayOfWeek = 0;
sysTime.wHour = 0;
sysTime.wMinute = 0;
sysTime.wSecond = 0;
sysTime.wMilliseconds = 0;
SendMessage( ( HWND ) _parnl( 1 ), DTM_SETSYSTEMTIME, _parni(5),
( LPARAM ) &sysTime );
}
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Gale,
This is the modfied Class TDTPicket Method SetDate() using the previous function change:
This is the modfied Class TDTPicket Method SetDate() using the previous function change:
Code: Select all
METHOD SetDate( dDate, lEmpty ) INLINE SetDatePick( ::hWnd, Year( dDate ),;
Month( dDate ), Day( dDate ),;
If( lEmpty != nil .and. lEmpty, 1, 0 ) )
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Gale,
Try it this way. Please include this code in your main PRG:
ACTIVATE DIALOG oDlg ;
ON INIT oBegDate:SetDate( nil, .T. )
Try it this way. Please include this code in your main PRG:
Code: Select all
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
HB_FUNC( SETDATEPICK ) // ( hWnd, wYear, wMonth, wDay, GTD_NONE )
{
SYSTEMTIME sysTime;
sysTime.wYear = hb_parni( 2 );
sysTime.wMonth = hb_parni( 3 );
sysTime.wDay = hb_parni( 4 );
sysTime.wDayOfWeek = 0;
sysTime.wHour = 0;
sysTime.wMinute = 0;
sysTime.wSecond = 0;
sysTime.wMilliseconds = 0;
SendMessage( ( HWND ) hb_parnl( 1 ), DTM_SETSYSTEMTIME, hb_parni(5),
( LPARAM ) &sysTime );
}
#pragma ENDDUMP
ON INIT oBegDate:SetDate( nil, .T. )
Thanks Antonio I have it working now.
I had to add #include <commctrl.h>
I am a little embarrassed because I was placing the #pragma after the include statements. Now life is good. Here is the code I am using.
Datepick.prg
tDtPicker.prg
Thanks everyone,
Gale
I had to add #include <commctrl.h>
I am a little embarrassed because I was placing the #pragma after the include statements. Now life is good. Here is the code I am using.
Datepick.prg
Code: Select all
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#include <commctrl.h>
HB_FUNC( SETDATEPICK ) // ( hWnd, wYear, wMonth, wDay, GTD_NONE )
{
SYSTEMTIME sysTime;
sysTime.wYear = hb_parni( 2 );
sysTime.wMonth = hb_parni( 3 );
sysTime.wDay = hb_parni( 4 );
sysTime.wDayOfWeek = 0;
sysTime.wHour = 0;
sysTime.wMinute = 0;
sysTime.wSecond = 0;
sysTime.wMilliseconds = 0;
SendMessage( ( HWND ) hb_parnl( 1 ), DTM_SETSYSTEMTIME, hb_parni(5),
( LPARAM ) &sysTime );
}
#pragma ENDDUMP
Code: Select all
#include "FiveWin.ch"
#include "constant.ch"
#define COLOR_WINDOW 5
#define COLOR_WINDOWTEXT 8
#define CS_DBLCLKS 8
#define DTS_SHOWNONE 0x0002
#ifdef __XPP__
#define Super ::TControl
#define New _New
#endif
//----------------------------------------------------------------------------//
CLASS TDatePick FROM TControl
CLASSDATA lRegistered
DATA lEmptyDate
METHOD New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, bValid, nClrFore,;
nClrBack, oFont, lDesign, oCursor, lPixel, cMsg, lUpdate,;
bWhen, bChange, nHelpId,lEmp) CONSTRUCTOR
METHOD ReDefine( nId, bSetGet,oWnd, nHelpId, cMsg, lUpdate, bWhen, bValid) CONSTRUCTOR
METHOD cText( cText ) SETGET
METHOD cToChar() INLINE Super:cToChar( "SysDateTimePick32" )
METHOD Initiate( hDlg )
METHOD SetDate( dDate ) // Modificado fgondi
METHOD GetDate() INLINE GetDatePick( ::hWnd )
METHOD LostFocus( hCtrl )
METHOD Change()
METHOD Changed() INLINE ( Eval( ::bSetGet, ::GetDate() ), ::Change() )
METHOD Refresh() INLINE ::SetDate( Eval( ::bSetGet ) )
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, bValid, nClrFore,;
nClrBack, oFont, lDesign, oCursor, lPixel, cMsg, lUpdate,;
bWhen, bChange, nHelpId, lEmp ) Class TDatePick
DEFAULT nRow := 0, nCol := 0,;
oWnd := GetWndDefault(),;
nWidth := 100,;
nHeight := If( oFont != nil, oFont:nHeight, 22 ),;
nClrFore := GetSysColor( COLOR_WINDOWTEXT ),;
nClrBack := GetSysColor( COLOR_WINDOW ),;
oFont := oWnd:oFont,;
nHelpId := 100,;
lDesign := .f.,;
lPixel := .f.,;
lUpdate := .f.,;
lEmp := .t.
::cCaption = ""
::nTop = nRow * If( ! lPixel, BTN_CHARPIX_H, 1 )
::nLeft = nCol * If( ! lPixel, BTN_CHARPIX_W, 1 )
::nBottom = ::nTop + nHeight
::nRight = ::nLeft + nWidth
::nHelpId = nHelpId
::oWnd = oWnd
::oFont = oFont
::bSetGet = bSetGet
::lEmptyDate := lEmp
::lEmptyDate := .t.
if !lEmp
::nStyle = nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP,;
If( lDesign, WS_CLIPSIBLINGS, 0 ) )
else
::nStyle = nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP, DTS_SHOWNONE,;
If( lDesign, WS_CLIPSIBLINGS, 0 ) )
endif
::nId = ::GetNewId()
::lDrag = lDesign
::lCaptured = .f.
::cMsg = cMsg
::lUpdate = lUpdate
::bWhen = bWhen
::bValid = bValid
::bChange = bChange
InitCommon()
if ! Empty( oWnd:hWnd )
::Create( "SysDateTimePick32" )
oWnd:AddControl( Self )
if oFont != nil
::SetFont( oFont )
endif
else
oWnd:DefControl( Self )
endif
if lDesign
::CheckDots()
endif
return Self
//----------------------------------------------------------------------------//
METHOD ReDefine( nId, bSetGet, oWnd, nHelpId, nClrFore, nClrBack,;
oFont, oCursor, cMsg, lUpdate, bWhen, bValid, bChanged ) Class TDatePick
DEFAULT oWnd := GetWndDefault(),;
nClrFore := GetSysColor( COLOR_WINDOWTEXT ),;
nClrBack := GetSysColor( COLOR_WINDOW ),;
lUpdate := .f.
::nId = nId
::hWnd = 0
::nHelpId = nHelpId
::oWnd = oWnd
::oFont = oFont
::oCursor = oCursor
::lCaptured = .f.
::lDrag = .f.
::cMsg = cMsg
::lUpdate = lUpdate
::bWhen = bWhen
::bValid = bValid
::bSetGet = bSetGet
::bChange = bChanged
::lEmptyDate := .t.
InitCommon()
::Register()
oWnd:DefControl( Self )
return Self
METHOD Initiate( hDlg ) Class TDatePick
Super:Initiate( hDlg )
::cText = Eval( ::bSetGet )
return nil
METHOD cText( uVal ) CLASS TDatePick
if PCount() == 1
Eval( ::bSetGet, uVal )
::SetDate( uVal )
::Refresh()
::Change()
endif
return ::GetDate()
//---------------------------------------------------------------------------//
// Controlo si la fecha esta vacia para quitar la marca del checkbox incluido en el campo
// El quinto parametro indica el estado del checkbox. 0 Marcado, 1 Desmarcado.
METHOD SetDate( dDate ) CLASS TDatePick
local dShow
local dDat := dDate
if empty( dDate )
dDat := if( !::lEmptyDate, date(), dDate )
endif
dShow := dDat
SetDatePick( ::hWnd, Year( dShow ), Month( dShow ), Day( dShow ), 0 )
if Empty(dDate)
SetDatePick( ::hWnd, Year( dShow ), Month( dShow ), Day( dShow ), 1 )
endif
return Self
METHOD LostFocus( hCtrl ) CLASS TDatePick
Eval( ::bSetGet, ::cText )
return Super:LostFocus( hCtrl )
METHOD Change() CLASS TDatePick
if ::bChange != nil
Eval( ::bChange, Self )
endif
return nil
Gale
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact: