Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

c++ - get selected date from DATETIMEPICK_CLASS win32 (NOT mfc)

I have 1 datetimepick_class control placed on win32 form. 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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use DTM_GETSYSTEMTIME message:

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:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...