|
-
Apr 27th, 2001, 07:23 AM
#1
Thread Starter
Monday Morning Lunatic
How are you using the timer? Callback functions are the most reliable method, and usually don't cause freezing.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 27th, 2001, 08:29 AM
#2
Frenzied Member
oops...I read my post before reading your reply, and noticed that I wasn't using "the" timer, I'm making my own, but my while loop is freezing it.
Code:
void Timer(bool on) {
while(on==true) {
long ConstTime;
long RefreshTime;
ConstTime=GetTickCount();
while(pauseme==false) {
RefreshTime = GetTickCount();
if(RefreshTime-ConstTime > 1000) {
secs++;;
if(secs>=60) {
secs=0;
mins++;
}
if(secs<=9) {
strcat(finalTime, itoa(mins, buffer, 10));
strcat(finalTime, ":0");
strcat(finalTime, itoa(secs, buffer, 10));
SendMessage(ghWnd_Timer, WM_SETTEXT, 0, (LPARAM) (LPCSTR) finalTime);
}
if(secs>9) {
strcat(finalTime, itoa(mins, buffer, 10));
strcat(finalTime, ":");
strcat(finalTime, itoa(secs, buffer, 10));
SendMessage(ghWnd_Timer, WM_SETTEXT, 0, (LPARAM) (LPCSTR) finalTime);
}
int i;
for(i=1; i<=90; i++) {
finalTime[i] = '\0';
}
ConstTime=GetTickCount();
}
}
Sleep(1);
}
}
-
Apr 27th, 2001, 12:06 PM
#3
Thread Starter
Monday Morning Lunatic
It could be getting optimised out 
The most likely explanation is that your program is stuck inside that loop, which means that it is no longer able to perform its message loop, thus freezing the application. This is why you use SetTimer, because it runs in an external thread, your program can update itself without worrying about this.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 27th, 2001, 04:28 PM
#4
Frenzied Member
Could you give me an example?
Could I do this?: Put the message loop into a function, and where it is right now I could call the function. So I could call it from my loop? Probably not, just a stab in the dark
-
Apr 27th, 2001, 04:52 PM
#5
Thread Starter
Monday Morning Lunatic
A possibility is something like this (pseudocode):
Code:
msgloop_func {
getmessage
translate
dispatch
}
timer_func {
// that code you had
each time round, call msgloop_func to ensure any messages are processed
}
winmain {
init
loop {
msgloop_func
}
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 27th, 2001, 05:35 PM
#6
Frenzied Member
Code:
C:\Windows\Desktop\C c++\Mediaboy\mediaboy.cpp(201) : warning C4508: 'WinMain' : function should return a value; 'void' return type assumed
C:\Windows\Desktop\C c++\Mediaboy\mediaboy.cpp(263) : error C2065: 'hInstance' : undeclared identifier
I'm getting these errors. Heres the code:
Code:
bool active;
active=true;
int MessageLoop();
winmain.... {
...
...
while(active==true) {
MessageLoop();
}
}
int Timer() {
//timer code is in here
}
int MessageLoop() {
//message loop directly copied from bottom of
//winmain
}
-
Apr 27th, 2001, 05:37 PM
#7
Thread Starter
Monday Morning Lunatic
Where it says hInstance isn't defined, substitute GetModuleHandle(NULL). The first one's easy. At the end of WinMain, return 0;
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 27th, 2001, 10:15 PM
#8
Frenzied Member
in my while loop to keep calling the message loop I just said return MessageLoop()...but it still freezes...I mean the static control keeps updating but can't push any buttons and I can't move the form.
-
Apr 28th, 2001, 01:37 PM
#9
Thread Starter
Monday Morning Lunatic
The main problem is that you're only in one thread -- the execution point can only be in one place at a time (without using setjmp/longjmp which isn't recommended). Why can't you use the normal timer functions?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 28th, 2001, 05:44 PM
#10
Frenzied Member
I don't know them
-
Apr 28th, 2001, 05:50 PM
#11
Thread Starter
Monday Morning Lunatic
Well, far be it from me to let you go without knowing these incredible functions 
Code:
void __stdcall TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {
// Do something here
}
WinMain(...) {
int nID = SetTimer(NULL, 0, 1000 /* Timeout in ms */, TimerProc);
// Message loop
KillTimer(NULL, nID);
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 28th, 2001, 05:53 PM
#12
Thread Starter
Monday Morning Lunatic
Oh, and if it whinges about UINT_PTR change it to UINT...I'm just using the PSDK defs because I don't have the old (obsolete ) ones any more.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 29th, 2001, 05:02 PM
#13
Frenzied Member
could you explain exactly what that does? Do they have to be around the message loop? Can I put them into a function?
by them I mean:
Code:
int nID = SetTimer(NULL, 0, 1000 /* Timeout in ms */, TimerProc);
KillTimer(NULL, nID);
-
Apr 30th, 2001, 12:03 PM
#14
Thread Starter
Monday Morning Lunatic
The timer runs from when you call SetTimer to when you call KillTimer. As a result, if you call KillTimer straight after SetTimer it's a tad pointless 
Idea: have 2 buttons on a window. When one is clicked, call SetTimer. When the other is clicked, call KillTimer. In your timer procedure update a static control with the time
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 1st, 2001, 04:13 PM
#15
Frenzied Member
errors: [code]C:\Windows\Desktop\C c++\Win32_clock\clock.cpp(36) : error C2065: 'nID' : undeclared identifier
C:\Windows\Desktop\C c++\Win32_clock\clock.cpp(39) : error C2065: 'TimerProc' : undeclared identifier
C:\Windows\Desktop\C c++\Win32_clock\clock.cpp(94) : error C2373: 'TimerProc' : redefinition; different type modifiersC:\Windows\Desktop\C c++\Win32_clock\clock.cpp(36) : error C2065: 'nID' : undeclared identifier
C:\Windows\Desktop\C c++\Win32_clock\clock.cpp(39) : error C2065: 'TimerProc' : undeclared identifier
C:\Windows\Desktop\C c++\Win32_clock\clock.cpp(94) : error C2373: 'TimerProc' : redefinition; different type modifiers[/code
-
May 1st, 2001, 04:13 PM
#16
Frenzied Member
errors:
Code:
C:\Windows\Desktop\C c++\Win32_clock\clock.cpp(36) : error C2065: 'nID' : undeclared identifier
C:\Windows\Desktop\C c++\Win32_clock\clock.cpp(39) : error C2065: 'TimerProc' : undeclared identifier
C:\Windows\Desktop\C c++\Win32_clock\clock.cpp(94) : error C2373: 'TimerProc' : redefinition; different type modifiersC:\Windows\Desktop\C c++\Win32_clock\clock.cpp(36) : error C2065: 'nID' : undeclared identifier
C:\Windows\Desktop\C c++\Win32_clock\clock.cpp(39) : error C2065: 'TimerProc' : undeclared identifier
C:\Windows\Desktop\C c++\Win32_clock\clock.cpp(94) : error C2373: 'TimerProc' : redefinition; different type modifiers
-
May 1st, 2001, 04:18 PM
#17
Thread Starter
Monday Morning Lunatic
Read my post a few posts up...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 1st, 2001, 04:32 PM
#18
Frenzied Member
I still get the errors by changing it to UNIT
-
May 1st, 2001, 04:34 PM
#19
Thread Starter
Monday Morning Lunatic
Oh f**k it, I'll talk to you on MSN
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|