Initializing DateTimePicker for Console Application

Initializing DateTimePicker for Console Application

I have a small program (console application) which displays the DateTimePicker control.  When the modeless dialog box is displayed, I want it to show a specified month/day/year, not necessarily the current month/day/year.  Is this possible to do?  Below is a copy of my code.  As soon as the dialog is displayed, the program jumps to the callback routine (DlgMain), where I attempt to set all zeros for the month/day/year.  Any help would be appreciated.

-------------------------------------------------------------------------

        program calendar

        use dflogm
        use dfwin

        implicit none

        include 'resource.fd'

        integer reti
        logical retl
        type (dialog) dlg
        type (T_MSG) mesg
        type (T_SYSTEMTIME) st
        external DlgMain,DlgCancelModeless

c       Initialize Dialog                              
        retl=dlginit(IDD_DIALOG1,dlg)

        retl=DlgSetSub(dlg,IDCANCEL,DlgCancelModeless)

c       Display Dialog                                           
        retl=dlgmodeless(dlg,SW_SHOW)

        call DlgMain(dlg,-1,0)

        do while (GetMessage (mesg,NULL,0,0))
           if (DlgIsDlgMessage(mesg).eqv..false.) then
              retl=TranslateMessage(mesg)
              reti=DispatchMessage(mesg)
           end if
        end do

        retl=DlgSendCtrlMessage(dlg,IDC_DATETIMEPICKER1,
     +                                      DTM_GETSYSTEMTIME,0,LOC(st))

        print *,'Day: ',st%wDay
        print *,'Month: ',st%wMonth
        print *,'Year: ',st%wYear

        call dlgexit(dlg)
        call DlgUninit(dlg)
        call exit ( )

        end

 

c       Subroutine DlgMain                                                                                                                 
c       This subroutine controls the main dialog box.              

        subroutine DlgMain(dlg,id,callbacktype)

        use dflogm
        use dfwin

        implicit none

        include 'resource.fd'

        integer hWnd,id,callbacktype,reti
        logical retl
        type (dialog) dlg
        type (T_SYSTEMTIME) st

c Trying to set all calendar data to zero - but this does not work, calandar still shows current date

        hWnd=GetDlgItem(dlg%hWnd,IDC_DATETIMEPICKER1)
        reti = SendMessage(GetDlgItem(dlg%hWnd, IDC_DATETIMEPICKER1 ),
     +                 MCM_SETCURSEL, 0, LOC(st))

        return
       
        end

 

c       Subroutine DlgCancelModeless                                  
c       This subroutine is used when Cancel button is pushed in a     
c       modeless dialog box.  Used to cancel current dialog and return
c       to main menu.                                              

        subroutine DlgCancelModeless(dlg,id,callbacktype)

        use dflogm
        use dfwin

        implicit none

        include 'resource.fd'

        integer id,callbacktype
        logical retl
        type (dialog) dlg

        call PostQuitMessage(0)

        return

        end

-------------------------------------------------------------------------

 

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Windows communicates with DateTimePicker controls via control-specific messages (DTM_*) and flags which are communicated to the control by the SendMessage() API function, using the control's handle.  Here is how a specific date is set in a DTP (with handle hw_day1), to appear as the default entry when the control is initially presented:


	TYPE(T_SYSTEMTIME)      :: st
st%wYear  = INT2(2000)

	st%wMonth = INT2(1)

	st%wDay   = INT2(1)  
!   initialize the DTP control

	rval = SendMessage (hw_day1, DTM_SETSYSTEMTIME, GDT_VALID, LOC(st))

	

This SendMessage() would be placed in the WM_INITDIALOG block within the proc function of the dialog which contains the DTP control.

Thanks for the reponse, Paul.

I tried to implement what you suggested, without success, so I probably did it wrong.  (I am self taught at all the dialog coding - so, I'm what you would call a beginner.)  I think you lost me a bit on your last sentence ("This SendMessage() would be placed in the WM_INITDIALOG block within the proc function of the dialog which contains the DTP control.")

I place the snippet of code you provide in my DlgMain callback routine, changing variable names where appropriate.  I used the following code:

        integer hWnd,id,callbacktype
        logical retl
        type (dialog) dlg
        type (T_SYSTEMTIME) st
        st%wYear=INT2(2000) 
        st%wMonth=INT2(1) 
        st%wDay=INT2(1)

        hWnd=GetDlgItem(dlg%hWnd,IDC_DATETIMEPICKER1)
        retl = SendMessage (dlg%hWnd, DTM_SETSYSTEMTIME, GDT_VALID,
     +           LOC(st))

        return

The DTP control is unaffected, showing the current date.

I believe I am initiating and or displaying my dialog differently than what you expect (I'm using: retl=dlginit(IDD_DIALOG1,dlg) and retl=dlgmodeless(dlg,SW_SHOW)).  I also do not use a WM_INITDIALOG block (nor have I ever), so I don't really know how that works.  If you or anyone else has a simple example, I would greatly appreciate it!

 

Paul is using win api you are using quickwin. In quickwin if you set a callback for the ID if the dialog itself then when you call dlgmodal (or modeless) and before the dialog is displayed this callback would be called with ID=IDD_DIALOG1 and callbacktype=DLG_INIT. This is the case where you can to some dialog initialisation.... On cancelling (IDCANCEL) or [x] click this callback is called again  with ID=IDD_DIALOG1 and callbacktype=DLG_DESTROY so you can do any tidying up and post a close message for the app etc 

BTW my preference is to have one callback for all the dialog controls and a SELECT CASE construct on ID  for the actions for each possible event.

 

...and before the dialog is displayed this callback would be called with ID=IDD_DIALOG1 and callbacktype=DLG_INIT.

and I should of added that this is the first point it is possible for you to get the handle for the dialog to do any initialisation that might need it.

For starters, SendMessage() needs to communicate with the control's handle, not the containing dialog's handle.  Thus your code SendMessage(dlg%hwnd, ...)   needs to be SendMessage(hWnd, ...) since your variable hWnd is the returned handle to the control.

My point about the proc function relates to how Windows works.  Having no or severely limited access to proc functions (ie, Quickwin) thus limits your ability to develop programs making full use of the Windows GUI.  Perhaps app4619's suggestion on how to game Quickwin to achieve some approximation of processing the WM_INITDIALOG message will provide a suitable location for the SendMessage() initializations.

 

Paul and App4619,

Thanks so much for your help.  I was able to get my program working correctly thanks to your responses.

I suppose down the road I will look into tackling win api for the expanded functionality.  For now quickwin has suited my purposes and has been fairly easy for me to pick up.

App4619,

I will look further into your suggestion to use one callback routine for all dialog controls in conjunction with a SELECT CASE construct.

Leave a Comment

Please sign in to add a comment. Not a member? Join today