Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » How do I use WIndows Message pump timer?
How do I use WIndows Message pump timer? [message #3290] Thu, 18 May 2006 04:01 Go to next message
jeff1101 is currently offline  jeff1101
Messages: 11
Registered: November 2005
Location: Philippines
Promising Member

Sorry if this topic should not be here.


I have reused CounterCtrl. How do I write the code to set a timer that will trigger a callback function at the appropriate time ?

I dont want to start a new thread just to do this. I do want the message pump of windows to call the callback function when the timer is set.

Thanks.
Re: How do I use WIndows Message pump timer? [message #3291 is a reply to message #3290] Thu, 18 May 2006 05:20 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
jeff1101 wrote on Wed, 17 May 2006 22:01

Sorry if this topic should not be here.


I have reused CounterCtrl. How do I write the code to set a timer that will trigger a callback function at the appropriate time ?

I dont want to start a new thread just to do this. I do want the message pump of windows to call the callback function when the timer is set.

Thanks.


void *SetTimeCallback(int delay_ms, Callback cb, void *id = NULL); // delay_ms < 0 -> periodic
void  KillTimeCallback(void *id);
bool  ExistsTimeCallback(void *id);
dword GetTimeClick();

inline
void  PostCallback(Callback cb, void *id = NULL)                { SetTimeCallback(1, cb, NULL); }

class TimeCallback
{
public:
	~TimeCallback()                      { Kill(); }

	void Set(int delay, Callback cb)     { ::SetTimeCallback(delay, cb, this); }
	void Kill()                          { ::KillTimeCallback(this); }
	void KillSet(int delay, Callback cb) { Kill(); Set(delay, cb); }
};

......

class Ctrl {
....
	void    SetTimeCallback(int delay_ms, Callback cb, int id = 0);
	void    KillTimeCallback(int id = 0);
	void    KillSetTimeCallback(int delay_ms, Callback cb, int id);
	bool    ExistsTimeCallback(int id = 0) const;
	void    PostCallback(Callback cb, int id = 0);
	void    KillPostCallback(Callback cb, int id);
.....
};


Mirek
Re: How do I use WIndows Message pump timer? [message #3298 is a reply to message #3290] Thu, 18 May 2006 17:09 Go to previous messageGo to next message
jeff1101 is currently offline  jeff1101
Messages: 11
Registered: November 2005
Location: Philippines
Promising Member

HI,

Excuse, how do I use your example? I modified the CounterCtrl class like so. (This is just a snippet)

void CounterCtrl::Paint(Draw& w)
{
Size sz = GetSize();
w.DrawRect(sz, paper);
String txt = AsString(number);
sz = (sz - w.GetTextSize(txt, font)) / 2;
w.DrawText(sz.cx, sz.cy, txt, font, ink);
}

/***
void CounterCtrl::LeftDown(Point, dword)
{
number++;
Refresh();
}
***/

I commented out LeftDown() because I dont want that trigger event . What I do want is a trigger event that happens every second and that I will then handle with the customized code I have in mind.

Thanks.

regards
Jeffrey
Re: How do I use WIndows Message pump timer? [message #3299 is a reply to message #3298] Thu, 18 May 2006 17:47 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
void CounterCtrl::Inc()
{
   number++;
   Refresh();
}

CounterCtrl::CounterCtrl()
{
   SetTimeCallback(THISBACK(Inc), -1000, 33);
}


Actually, that '33' is somewhat faulty (you should rather follow "TIMEID" enum protocol), but as the first iteration, it is OK.

Mirek

[Updated on: Thu, 18 May 2006 17:47]

Report message to a moderator

Re: How do I use WIndows Message pump timer? [message #3414 is a reply to message #3290] Wed, 24 May 2006 11:34 Go to previous messageGo to next message
jeff1101 is currently offline  jeff1101
Messages: 11
Registered: November 2005
Location: Philippines
Promising Member

Ahhh, I understand now. I will try this and give feedback on the results. Thanks. Very Happy
Re: How do I use WIndows Message pump timer? [message #3421 is a reply to message #3290] Wed, 24 May 2006 17:12 Go to previous messageGo to next message
jeff1101 is currently offline  jeff1101
Messages: 11
Registered: November 2005
Location: Philippines
Promising Member

Hi,

Got the ff errors on compile: (Do I need to include an *.h file to use SetTimeCallback() ?)

C:\MyApps\Counter\Counter.cpp: In member function `void CounterCtrl::InitTimer
(int)':
C:\MyApps\Counter\Counter.cpp:16: error: `CLASSNAME' has not been declared
C:\MyApps\Counter\Counter.cpp:16: error: ISO C++ forbids taking the address of
an unqualified or parenthesized non-static member function to form a poin
ter to member function. Say `&CounterCtrl::Inc'
C:\MyApps\Counter\Counter.cpp:16: error: invalid conversion from `int' to `_CN
ULL'
C:\MyApps\Counter\Counter.cpp:16: error: initializing argument 1 of `Callbac
k::Callback(_CNULL)'
Exitcode: 1
compiled in (0:03.12)
1 file(s) compiled in (0:03.12) 3125 msec/file

There were errors. (0:03.14)


Thanks
Re: How do I use WIndows Message pump timer? [message #3426 is a reply to message #3421] Wed, 24 May 2006 18:49 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Add

typedef CounterCtrl CLASSNAME;

to the CounterCtrl class definition.

Mirek
Re: How do I use WIndows Message pump timer? [message #3599 is a reply to message #3290] Mon, 05 June 2006 16:08 Go to previous messageGo to next message
jeff1101 is currently offline  jeff1101
Messages: 11
Registered: November 2005
Location: Philippines
Promising Member

Hi,

I'm still having some problems. Crying or Very Sad I added the typedef but I still get compile errors. Here is the code:


void CounterCtrl::Inc()
{
number++;
Refresh();
}

void CounterCtrl::InitTimer(int seconds)
{
SetTimeCallback(THISBACK(CounterCtrl::Inc), -1000, 33);
}

Value CounterCtrl::GetData() const
{
return number;
}

void CounterCtrl::SetData(const Value& v)
{
number = v;
Refresh();
}

void CounterCtrl::Paint(Draw& w)
{
Size sz = GetSize();
w.DrawRect(sz, paper);
String txt = AsString(number);
sz = (sz - w.GetTextSize(txt, font)) / 2;
w.DrawText(sz.cx, sz.cy, txt, font, ink);
}

/***
void CounterCtrl::LeftDown(Point, dword)
{
number++;
Refresh();
}
***/

CounterCtrl::CounterCtrl()
{
number = 0;
ink = SBlack;
paper = SWhite;
font = StdFont();
SetFrame(BlackFrame());
}

CounterCtrl::~CounterCtrl() {}


Notice how I disabled LeftDown() callback? I wanted to replace it with the Inc() method which gets called at preset intervals by calling the InitTimer() method. When I compile this I get the ff errors:



C:\MyApps\Counter\Counter.cpp: In member function `void CounterCtrl::InitTimer(int)':
C:\MyApps\Counter\Counter.cpp:16: error: invalid conversion from `int' to `_CNULL'
C:\MyApps\Counter\Counter.cpp:16: error: initializing argument 1 of `Callback::Callback(_CNULL)'
Exitcode: 1
compiled in (0:10.53)
1 file(s) compiled in (0:10.53) 10531 msec/file

There were errors. (0:14.82)


I am thinking the typedef required a specific method signature as input? Can you point me to the right direction? Thanks.


regards
Re: How do I use WIndows Message pump timer? [message #3600 is a reply to message #3599] Mon, 05 June 2006 16:32 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
My apologies, I swapped parameters:

 SetTimeCallback(-1000, THISBACK(CounterCtrl::Inc), 33);


Mirek
Previous Topic: Stripping unnecessary classes
Next Topic: How to set the Constructor of a derived widget class?
Goto Forum:
  


Current Time: Mon May 06 13:41:32 CEST 2024

Total time taken to generate the page: 0.03274 seconds