Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DateTimePicker unable to select and modify a specific field
#1
In the following code, I encountered two problems:

1. After clicking on the DateTimePicker, unable to select and modify a specific field.
2. How incremented value of the month in DATE?

Macro Macro22
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;4 SysDateTimePick32 0x56030009 0x0 120 16 96 15 ""
;3 SysDateTimePick32 0x56030001 0x0 16 16 96 15 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,DATE d.getclock ;;get current time
,d=d+1 ;;add 1 day
,;how to add 1 month?
,
,_s.timeformat("{yy-MM-dd}" d)
,SendMessage(id(3 hDlg) DTM_SETFORMAT 0 _s)
,
,_s.timeformat("{HH:mm}")
,SendMessage(id(4 hDlg) DTM_SETFORMAT 0 _s)
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#2
date adjustment code works correctly, but the DTS_UPDOWN style cannot be used.

Macro date2
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 SysDateTimePick32 0x56030010 0x0 28 28 96 13 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,DATE d.getclock ;;get current time
,d=d+1 ;;add 1 day
,;how to add 1 month?
,
,_s.timeformat("{yy-MM-dd}" d)
,SendMessage(id(3 hDlg) DTM_SETFORMAT 0 _s)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
;messages3
NMHDR* nh=+lParam
sel nh.code
,case DTN_DATETIMECHANGE
,NMDATETIMECHANGE* p=+nh
,if p.dwFlags=GDT_VALID
,,DateTime dt
,,dt.FromSYSTEMTIME(p.st)
,,_s.timeformat("{yy-MM-dd}" dt)
,,SendMessage(id(3 hDlg) DTM_SETFORMAT 0 _s)
,else out "empty"

The time picker is not adjustable.

Macro time2
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 SysDateTimePick32 0x56030019 0x0 28 28 96 13 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,_s.timeformat("{HH:mm}")
,SendMessage(id(3 hDlg) DTM_SETFORMAT 0 _s)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
;messages3
NMHDR* nh=+lParam
sel nh.code
,case DTN_DATETIMECHANGE
,NMDATETIMECHANGE* p=+nh
,if p.dwFlags=GDT_VALID
,,DateTime dt
,,dt.FromSYSTEMTIME(p.st)
,,_s.timeformat("{HH:mm}" dt)
,,SendMessage(id(3 hDlg) DTM_SETFORMAT 0 _s)
,else out "empty"
#3
The result I need is similar to the following C# code. How can I achieve the same effect in QM?
 
Code:
Copy      Help
using System;
using System.Globalization;
using System.Windows.Forms;

void Main()
{
    DateTimePicker dateTimePicker = new DateTimePicker();
    dateTimePicker.Format = DateTimePickerFormat.Custom;
    dateTimePicker.ShowUpDown = true;
    dateTimePicker.CustomFormat = "yy-M-dd HH:mm";

    DateTime initialDateTime = DateTime.Now.AddMonths(1).AddHours(1);
    dateTimePicker.Value = initialDateTime;

    dateTimePicker.ValueChanged += (sender, e) => Console.WriteLine(dateTimePicker.Value);

    using (Form form = new Form())
    {
        form.Controls.Add(dateTimePicker);

        Application.Run(form);
    }
}

[Image: a.gif]

C++ Code From ChatGPT
 
Code:
Copy      Help
#include <windows.h>
#include <commctrl.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
    }

    return DefWindowProc(hwnd, msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    // Initialize the Common Controls Library
    INITCOMMONCONTROLSEX icex;
    icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    icex.dwICC = ICC_DATE_CLASSES;
    InitCommonControlsEx(&icex);

    // Create the main window
    HWND hwnd = CreateWindowEx(0, L"STATIC", NULL, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

    // Create the SysDateTimePick32 control
    HWND dtPicker = CreateWindowEx(0, DATETIMEPICK_CLASS, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd, NULL, hInstance, NULL);

    // Set the date and time format
    SendMessage(dtPicker, DTM_SETFORMAT, 0, (LPARAM)L"yy-M-dd HH:mm");

    // Get the current date and time, and increment the hour and month by 1
    SYSTEMTIME initialDateTime;
    GetLocalTime(&initialDateTime);
    initialDateTime.wHour += 1;
    initialDateTime.wMonth += 1;

    // Set the date and time
    SendMessage(dtPicker, DTM_SETSYSTEMTIME, GDT_VALID, (LPARAM)&initialDateTime);

    // Show the window
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    // Message loop
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int)msg.wParam;
}

The above C# code was generated using ChatGPT and appears to be very understandable. However, the dialog window I have created is in QM (Quick Macros), and I need the QM code.
#4
The problem is the custom format.

DTM_SETFORMAT is used to set the format not the actual date or time.
for that you need to use DTM_SETSYSTEMTIME

here is working example

Function Function57
Code:
Copy      Help
def DTM_SETSYSTEMTIME 0x00001002

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;4 SysDateTimePick32 0x56030009 0x0 120 16 96 15 ""
;3 SysDateTimePick32 0x56030001 0x0 16 16 96 15 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

