Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Month Calendar Control question

Intel_C_Intel
Employee
669 Views
Can anybody help me in retrieving a date value using the "Month Calendar" dialog control with CVF version 6.6A? I can get the control to appear and all its buttons function but am unable to figure out how to retrieve the selected date.
I used the code fragment for initializing common controls:
type (T_INITCOMMONCONTROLSEX) iccex
integer*4               ret
logical*4               lret
iccex.dwSize = sizeof(iccex)
iccex.dwICC = ICC_DATE_CLASSES
call initcommoncontrolsex(iccex)

before initializing the dialog as descibed in Norman Lawrence's book, Compaq Visual Fortran. Unfortunately, his example (Calendar) in the book and on the Digital Press download site did not show how a value is retrieved.
Do I use the Module Wizard or something in order to generate the valid Control Indices to use in DlgGet calls?

Harry
0 Kudos
7 Replies
Jugoslav_Dujic
Valued Contributor II
669 Views
See MCM_GETCURSEL message (for DateTimePicker controls, it is DTM_GETSYSTEMTIME).
0 Kudos
Intel_C_Intel
Employee
669 Views
Thanks, Jugoslav. But I guess I don't understand how to pass the MCM_GETCURSEL message if I'm using a Modal dialog. Can I use the functions SendMessage and GetMessage within the context of a Modal dialog?

Harry Bell
0 Kudos
Jugoslav_Dujic
Valued Contributor II
669 Views
Is that sample DFLOGM-based or API-based?

As for DFLOGM, SendMessage works in modal dialogs, but only in context of callback routines; it doesn't work before or after DlgModal. If you just want to pick up the time after click on OK, create a callback for OK button:
i = DlgSetSub(Dlg, IDOK, OnOK)
...
SUBROUTINE OnOK(Dlg,ID,iEvent)
USE DFLOGM
USE DFWIN
TYPE(DIALOG):: Dlg
INTEGER::  ID, iEvent, i
TYPE(T_SYSTEMTIME)::  ST
INCLUDE "Resource.fd"
i = SendMessage(GetDlgItem(Dlg%hWnd, IDC_MONTH), &
    MCM_GETCURSEL, 0, LOC(ST))
!Do something with members of ST
i = DlgExit(Dlg, ID)
END SUBROUTINE OnOK

Similarly, if you want to initialize the control, create a dialog-initialization callback and use MCM_SETCURSEL from there.

If it's API-based, do the retrieval/validation on CASE (WM_COMMAND)/IDOK before EndDialog in the similar manner.

Jugoslav
0 Kudos
Intel_C_Intel
Employee
669 Views
Norman Lawrence's Calendar sample program (see Compaq Visual Fortran Examples by N Lawrence Digital Press)is not DFLOGM-based (it includes no "USE DFLOGM" command).
The SendMessage function worked perfectly as coded above. Thanks again, Yugoslav!

Harry
0 Kudos
Intel_C_Intel
Employee
669 Views
Now I would like to use the Month Calendar Control with a "buddy" edit box control such that with each click on the Month Calendar control the "buddy" control is updated to agree with the latest selection in the Month Calendar control. Can this be done with DFLOGM mode in a modal dialog? I think it would involve detecting the windows message MCM_SELCHANGE from inside a callback function that had been triggered by DlgSetSub(dlg, IDC_EDIT1, DLG_GAINFOCUS) where IDC_EDIT1 is the buddy edit box ID.
If I get this last piece of my date-picker project worked out I think I will paste the code fragment in this thread.
The other refinement that I've largely worked out now is making the Month Calendar control only appear when the buddy edit box is entered then diappear when the buddy edit box loses focus.

Harry Bell
0 Kudos
Jugoslav_Dujic
Valued Contributor II
669 Views
No, you can't handle MCN_SELCHANGE with DFLOGM. The problem with DFLOGM is that it can't handle an arbitrary message to/from an arbitrary control class. One workaround is to use ActiveX version of MonthCal from comctl32.ocx, but it's an overkill; the other is to tweak DFLOGM.f90 to allow handling of non-supported messages (it's not very complicated, define your own control type, e.g. "ctrl_monthcal", then search for e.g. "ctrl_checkbox", and add code with parallel functionality).

Jugoslav
0 Kudos
hbell
Beginner
669 Views
Here is the MONTHCALENDAR callback routine that I got to work with much help from Jugoslav Dujic's modified DFLOGM.F90 called XFLOGM (XFTfile.f90). Actually, I wound up editing my own DFLOGM.f90 file because my CVF version is later than Jugoslav's.
SUBROUTINE CalendarAid( dlg, id, callbacktype )
use user32
use xflogm2
use comctl32

implicit none

