dtpicker and empty date

dtpicker and empty date

Postby Gale FORd » Wed May 02, 2007 5:25 pm

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".
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby Antonio Linares » Wed May 02, 2007 7:02 pm

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42100
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Gale FORd » Wed May 02, 2007 8:23 pm

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.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby Gale FORd » Wed May 02, 2007 10:42 pm

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?
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby StefanHaupt » Thu May 03, 2007 7:55 am

Gale,

here is the updated function in datepick.c

Code: Select all  Expand view  RUN
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 );
}


Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Postby Antonio Linares » Thu May 03, 2007 9:45 am

Gale,

This is the modfied Class TDTPicket Method SetDate() using the previous function change:
Code: Select all  Expand view  RUN
   METHOD SetDate( dDate, lEmpty ) INLINE SetDatePick( ::hWnd, Year( dDate ),;
                                  Month( dDate ), Day( dDate ),;
                                  If( lEmpty != nil .and. lEmpty, 1, 0 ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42100
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Gale FORd » Thu May 03, 2007 3:16 pm

I'm sorry but I cannot get this to work. I get errors trying to compile the c code provided.

Also, DTPicker does not call setdate() with the second parameter anywhere that I could see.

Does anybody have this working?
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby Gale FORd » Thu May 03, 2007 4:20 pm

I appreciate the code Stefan but I use xHarbour professional and I cannot get the code to compile without errors.

Gale
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby Gale FORd » Thu May 03, 2007 7:51 pm

Would someone send me a compiled datepick.c that include the changes above.

I will try to work out the rest.

Thanks,
Gale
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby Antonio Linares » Thu May 03, 2007 7:56 pm

Gale,

Try it this way. Please include this code in your main PRG:

Code: Select all  Expand view  RUN
#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

ACTIVATE DIALOG oDlg ;
ON INIT oBegDate:SetDate( nil, .T. )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42100
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Gale FORd » Thu May 03, 2007 8:43 pm

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
Code: Select all  Expand view  RUN
#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


tDtPicker.prg
Code: Select all  Expand view  RUN
#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


Thanks everyone,
Gale
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby Antonio Linares » Thu May 03, 2007 9:25 pm

Gale,

glad to know you got it working :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42100
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 95 guests

cron