DateTime t1 t2 dt
if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,t1.FromComputerTime(); t1.AddParts(1); t1.AddMonths(1)
,SYSTEMTIME st1 st2
,st1=t1.ToSYSTEMTIME()
,st2=t1.ToSYSTEMTIME
,SendMessage(id(3 hDlg) DTM_SETFORMAT 0 "yy'-'MM'-'dd")
,SendMessage(id(3 hDlg) DTM_SETSYSTEMTIME GDT_VALID &st1)
,SendMessage(id(4 hDlg) DTM_SETFORMAT 0 "H':'mm")
,SendMessage(id(4 hDlg) DTM_SETSYSTEMTIME GDT_VALID &st2)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
;messages3
NMHDR* nh=+lParam
sel nh.code
,case DTN_DATETIMECHANGE
,NMDATETIMECHANGE* p=+nh
,if p.dwFlags=GDT_VALID
,,dt.FromSYSTEMTIME(p.st)
,,out dt.ToStr
,else out "empty"
#5
Thanks for your help, the code is working well.
Can I merge the date and time fields together like in the image below? This is the response I got in ChatGPT, but I couldn't find the WS_CHILD style.

[Image: 9.png]
the SysDateTimePick32 control can display both date and time simultaneously. It provides a convenient way for users to select and view date and time values within the same control.

By default, the SysDateTimePick32 control only displays the date part. However, you can set the control's style during creation to display both date and time. When creating the control, use the WS_CHILD | WS_VISIBLE | DTS_TIMEFORMAT style.

Here is an example code snippet to create a SysDateTimePick32 control that displays both date and time:

HWND dtPicker = CreateWindowEx(0, DATETIMEPICK_CLASS, NULL, WS_CHILD | WS_VISIBLE | DTS_TIMEFORMAT, 0, 0, 0, 0, hwnd, NULL, hInstance, NULL);

By applying this style, the SysDateTimePick32 control will allow users to select and view both date and time values.
#6
all in one 
Function Function61
 
Code:
Copy      Help
def DTM_SETSYSTEMTIME 0x00001002

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 SysDateTimePick32 0x56030009 0x0 28 28 96 13 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret

#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,DateTime dt.FromComputerTime; dt.AddParts(1); dt.AddMonths(1)
,SYSTEMTIME st=dt.ToSYSTEMTIME
,SendMessage(id(3 hDlg) DTM_SETFORMAT 0 "yy'-'MM'-'dd' 'HH':'mm")
,SendMessage(id(3 hDlg) DTM_SETSYSTEMTIME GDT_VALID &st)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
;messages3
NMHDR* nh=+lParam
sel nh.code
,case DTN_DATETIMECHANGE
,NMDATETIMECHANGE* p=+nh
,if p.dwFlags=GDT_VALID
,,DateTime dt1
,,dt1.FromSYSTEMTIME(p.st)
,,out dt1.ToStrFormat("{yy-MM-dd} {HH:mm}")
,else out "empty"

can also use the arrow keys (up +down) to change values Use arrow keys(left +right) to move to each part.
#7
Unable to select other fields after the first field, it is easy to select and adjust a field in the above C# code.
#8
change this line 
3 SysDateTimePick32 0x56030019 0x0 28 28 96 13 ""
to  
3 SysDateTimePick32 0x56030009 0x0 28 28 96 13 ""


somehow a style got applied that i didnt want
fixed in post above
#9
thank you so much !
#10
I added 6 hours to the hour field in the time, so the time now is 19:38. However, it is displayed as 0:00. I believe it should be displayed as 1:38.

Macro time3
Code:
Copy      Help
def DTM_SETSYSTEMTIME 0x00001002

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;4 SysDateTimePick32 0x56030009 0x0 120 16 96 15 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

DateTime t1 t2 dt
if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,SYSTEMTIME st2; GetLocalTime &st2; st2.wHour+6

,SendMessage(id(4 hDlg) DTM_SETFORMAT 0 "H':'mm")
,SendMessage(id(4 hDlg) DTM_SETSYSTEMTIME GDT_VALID &st2)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
;messages3
NMHDR* nh=+lParam
sel nh.code
,case DTN_DATETIMECHANGE
,NMDATETIMECHANGE* p=+nh
,if p.dwFlags=GDT_VALID
,,dt.FromSYSTEMTIME(p.st)
,,out dt.ToStr
,else out "empty"
#11
Your system time is invalid.
The SYSTEMTIME does not check to see if the date represented is a real and valid date.
Better to use DateTime class then convert to SYSTEMTIME.
 
Code:
Copy      Help
def DTM_SETSYSTEMTIME 0x00001002

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;4 SysDateTimePick32 0x56030009 0x0 120 16 96 15 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

DateTime dt1 dt2

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc v
function# hDlg message wParam lParam

SYSTEMTIME st1

sel message
,case WM_INITDIALOG
,dt1.FromComputerTime; dt1.AddParts(0 6);;AddParts([days] [hours] [minutes] [seconds] [ms] [^micros])
,st1=dt1.ToSYSTEMTIME
,SendMessage(id(4 hDlg) DTM_SETFORMAT 0 "H':'mm")
,SendMessage(id(4 hDlg) DTM_SETSYSTEMTIME GDT_VALID &st1)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
;messages3
NMHDR* nh=+lParam
sel nh.code
,case DTN_DATETIMECHANGE
,NMDATETIMECHANGE* p=+nh
,if p.dwFlags=GDT_VALID
,,dt2.FromSYSTEMTIME(p.st)
,,out dt2.ToStr
,else out "empty"
#12
Thank you again!


Forum Jump:


Users browsing this thread: 1 Guest(s)