type (dialog) dlg
integer id, callbacktype
integer(4) ret
character*12 cstr
logical*4 lret
character*12 datefirst, datelast
character*240 filename,datefilename, filenameloc
real percentwanted, fracmax
integer numcomps, maxmissed, filesize, normalizationmode, numwritemax
logical use_update, noslashes, use_numcomps
logical state_b4,state_b5,state_b6,state_b7, state_b9, state_r1, state_r2
logical state_eb1,state_eb2,state_eb3,state_eb4
type (T_SYSTEMTIME) daterecord
include 'resource.fd'

common /daterange/ datefirst,datelast

if (callbacktype == dlg_clicked) then
  if (id == IDC_POPUPCAL1) then
! Hide the button that just triggered the popup calendar control using J. Dujic's XFLOGM:
! also temporarily hide all edit boxes and buttons underneath the calendar:
     lret = DlgSet(dlg, IDC_POPUPCAL1, .FALSE., dlg_visible)
     lret = DlgSet(dlg, IDC_POPUPCAL1, .FALSE., dlg_enable)
     lret = DlgSet(dlg, IDC_CLOSECAL1, .TRUE., dlg_visible)
     lret = DlgSet(dlg, IDC_CLOSECAL1, .TRUE., dlg_enable)
     lret = DlgGet(dlg, IDC_RADIO1, state_r1, dlg_enable)
     lret = DlgSet(dlg, IDC_RADIO1, .FALSE., dlg_visible)
     lret = DlgGet(dlg, IDC_RADIO2, state_r2, dlg_enable)
     lret = DlgSet(dlg, IDC_RADIO2, .FALSE., dlg_visible)
     lret = DlgGet(dlg, IDC_BUTTON9, state_b9, dlg_enable)
     lret = DlgSet(dlg, IDC_BUTTON9, .FALSE., dlg_visible)
     lret = DlgSet(dlg, IDC_EDIT_DATE, .FALSE., dlg_visible)
! Pop up a calendar over the top of the hidden and deactivated controls:
     ret = ShowWindow(GetDlgItem(dlg%hWnd, IDC_MONTHCALENDAR1), SW_SHOW)
else if (id == IDC_CLOSECAL1) then
! Collapse first calendar and record the selected date in IDC_EDIT1
     lret = DlgSet(dlg, IDC_CLOSECAL1, .FALSE., dlg_visible)
     lret = DlgSet(dlg, IDC_CLOSECAL1, .FALSE., dlg_enable)
     lret = DlgSet(dlg, IDC_POPUPCAL1, .TRUE., dlg_visible)
     lret = DlgSet(dlg, IDC_POPUPCAL1, .TRUE., dlg_enable)
! bring back the various hidden and inactivated controls:
     lret = DlgSet(dlg, IDC_RADIO1, .TRUE., dlg_visible)
     lret = DlgSet(dlg, IDC_RADIO1, state_r1, dlg_enable)
     lret = DlgSet(dlg, IDC_RADIO2, .TRUE., dlg_visible)
     lret = DlgSet(dlg, IDC_RADIO2, state_r2, dlg_enable)
     lret = DlgSet(dlg, IDC_BUTTON9, .TRUE., dlg_visible)
	 lret = DlgSet(dlg, IDC_BUTTON9, state_b9, dlg_enable)
     lret = DlgSet(dlg, IDC_EDIT_DATE, .TRUE., dlg_visible)
	 ret = SendMessage(GetDlgItem(dlg%hWnd, IDC_MONTHCALENDAR1 ), MCM_GETCURSEL, 0, LOC(daterecord))
      write(cstr,'(I2.2,A1,I2.2,A1,I4.4)') daterecord.wMonth , '/', daterecord.wDay , '/', daterecord.wYear 
     lret = DlgSet(dlg, IDC_EDIT_DATE, cstr)
     ret = ShowWindow(GetDlgItem(dlg%hWnd, IDC_MONTHCALENDAR1), SW_HIDE)
end if
      write(cstr,'(I2.2,A1,I2.2,A1,I4.4)') daterecord.wMonth , '/', daterecord.wDay , '/', daterecord.wYear 
return
end

This works fine within my modal dialog control.
Note the DLG_VISIBLE control index is from Mr. Dujic's modified DFLOGM (I named my edited version above XFLOGM2). The button named IDC_POPUPCAL1 opens the calendar and the IDC_CLOSECAL1 closes the calendar and pastes a date in the buddy edit box IDC_EDIT_DATE. Both of these need to be set up prior to calling DlgModal:

lret = DLGSETSUB(dlg,IDC_POPUPCAL1,CalendarAid)
lret = DLGSETSUB(dlg,IDC_CLOSECAL1,CalendarAid)
ret = DLGMODAL(dlg)

Harry Bell
0 Kudos
Reply