Mr. Carroll,
Thanks a lot.
HYC
X
-
Suggest you post questions in another sub-forum, such as 'PowerBASIC for Windows' or 'Programming' as this one is for source code listings.
However...
In a DDT callback function, CB.HNDL is the handle of the dialog, so there is no need to call
Code:CONTROL GET TEXT hDlg ,%IDC_CALDATE1 to szDate1 CONTROL GET TEXT hDlg ,%IDC_CALDATE2 to szDate2
Code:CONTROL GET TEXT CB.HNDL, %IDC_CALDATE1 to szDate1 CONTROL GET TEXT CB.HNDL, %IDC_CALDATE2 to szDate2
It is buggy, though, as the code does not match the expected behaviour.
To demonstrate this, change the date, then change the time.- When the date is changed, the label will show the changed date, and the existing time.
- When the time is changed after the date has been changed, the label will show today's date (not the existing date) and the changed time. [And the date in the date control will be different than that displayed in the label as the 'selected date'.]
This is because GetDateFormat is called before GetTimeFormat in the notification that is called for any change in either of these controls. When the time is changed, GetDateFormat will get the date of the time control, and as that has not been set specifically, it will return today's date.
To solve this, and also to answer your question, %DTN_DATETIMECHANGE should be handled separately for each control.
The following demonstrates:
Code:Local ptNmdtc As NMDATETIMECHANGE Ptr Local ptNmh As NMHDR Ptr Local szDate As Asciiz * 64 Case %WM_NOTIFY ptNmh = Cb.lParam Select Case @ptNmh.idFrom Case %IDC_CALDATE1 Select Case @ptNmh.code Case %DTN_DATETIMECHANGE ptNmdtc = Cb.lParam GetDateFormat %LOCALE_USER_DEFAULT, %DATE_LONGDATE, @ptNmdtc.st, ByVal %NULL, szDate, SizeOf(szDate) Control Set Text Cb.Hndl, %IDC_LABEL, "Date 1 changed to: " + szDate End Select Case %IDC_CALDATE2 Select Case @ptNmh.code Case %DTN_DATETIMECHANGE ptNmdtc = Cb.lParam GetDateFormat %LOCALE_USER_DEFAULT, %DATE_LONGDATE, @ptNmdtc.st, ByVal %NULL, szDate, SizeOf(szDate) Control Set Text Cb.Hndl, %IDC_LABEL, "Date 2 changed to: " + szDate End Select End Select
Code:Local ptNmdtc As NMDATETIMECHANGE Ptr Local ptNmh As NMHDR Ptr Local tST As SYSTEMTIME Static sszDate1 As Asciiz * 64 Static sszDate2 As Asciiz * 64 Case %WM_INITDIALOG ' record initial values of dates ' .. date 1 SendMessage GetDlgItem(Cb.Hndl, %IDC_CALDATE1), %DTM_GETSYSTEMTIME, 0, VarPtr(tST) GetDateFormat %LOCALE_USER_DEFAULT, %DATE_LONGDATE, tST, ByVal %NULL, sszDate1, SizeOf(sszDate1) ' .. date 2 SendMessage GetDlgItem(Cb.Hndl, %IDC_CALDATE2), %DTM_GETSYSTEMTIME, 0, VarPtr(tST) GetDateFormat %LOCALE_USER_DEFAULT, %DATE_LONGDATE, tST, ByVal %NULL, sszDate2, SizeOf(sszDate2) Function = 1 Case %WM_NOTIFY ptNmh = Cb.lParam Select Case @ptNmh.idFrom Case %IDC_CALDATE1 Select Case @ptNmh.code Case %DTN_DATETIMECHANGE ptNmdtc = Cb.lParam GetDateFormat %LOCALE_USER_DEFAULT, %DATE_LONGDATE, @ptNmdtc.st, ByVal %NULL, sszDate1, SizeOf(sszDate1) Control Set Text Cb.Hndl, %IDC_LABEL, "Date 1 changed to: " + sszDate1 + $crlf + _ " and Date 2 remains as: " + sszDate2 End Select Case %IDC_CALDATE2 Select Case @ptNmh.code Case %DTN_DATETIMECHANGE ptNmdtc = Cb.lParam GetDateFormat %LOCALE_USER_DEFAULT, %DATE_LONGDATE, @ptNmdtc.st, ByVal %NULL, sszDate2, SizeOf(sszDate2) Control Set Text Cb.Hndl, %IDC_LABEL, "Date 2 changed to: " + sszDate2 + $crlf + _ " and Date 1 remains as: " + sszDate1 End Select End Select
Leave a comment:
-
By using Control Get Text, the program is working. But I set hDlg as global.
#COMPILER PBWIN 9
#COMPILE EXE
#DIM ALL
'------------------------------------------------------------------------------
' Include files
'------------------------------------------------------------------------------
%USEMACROS = 1
#INCLUDE "Win32API.inc"
#INCLUDE "CommCtrl.inc"
#INCLUDE "InitCtrl.inc"
GlobAL hDlg AS DWORD
'------------------------------------------------------------------------------
' Equates
'------------------------------------------------------------------------------
%IDC_LABEL = %WM_USER + 2110
%IDC_CALDATE1 = %WM_USER + 2150
%IDC_CALDATE2 = %WM_USER + 2170
''%IDC_CALTIME = %WM_USER + 2151
'------------------------------------------------------------------------------
' Main callback
'------------------------------------------------------------------------------
CALLBACK FUNCTION DlgProc () AS LONG
LOCAL pNMDTC AS NMDATETIMECHANGE PTR
LOCAL szDate1 AS ASCIIZ * 64
LOCAL szDate2 AS ASCIIZ * 64
'' LOCAL szTime AS ASCIIZ * 64
SELECT CASE CB.MSG
CASE %WM_COMMAND
' User selected CLOSE button
IF CB.CTL = %IDCANCEL THEN DIALOG END CB.HNDL
CASE %WM_NOTIFY 'Use this to detect changes in the calendar
' Set up the NMDATETIMECHANGE pointer passed in CB.LPARAM
pNMDTC = CB.LPARAM
IF @pNMDTC.hdr.code = %DTN_DATETIMECHANGE THEN 'Get selected date/time
' Here we use API messages to format a system local date/time text,
' but we can also use CONTROL GET TEXT to get the text directly, or
' format individual members of the @hdrX.st SYSTEMTIME structure directly.
CONTROL GET TEXT hDlg ,%IDC_CALDATE1 to szDate1
CONTROL GET TEXT hDlg ,%IDC_CALDATE2 to szDate2
' GetDateFormat %LOCALE_USER_DEFAULT, %DATE_LONGDATE, _
' @pNMDTC.st, BYVAL %NULL, szDate1, SIZEOF(szDate1)
' GetDateFormat %LOCALE_USER_DEFAULT, %DATE_LONGDATE, _
' @pNMDTC.st, BYVAL %NULL, szDate2, SIZEOF(szDate2)
' ? szDate1
' ? szDate2
'' GetTimeFormat %LOCALE_USER_DEFAULT, %TIME_FORCE24HOURFORMAT, _
'' @pNMDTC.st, BYVAL %NULL, szTime, SIZEOF(szTime)
CONTROL SET TEXT CB.HNDL, %IDC_LABEL, _
"Selected date1: " + szDate1 + $CR + "Selected date2: " + szDate2
END IF
CASE %WM_SYSCOLORCHANGE, %WM_WININICHANGE
' If user changes color scheme, forward the notification to the Ani control
CONTROL SEND CB.HNDL, %IDC_CALDATE1, CB.MSG, CB.WPARAM, CB.LPARAM
CONTROL SEND CB.HNDL, %IDC_CALDATE2, CB.MSG, CB.WPARAM, CB.LPARAM
END SELECT
END FUNCTION
'------------------------------------------------------------------------------
' Main entry point for the application
'------------------------------------------------------------------------------
FUNCTION PBMAIN () AS LONG
' LOCAL hDlg AS DWORD
'---------------------------------------------------------------------------
' Note: SysMonthCal32 requires COMCTL32.DLL v4.70 (MSIE 3.0) or latter.
' Therefore, we must check the version number of COMCTL32, so we'll use the
' return value from the helper function InitComCtl32() for this.
'---------------------------------------------------------------------------
IF InitComCtl32(%ICC_DATE_CLASSES) < [email protected] THEN
MSGBOX "Sorry, this program needs a later version of COMCTL32.DLL." + $CRLF _
+ "Please install MSIE version 3 or higher, or get the file directly from: " + $CRLF _
+ $CRLF _
+ "http://www.microsoft.com/msdownload/ieplatform/ie/comctrlx86.asp", _
%MB_ICONWARNING OR %MB_SYSTEMMODAL, "SysMonthCal32 Error"
EXIT FUNCTION
END IF
'--------------------------------------------------------------------------
DIALOG NEW 0, "DateTime picker demo", 194, 109, 309, 70, %WS_CAPTION OR %WS_SYSMENU OR %WS_VISIBLE OR _
%DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR _
%WS_EX_CONTROLPARENT, TO hDlg
CONTROL ADD LABEL, hDlg, %IDC_LABEL, "Select a date1 and/or date2.", 6, 30, 194, 20
CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Close", 150, 52, 50, 14
CONTROL ADD "SysDateTimePick32", hDlg, %IDC_CALDATE1, "", 5, 5, 134, 14, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR _
%DTS_LONGDATEFORMAT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CLIENTEDGE
CONTROL ADD "SysDateTimePick32", hDlg, %IDC_CALDATE2, "", 140,5, 134, 14, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR _
%DTS_LONGDATEFORMAT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CLIENTEDGE
' CONTROL ADD "SysDateTimePick32", hDlg, %IDC_CALTIME, "", 140, 5, 63, 14, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR _
' %DTS_UPDOWN OR %DTS_TIMEFORMAT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CLIENTEDGE
'--------------------------------------------------------------------------
DIALOG SHOW MODAL hDlg CALL DlgProc
END FUNCTION
Leave a comment:
-
Date1 & Date2
I am trying to get 2 dates using PB datetime ddt sample program. But here date1 and date2 are the same. Can anyone help here?
'------------------------------------------------------------------------------
' Metastatements
'------------------------------------------------------------------------------
#COMPILER PBWIN 9
#COMPILE EXE
#DIM ALL
'------------------------------------------------------------------------------
' Include files
'------------------------------------------------------------------------------
%USEMACROS = 1
#INCLUDE "Win32API.inc"
#INCLUDE "CommCtrl.inc"
#INCLUDE "InitCtrl.inc"
'------------------------------------------------------------------------------
' Equates
'------------------------------------------------------------------------------
%IDC_LABEL = %WM_USER + 2110
%IDC_CALDATE1 = %WM_USER + 2150
%IDC_CALDATE2 = %WM_USER + 2170
''%IDC_CALTIME = %WM_USER + 2151
'------------------------------------------------------------------------------
' Main callback
'------------------------------------------------------------------------------
CALLBACK FUNCTION DlgProc () AS LONG
LOCAL pNMDTC AS NMDATETIMECHANGE PTR
LOCAL szDate1 AS ASCIIZ * 64
LOCAL szDate2 AS ASCIIZ * 64
'' LOCAL szTime AS ASCIIZ * 64
SELECT CASE CB.MSG
CASE %WM_COMMAND
' User selected CLOSE button
IF CB.CTL = %IDCANCEL THEN DIALOG END CB.HNDL
CASE %WM_NOTIFY 'Use this to detect changes in the calendar
' Set up the NMDATETIMECHANGE pointer passed in CB.LPARAM
pNMDTC = CB.LPARAM
IF @pNMDTC.hdr.code = %DTN_DATETIMECHANGE THEN 'Get selected date/time
' Here we use API messages to format a system local date/time text,
' but we can also use CONTROL GET TEXT to get the text directly, or
' format individual members of the @hdrX.st SYSTEMTIME structure directly.
GetDateFormat %LOCALE_USER_DEFAULT, %DATE_LONGDATE, _
@pNMDTC.st, BYVAL %NULL, szDate1, SIZEOF(szDate1)
GetDateFormat %LOCALE_USER_DEFAULT, %DATE_LONGDATE, _
@pNMDTC.st, BYVAL %NULL, szDate2, SIZEOF(szDate2)
' ? szDate1
' ? szDate2
'' GetTimeFormat %LOCALE_USER_DEFAULT, %TIME_FORCE24HOURFORMAT, _
'' @pNMDTC.st, BYVAL %NULL, szTime, SIZEOF(szTime)
CONTROL SET TEXT CB.HNDL, %IDC_LABEL, _
"Selected date1: " + szDate1 + $CR + "Selected date2: " + szDate2
END IF
CASE %WM_SYSCOLORCHANGE, %WM_WININICHANGE
' If user changes color scheme, forward the notification to the Ani control
CONTROL SEND CB.HNDL, %IDC_CALDATE1, CB.MSG, CB.WPARAM, CB.LPARAM
CONTROL SEND CB.HNDL, %IDC_CALDATE2, CB.MSG, CB.WPARAM, CB.LPARAM
END SELECT
END FUNCTION
'------------------------------------------------------------------------------
' Main entry point for the application
'------------------------------------------------------------------------------
FUNCTION PBMAIN () AS LONG
LOCAL hDlg AS DWORD
'---------------------------------------------------------------------------
' Note: SysMonthCal32 requires COMCTL32.DLL v4.70 (MSIE 3.0) or latter.
' Therefore, we must check the version number of COMCTL32, so we'll use the
' return value from the helper function InitComCtl32() for this.
'---------------------------------------------------------------------------
IF InitComCtl32(%ICC_DATE_CLASSES) < [email protected] THEN
MSGBOX "Sorry, this program needs a later version of COMCTL32.DLL." + $CRLF _
+ "Please install MSIE version 3 or higher, or get the file directly from: " + $CRLF _
+ $CRLF _
+ "http://www.microsoft.com/msdownload/ieplatform/ie/comctrlx86.asp", _
%MB_ICONWARNING OR %MB_SYSTEMMODAL, "SysMonthCal32 Error"
EXIT FUNCTION
END IF
'--------------------------------------------------------------------------
DIALOG NEW 0, "DateTime picker demo", 194, 109, 309, 70, %WS_CAPTION OR %WS_SYSMENU OR %WS_VISIBLE OR _
%DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR _
%WS_EX_CONTROLPARENT, TO hDlg
CONTROL ADD LABEL, hDlg, %IDC_LABEL, "Select a date1 and/or date2.", 6, 30, 194, 20
CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Close", 150, 52, 50, 14
CONTROL ADD "SysDateTimePick32", hDlg, %IDC_CALDATE1, "", 5, 5, 134, 14, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR _
%DTS_LONGDATEFORMAT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CLIENTEDGE
CONTROL ADD "SysDateTimePick32", hDlg, %IDC_CALDATE2, "", 140,5, 134, 14, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR _
%DTS_LONGDATEFORMAT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CLIENTEDGE
' CONTROL ADD "SysDateTimePick32", hDlg, %IDC_CALTIME, "", 140, 5, 63, 14, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR _
' %DTS_UPDOWN OR %DTS_TIMEFORMAT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CLIENTEDGE
'--------------------------------------------------------------------------
DIALOG SHOW MODAL hDlg CALL DlgProc
END FUNCTION
HYCTags: None
Leave a comment: