Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DateTimePicker unable to select and modify a specific field
#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.


Messages In This Thread
RE: DateTimePicker unable to select and modify a specific field - by Davider - 09-25-2023, 12:10 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)