开发者

C++/CLI: SYSTEMTIME Programming Error

I'm trying to make a little alert system to do something (IDK what I want yet) when a certain time arrives. However, I'm getting all these errors when I run that code in a WinForm after some brief changes. But this code (unchanged) worked in my empty project! I have 开发者_如何学Pythonthe snippet below:

int checktime ()
{
    SYSTEMTIME time;
    GetLocalTime( &time );
    int hour = time.wHour;
    int minute = time.wMinute;
    if (hour > 12) hour -= 12;
    if hour == 8
    {
        this->progressBar1->PerformStep();
    }
}

As always, I would appreciate any help or suggestions available. Thanks!


if hour == 8

That's not valid C++ or C++/CLI. The parentheses in an if statement are not optional.

And why aren't you using .NET System::DateTime::Now? That whole function could be:

int checktime ()
{
   int hour = System::DateTime::Now.Hour;
   if (hour == 8 || hour == 20)
    this->progressBar1->PerformStep();
}


Use a Timer object to keep track of the passing time.

In the designer, drag a timer over from the toolbox onto your form, or instantiate one in the code. You can set the duration (using the interval member), and with each "tick", the system raises an event, and you can perform an action.

It's nice because it's almost like having another thread keeping track in the background.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