简体   繁体   English

从 DATETIMEPICK_CLASS win32 获取选定日期(不是 mfc)

[英]get selected date from DATETIMEPICK_CLASS win32 (NOT mfc)

I have 1 datetimepick_class control placed on win32 form .我在win32 表单上放置了 1 个datetimepick_class控件。 I create it like below:我创建它如下:

HWND Date = CreateWindowEx(
    0,
    DATETIMEPICK_CLASS,
    TEXT("DateTime"),
    WS_BORDER | WS_CHILD | WS_VISIBLE ,
    10, 10
    250, 30,
    hWnd,
    (HMENU)IDC_DATE_TIME_PICK,
    hInst,
    NULL
);

And I have button .我有按钮 I want when this button clicked , it should get selected date value from that mentioned datetimepick widget.我希望当单击此按钮时,它应该从提到的datetimepick小部件中获取选定的日期值

I handle button clicked event as below:我处理按钮单击事件如下:

switch (message)
{
    case WM_COMMAND:
    {
        int wmId = LOWORD(wParam);
        switch (wmId)
        {
            case IDC_Calculate_Button: 
            //Button clicked so 
            //Display selected date value in msgbox  
        }
}               

I tried existing answers but they are rare or not well documented or in detailed.我尝试了现有的答案,但它们很少见或没有很好的记录或详细说明。 Please guide me.请指导我。

You can use DTM_GETSYSTEMTIME message:您可以使用DTM_GETSYSTEMTIME消息:

case WM_COMMAND:
{
    int wmId = LOWORD(wParam);
    switch (wmId)
    {
    case IDC_Calculate_Button:
    {
        //Button clicked so 
        //Display selected date value in msgbox  
        SYSTEMTIME st{};
        DateTime_GetSystemtime(Date, &st);
        TCHAR buf[100]{};
        wsprintf(buf, L"%d-%d-%d", st.wYear, st.wMonth, st.wDay);
        MessageBox(hwnd, buf, L"Time", 0);
    }
    }
}

It works for me:这个对我有用:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM