|
|
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » How do I use WIndows Message pump timer?
|
Re: How do I use WIndows Message pump timer? [message #3291 is a reply to message #3290] |
Thu, 18 May 2006 05:20   |
 |
mirek
Messages: 14255 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   |
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 #3599 is a reply to message #3290] |
Mon, 05 June 2006 16:08   |
jeff1101
Messages: 11 Registered: November 2005 Location: Philippines
|
Promising Member |

|
|
Hi,
I'm still having some problems. 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
|
|
|
|
Goto Forum:
Current Time: Tue Apr 29 10:23:45 CEST 2025
Total time taken to generate the page: 0.00473 seconds
|
|
|