|
thanks for the responses, I'll try to put all the pieces together...
|
|
|
|
|
My application freezes after my while loop is in effect. The thing is everything in the while loop executes while the gui remains frozen and windows saying the application is not responding. Cpu usage is at 3% and its still executing properly, its just that the gui is frozen! I cant click my button which resets activeR to false thus ending the loop!
I first tried a simple Sleep(5000) at the end of the while loop, but that ended up with 100% cpu usage.
So i looked up on t_time and worked this out... like i said, it works... but the gui freezes. It still executes the keypress every 5 seconds though.
void roger()
{
int count = 5;
time_t seconds;
time_t curseconds;
bool seq = false;
curseconds = time (NULL) + count;
while(activeR){
if(activeR && seq){
curseconds = time (NULL) + count;
numRogers = numRogers + 1;
keybd_event(VK_PRIOR, 0xc9, 0, 0);
keybd_event(VK_PRIOR, 0xc9, KEYEVENTF_KEYUP, 0);
seq = false;
}else{
seconds = time (NULL);
if(seconds >= curseconds)
{
seq = true;
}
}
Sleep(1);
}
}
|
|
|
|
|
you need to implement this on a different thread.
your loop utilizes the main thread and thus the UI freezes.
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
As suggested above, you should call this function on a separate thread. If MFC, look up AfxBeginThread.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
That was a fabulous way of doing things not only the wrong way, but to also complicate it beyond recognition.
If I haven't misunderstood it seems like what you want to do is synthesize a PgUp keystroke every fifth second.
Use CWnd::SetTimer() , or similar, to set up a timer that is fired every fifth second and call ::keybd_event() from the WM_TIMER message handler.
You do not need a secondary thread for this.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
lol it looks like you've answered his call "roger()" . I didn't actually look at the intention of the code. It looked like it's a strong while loop. So didn't opt for timers. Yep timers can do if that's his requirement.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
VuNic wrote: it looks like you've answered his call "roger()"
I didn't think of it that way, but now that you mention it, it is actually a rather funny coincidence.
Good one!
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
The UI would appear to be frozen because your application is busy processing roger() function. One way (from the book: "Ugliest things to do") is to do the dirty stuff manually, but I said it is dirty.
Put this within your while loop:
MSG Msg;
while(::PeekMessage(&Msg, NULL, 0, 0, PM_NOREMOVE))
{
AfxPumpMessage();
}
I've assumed you're using MFC, if you're not, you can still call up on TranslateMessage and DispatchMessage (which would make it dirtier)
This would manually pump message during every iteration of the loop and your application's UI won't appear frozen. *BUT*, you must do such things on a separate thread, like everyone else said.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: you must do such things on a separate thread, like everyone else said.
Ummm, no, I did not.
In fact I said the opposite based on what it seems like he's trying to do.
His whole while-loop is an attempt to create timer-functionality and "count seconds".
He'd better correct the root cause and use a timer instead of still doing the wrong thing, but disguising it in a thread.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
OK, boo me. I must read the whole thing carefully before replying.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
lol I just did the same.. looking at the loop he had put, I just replied him to go ahead with a worker thread.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Hi,
I have created SDI application from CView base class, Now I want to type charactors on the client area. But it was derived from CView so i couldn't get control. So I have created one CRichEditView class object. But i dont know to create the RichEditView for the currently active window. Pls help me
|
|
|
|
|
Ummm - why not just change your custom view to derive from CRichEditView ? You'll also have to replace CView with CRichEditView in various places in your view's .cpp file, for example, in an IMPLEMENT_DYNCREATE statement, a BEGIN_MESSAGE_MAP statement and where CView methods are called (e.g. your view's PreCreateWindow method will call CView::PreCreateWindow - that should be changed to CRichEditView::PreCreateWindow ).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I what to inherit the struct from another struct in IDL file
any idea?
|
|
|
|
|
Gopal_Kanchana wrote: any idea?
Yes.
Hint: Goooooogle is sooooooooooooo powerful ^ (third item looks promising...).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I didn't get your reply. Please clarify in detail
|
|
|
|
|
Gopal_Kanchana wrote: I didn't get your reply. Please clarify in detail
Using Google will make you a developer with superpowers...
Click the link I provided, in the 'Hint' at the bottom of my previous reply.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
i'm new to c preprocessor and i would like to do some string replacement in a text file using c preprocessor.
the code is something like this
---
#define __TOREPLACE__ replaced
path/subpath/__TOREPLACE__
path\__TOREPLACE__image.png
---
the output is:
...
path/subpath/replaced
path\__TOREPLACE__image.png
...
as seen, there is a replacement in the first path, but not in the second one.
why isn't the second one replaced ?
is this a good approach at all ?
thanks in advance
|
|
|
|
|
Just a guess... But try it with a double \\. In C files, a single \ means the next character has something special about it. Well, it quoted strings it does!
And as your paths aren't valid commands or variable names, I'm guessing you left out the rest of the line and the quotation marks?
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
thanks for your answer, Iain.
i've already tried using the double backslash, but no real effect.
the code i've posted is only seen as an example.
the text files i would like to be preprocessed are no real c code,
more like text conf files, where some text variables have to be replaced.
|
|
|
|
|
I've already given you an answer - but with this extra information...I'd suggest you might be better off using something other than the C pre-processor. awk, m4, perl? They're all available using something like gnuwin32[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I guess the macro should be modified as follows
#define __TOREPLACE__ "replaced"
and used like
"path/subpath/"__TOREPLACE__
"path\"__TOREPLACE__"image.png"
|
|
|
|
|
thanks Naveen, but unfortunately,
the result is not what i wanted.
"path/subpath/""replaced"
"path\"__TOREPLACE__"image.png"
|
|
|
|
|
tarcairion wrote: "path\"__TOREPLACE__"image.png"
you should put double slashes...
"path\\"__TOREPLACE__"image.png"
|
|
|
|
|
The C pre-processor is seeing __TOREPLACE__image.png as a single identifier. That identifier isn't __TOREPLACE__ , so it doesn't replace it.
If you want to 'glue' a replaced value to some static text, you'll need something like this:
#define GLUE2(A, B) A##B
#define GLUE(A, B) GLUE2(A,B)
#define __TOREPLACE__ replaced
path/subpath/__TOREPLACE__
GLUE(path\,GLUE(__TOREPLACE__,image.png))
That works OK under the VC++ pre-processor, giving this output:
path/subpath/replaced
path\replacedimage.png
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|