在DATETIMEPICK_CLASS元素中获取和设置日期 [英] Getting and setting date in DATETIMEPICK_CLASS element

查看:35
本文介绍了在DATETIMEPICK_CLASS元素中获取和设置日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建

I am creating time picker element described here. I am writing code in C++ using simple winapi calls

我找不到如何以编程方式在此元素中实际获取和设置时间的任何示例.

I cannot find any examples of how to actually get and set time within this element programmatically.

首先,该元素在程序启动时以一些随机时间进行初始化(甚至与系统时间都不匹配),我希望它以 00:00 进行初始化.我该怎么办?

First of all, the element initializes with some random time at program startup (which does not even match system time) and I would like it to initialize with 00:00. How do I do that?

第二个问题是我应该使用哪种方法从控件元素中获取时间值.我已经尝试了 GetWindowText()并取得了一些成功,但是我不确定这是否是正确的解决方案.

Second question is what method should I use to get time value from control element. I have tried GetWindowText() with some success but I am not sure if this is the correct solution.

下面提供了我用于初始化的代码示例

The example of code that I use to initialize is provided below

    /* TIMER2*/
    dtmTimer2 = CreateWindowEx( //
            /* Extended Style   */0, //
            /* Class Name       */DATETIMEPICK_CLASS, //
            /* Element Name     */GUI_TIMER2_LABEL, //
            /* Style            */(WS_BORDER | WS_CHILD |WS_VISIBLE | DTS_TIMEFORMAT), //
            /* X Position       */GUI_TIMER2_POS_X, //
            /* Y Position       */GUI_TIMER2_POS_Y, //
            /* Width            */GUI_TIMER2_WIDTH, //
            /* Height           */GUI_TIMER2_HEIGHT, //
            /* Parent Window    */hwnd, //
            /* Menu             */NULL, //
            /* Instance         */NULL, //
            /* Parameter        */NULL);
    SendMessage(dtmTimer2, WM_SETFONT, (WPARAM) hFont, MAKELPARAM(TRUE, 0));
    SendMessage(dtmTimer2, DTM_SETFORMAT, 0, (LPARAM) "HH:MM");

似乎我在这里确实缺少一些明显的东西.任何帮助将不胜感激.

It seems like I am missing something really obvious here. Any help will be appreciated.

推荐答案

您需要的消息是 DTM_GETSYSTEMTIME DTM_SETSYSTEMTIME (或其对应的宏),它们使用 SYSTEMTIME 结构进行操作.

The messages you need are DTM_GETSYSTEMTIME and DTM_SETSYSTEMTIME (or their corresponding macros) which operate using SYSTEMTIME structs.

这篇关于在DATETIMEPICK_CLASS元素中获取和设置日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