OWL NExt - Knowledge Base

[ Home | Contents | Search | Next | Previous | Up ]

TTimeGadget Shows wrong Time?

Date: 11/30/99
Time: 12:23:22 AM

Q. My TimeGadget shows a wrong time. If it is 15:34:12 it shows 13:34:12. How can I fix this Error?

A.There are different TGetTimeFunc-functions for the TTimeGadget available. Try some of the other available TGetTimeFunc-functions. Some of them are
really working correct!! Or write yourself an own function (I did that - It works great!!!) Here's an example:

#include <owl\docking.h>
#include <owl\timegadg.h>
#include <owl\statusba.h>
#include <stdio.h>

class TStepWindow : public TWindow {
    public:
        TStepWindow(TWindow* parent = 0);
};

TStepWindow::TStepWindow(TWindow* parent)
{
    Init(parent,0,0);
}

class TMyApplication : public TApplication {
    public:
        TMyApplication() : TApplication() {}
        void InitMainWindow();
};

void GetSystemTime(string& newTime)
{
    struct date Datum;
    getdate(&Datum);
    struct time Zeit;
    gettime(&Zeit);

    char Zeile[22];
    sprintf(Zeile,"%02d:%02d:%04d%02d:%02d:%02d",Datum.da_day,Datum.da_mon,Datum.da_year,Zeit.ti_hour,Zeit.ti_min,Zeit.ti_sec);
    newTime = Zeile;
}

void TMyApplication::InitMainWindow()
{
    TDecoratedFrame* DecoratedFrame = new TDecoratedFrame(0,"Steps",new TStepWindow(),true);
    TStatusBar* StatusBar = new TStatusBar(GetMainWindow(),TGadget::Recessed,TStatusBar::SizeGrip);
    StatusBar->Insert(*new TTimeGadget((TTimeGadget::TGetTimeFunc)GetSystemTime));
    StatusBar->SetWideHints(false);
    DecoratedFrame->Insert(*StatusBar,TDecoratedFrame::Bottom);
    SetMainWindow(DecoratedFrame);
}

int OwlMain(int,char*[])
{
    return TMyApplication().Run();
}

Wolfgang D

Last changed: July 14, 2001