|
RandyS wrote: When I use DrawText to put the text in the control, how can I tell where each word is located in that text?
There is an API which tells you the size of the text you're rendering, you'd need to render one word at a time and keep track of how big each one is on screen, to work out which word holds which co-ordinates.
RandyS wrote: The only idea I had was to manually figure out each word location when placing them in the control and keep a map of the rectangular area used for each word.
Yes, that's about it.
RandyS wrote: But, this would be a lot of work, and memory
A little work, the memory usage is trivial.
RandyS wrote: and I was hoping there would be an easier way
No. There isn't.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
My program gives me a problem in XP and XP alone. The main program runs fine, but when I open a form that then runs another thread and some other tasks if the user clicks on the dialog while the tasks are being processed the form won't close after the tasks are complete (as it should). The tasks are all completed correctly except the form won't close. I also get a "Not responding message" in the dialog top bar when the user is clicking on the form. I throught maybe i needed to run the DisableProcessWindowsGhosting() function at the beginning of my program, however my program does'nt not seem to recognize that function. I have inclued "winuser.h" as a header. Any thoughts on this, either how to get the DisableProcessWindowsGhosting() to work, or another possible solution.
Note: I have also tried the PeekMessage function but this did not work.
Cheers* Any help would be greatful .
Debs*
|
|
|
|
|
Hi...
If there is a better way to do what I am doing, I'll jump on it.
I am using Sleep(milliseconds) in my code to place strategic waits for time to pass. As an example, I need to stop the application because I know that something going on in the real world will take at least 100 msecs to finish and I don't have anyway to handshake with this device/application. So I put a Sleep(100). This has worked ok until recently when I tried running my app in one of the newer PCs with the real fast processor etc.
Now my Sleep()'s are too short.
Is there a way to figure out what the Sleep() will be in msecs from one PC to another?
Also... what is the accuracy of, let's say, Sleep(20). How close to waiting 20 msecs will that be?
Like I said earlier, if there is a better and more accurate way to do this the using Sleep(), I am open to all suggestions...
Regards and thank you in advance
Pierre
|
|
|
|
|
Use a timer, a timers interval is set in milliseconds.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
That's surprising. I would have thought that calling Sleep(100); would suspend the process for at least (but not necessarily exactly) 100mSec.
/ravi
|
|
|
|
|
So you are saying that new fast processors alter time? milliseconds are milliseconds (I thought).
pblais wrote: Also... what is the accuracy of, let's say, Sleep(20). How close to waiting 20 msecs will that be?
I believe the accuracy of Sleep() can vary from +-10ms to +-55ms, depending on the system.
A possibly interesting article: Precision is not the same as accuracy[^]
|
|
|
|
|
Mark Salsbery wrote: So you are saying that new fast processors alter time? milliseconds are milliseconds (I thought).
Everyone likes a wise cracker
|
|
|
|
|
You're the one that stated "Now my Sleep()'s are too short"
If you choose to use a timer then you'll need to use a multimedia timer. Chances are a WM_TIMER
through the SetTimer API is going to be just as inaccurate.
I agree with another poster that the problem is probably related to the time the thread's awake,
not the time it's suspended in Sleep().
Do you do I/O with the external device you are trying to sync to? If so, is there any way you
can use overlapped I/O or soething to make it a bit more event driven instead of trying to fine-
tune timeslices of threads?
Mark
|
|
|
|
|
Mark Salsbery wrote: Do you do I/O with the external device you are trying to sync to? If so, is there any way you
can use overlapped I/O or soething to make it a bit more event driven instead of trying to fine-
tune timeslices of threads?
Yes sometimes. I am writing test software. Sometimes I have to wait for another piece of test equimpmen to go through it's boot up self test and I have no way knowing when it is done. I do know that it takes it approximately 300 mSec. So I put a Sleep(350) in my code to wait for it. I have recently found, on some newer/faster PCs that the application isn't waiting long enough...
|
|
|
|
|
I suspect the problem is in the ratio of the “wake time” to the “sleep time”. On faster machines the “wake time” is lower but the “sleep time” remains about the same.
Steve
|
|
|
|
|
pblais wrote: I don't have anyway to handshake with this device/application.
pblais wrote: when I tried running my app in one of the newer PCs
pblais wrote: Now my Sleep()'s are too short.
Maybe the parameter for the Sleep() call or Timer event should be configurable rather than hard coded?
Otherwise at some point your application will be Sleep()ing with the fishes.
led mike
|
|
|
|
|
led mike wrote: Maybe the parameter for the Sleep() call or Timer event should be configurable rather than hard coded?
And use a trackbar for fine-tuning!
|
|
|
|
|
led mike wrote: Maybe the parameter for the Sleep() call or Timer event should be configurable rather than hard coded?
I like that idea... How would I make configurable?
|
|
|
|
|
pblais wrote: How would I make configurable?
Instead of Sleep(100)
something like this:
Sleep( Config.Milliseconds);
where the number in that variable is provided by a user or administrator.
led mike
|
|
|
|
|
|
I wonder if he wants special sauce on his Fish Filet?
led mike
|
|
|
|
|
The whole thing brings back memories of my first computer job - interfacing with a
home-brewed laser scanner. All the magic numbers in the legacy code, and how the new 386
CPU messed it all up LOL! To this day, it's still referred to (by myself and my business
partner, who worked with me then) as the Laser Bread Slicer (that, we figured, was the extent of
its accuracy).
So, typical tech support goes something like "See the edit box labeled 'Fudge Factor'? Try
entering 203 insead of 198 and see if that fixes it."
Thanks man...I thought I had successfully repressed those memories
|
|
|
|
|
As has been said, the number you pass to Sleep() is just a request. Your thread might not wake up for a minute if some high-priority thread grabs the CPU. Something more accurate than Sleep() seems to be in order, check out multimedia timers and waitable timers.
|
|
|
|
|
Hi, maybe a silly question but:
My resource file, each time it auto-generates, includes windows.h. I need it to include afxcmn.h instead. I can of course change it manually but then each time I use the resource editor the .rc file generates again with windows.h and overwrites the manual change to afxcmn.h. How do I fix this? It's saying Generated from the TEXTINCLUDE 2 resource, maybe I can find/edit that? I have no idea what it is.
Thanks!
KR
|
|
|
|
|
|
Ok I got it to work, thanks.
KR
|
|
|
|
|
I'm having trouble adding inheritance into my program. First here is my code so far:
#include <GL/glut.h><br />
<br />
class Character<br />
{<br />
protected:<br />
int width, height;<br />
int tileX, tileY;<br />
float x, y;<br />
float speed;<br />
public:<br />
Character(float xPos, float yPos);<br />
Character();<br />
~Character();<br />
void draw();<br />
void move(int direction);<br />
float getX();<br />
float getY();<br />
};<br />
<br />
#include "Character.h"<br />
<br />
Character::Character(float xPos, float yPos)<br />
{<br />
width = 50;<br />
height = 50;<br />
x = xPos;<br />
y = yPos;<br />
speed = 0.5;<br />
}<br />
<br />
Character::Character()<br />
{<br />
}<br />
<br />
void Character::draw()<br />
{<br />
glColor3f(1.0, 0.0, 0.0);<br />
glPushMatrix();<br />
glTranslatef(x,y,0);<br />
glBegin(GL_QUADS);<br />
glVertex2d(0, 0);<br />
glVertex2d(0, height);<br />
glVertex2d(width, height);<br />
glVertex2d(width, 0);<br />
glEnd();<br />
glPopMatrix();<br />
}<br />
<br />
void Character::move(int direction)<br />
{<br />
if (direction == 2)<br />
{<br />
x -= speed;<br />
}<br />
else if (direction == 1)<br />
{<br />
x += speed;<br />
}<br />
else if (direction == 3)<br />
{<br />
y += speed;<br />
}<br />
else<br />
{<br />
y -= speed;<br />
}<br />
}<br />
<br />
float Character::getX()<br />
{<br />
return x;<br />
}<br />
<br />
float Character::getY()<br />
{<br />
return y;<br />
}<br />
<br />
#include <GL/glut.h><br />
#include "Character.h"<br />
<br />
class Alien : public Character<br />
{<br />
public:<br />
Alien(float xPos, float yPos);<br />
};<br />
<br />
#include "Alien.h"<br />
<br />
Alien::Alien(float xPos, float yPos)<br />
{<br />
width = 50;<br />
height = 50;<br />
x = xPos;<br />
y = yPos;<br />
speed = 0.1;<br />
}<br />
I thought this was adequate to get Alien to inherit all of the methods of Character, but I get the following errors:
error C2011: 'Character' : 'class' type redefinition
error C2504: 'Character' : base class undefined
error C2039: 'draw' : is not a member of 'Player'
error C2039: 'draw' : is not a member of 'Alien'
and so on. Any ideas what I am doing wrong? Thanks.
|
|
|
|
|
Don't forget to add the precompiler directive at the top of your header files so that they are included only once:
#ifndef MYFILE_H
#define MYFILE_H
#endif
|
|
|
|
|
Ah this fixed it. May I ask what these lines actually do? I've seen these a few times.
|
|
|
|
|
They just prevent that your header file is included several time (thus avoiding a redefinition of an existing class).
Basically, when you do an include, the precompiler will replace the include directive by the contents of the included file. Thus, in certain condition it can happen that you include the same file from different files (if two files include the same file and they are both included in another file).
|
|
|
|