|
kumar_subrahmanya wrote: But SetTimer API documentation does not talk about the above usage.
(where in both hWnd and callback functions are NULL)
Are you sure? Per MSDN:
hWnd
If this parameter is NULL, no window is associated with the timer and the nIDEvent parameter is ignored.
lpTimerFunc
If lpTimerFunc is NULL, the system posts a WM_TIMER message to the application queue.
Either can be NULL independent of the other.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Well, MSDN says "If lpTimerFunc is NULL, the system posts a WM_TIMER message to the application queue." What is application Queue? is it the message queue of the thread which started the timer or it is "THE" applications main message queue?
Here in my code, I have both hWnd and timer call back as null and I am recieving the WM_TIMER messages at my thread message Queue!!!
|
|
|
|
|
You can use WM_TIMER in CWinThread, but there may be problems.
I just finished a graphics processing application and I was using a timer in a worker thread, to do some minor stuff. Since WM_TIMER is a low priority message... during image processing and fast image Blting... the timer was not working correctly... some long delays at random intervals.
My research showed me that it was being caused by rapid WM_PAINT messages due to my flicker-free paint functions. For example, if the user grabbed a large image (several megabytes)on the screen and moved it around with the mouse... the WM_TIMER messages never reached the thread.
I redesigned my worker threads so they work in an infinite loop, with a custom sleep function. The starting and stopping of the threads are purely message based, works *much* better this way.
Note: this may or may not apply to your project.
You can read more about the problem on google:
http://www.google.com/search?hl=en&q=WM_TIMER+low+priority[^]
|
|
|
|
|
Hi thanks for the input. I will check how this would affect my project.
thanks again.
|
|
|
|
|
hi,
I need to create a delay in step of 250 micro sec..But GetTickCount API counts the tick in terms of milli seconds.
Is there any other method to achieve the same using inline assembly, but only issue is it shouldn't be processor specific/dependent...
can someone post a snippet for the same..
thanx..
|
|
|
|
|
|
Hi,
I don't think you will be able to do this in Windows. This is because the Windows timers don't really provide such high resolution. With multimedia timers you can get about 1ms resolution, at best. Check out the timeBeginPeriod function.
If you are into developing hardware you might solve your problem by developing a microcontroller to connect to a serial port, and then user the received serial data as event triggers. With a serial data rate of 128000 bps and 10 bits per byte, you would get about 12800 bytes per second (78 us per byte). Nevertheless, no real guarantees of accurate timming exist, because Windows could always group several bytes together before generating an event to the application, especially if there are other processes running. (you could try a loopback serial cable to avoid developing hardware).
What you could do, using assembly language or C, is to take advantage of the fairly predictable execution rate of processors (after the startup stabilization and cache warming up) to estimate how many instructions execute within a given timer tick interval. For example, if 10ms elapse between timer ticks, and during that time your processor executes 3,000,000 for() loops, then it is a reasonable approximation to consider that your processor will execute 300,000 instruction in 1 ms, or 75,000 in 250 us. So, to wait 250 us you would do "for(int i=0; i<75000; i++);". For this to be accurate your program should not be interrupted by other processes in the system (so it should have a high execution priority), and the for() loops you use to measure execution rate should be very similar (ideally the same) as the for() loops used for waiting. And, of course, the execution time wasted between waits should be negligeble.
One thing you must take into account when writting delays with this technique, is that the execution speed should be measured for each processor, or, ideally, before any execution. For the loops to be similar you could start a loop that you know will take about 1s or so to execute, and when it finished measure the time diference. For example:
void main(void) {
double t0, t1;
t0=((double)clock())/((double)CLOCKS_PER_SEC);
for(int i=0; i<500000000; i++);
t1=((double)clock())/((double)CLOCKS_PER_SEC);
printf("t1-t0=%g", t1-t0);
}
On my computer, which is a Pentium 4 running at 3.2 GHz, this 500,000,000 count loop takes about 1.1 seconds. If I run this application on my old 386 at 25 MHz I could expect it to take over 2 minutes, which could be unacceptable. If your application is to be run on such different machines you should consider first estimating the execution rate by using an alogorithm like:
1) Estimate how many loops can be executed in 0.5 seconds by using a while() loop that keeps running while the timer is under 0.5 seconds, while incrementing the loop counter.
2) Execute the real measurement for() loop using the estimated value in 1), corrected to execute in the time you think is acceptable, while measuring the start time and the end time. For example, if you think users accept waiting for 2 seconds while the application measures execution speed, then the real for() loop should run for a corrected value of about 3 times that achieved in the while loop (step 1) took 0.5 seconds, so step 2) should take no more than 1.5 seconds, or 3 times the time of setp1) ).
Since the loops are diferent, you should expect that a for() loop counting to a value 3 times higher than that achieved with the while() loop does not take 3 times as much time. But, since you measure the actual time of the for loop, that will not be very important for the accuracy of the measure.
For accuracy, the measurement loop should take enough time for the timer tick interval to be negligeable. For example, in Windows XP you get about 100 ticks per second, so measuring for 1 second gives you an error with an order of magnitude of about 1%. Executing measurements for 2 seconds 0.5%, and so on. The worst Windows timer resolution I know is with 95/98 with tick intervals of about 50 ms.
Also take into account that for the loops to be equal, the measure loop and the wait loop should use the same termination conditions. Either both use constant fixed limits, or both use variable limits, otherwise the compiler may generate different code for them. For the same reason, both should be subject to the same compiler optimizations. For best accuracy, try to isolate the loop in a function of its own.
An application built in this manner is not very user friendly, because it will be taking all the available CPU while waiting. This is especially noticeable if the process priority is high. With enough bad programming you can even make the CPU so busy with your loops that not even the mouse pointer gets any CPU to move around.
Rilhas
|
|
|
|
|
hi
i hav a listbox in dialog.
i have to add two column in the list.
in the leftone i want to add image & in the second column i want to string.
and the other thing is that i ahev to add these data from a loop.
plz tell me
thanx
|
|
|
|
|
You can use ClistCtrl i think its better but for image in listbox seeHere[^]
whitesky
|
|
|
|
|
hello sir
thanx for replying but not getting how to make the multicolum listcntrl.
& how can i add both string and image simultaneously.
plz tell me thanx
|
|
|
|
|
SeeInsertItem and InsertColumn in CListCtrl
whitesky
|
|
|
|
|
aavesh wrote: thanx for replying but not getting how to make the multicolum listcntrl.
Use the LVS_REPORT style.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi there,
as you can see i'm new to these forums so go easy on me
I've been programming in C for a couple of years now and have recently moved onto C++. I am now undertaking a project to design control software for pipeline inspection tractors / vehicles where by i am now teaching my self Visual C++ (Using Microsoft Visual C++ 2005 express). Now i am far from an expert in C++, so VC++ is prooving to be rather difficult.
One thing i am trying to do is set a routine at the beginning of the programme to read a set of data from a collection of objects from a header file.
#include <string>
using namespace std;
class TRACTOR
{
public :
char name[40];
int bristles, pistons;
TRACTOR();
TRACTOR( char _name[40], int _bristles, int _pistons);
};
TRACTOR::TRACTOR (char _name[40], int _bristles, int_pistons)
{
strcopy(name, _name);
bristles = _bristles;
pistons = _pistons ;
}
TRACTOR DPT_1("8 inch", 3, 2);
TRACTOR DPT_2("10 inch", 4, 3);
I am trying to set a routine to read the name value of each object into a combo list at the start of the programme (so that the tractor_types.h file can be quickly edited to add / remove / alter tractor properties).
I would also like to be able to display the chosen type of tractor in a label, but i keep getting errors telling me that the compiler is unable to convert char* to System::string... or something like that.
Finally... and my apologies for such a long first post.
parallel port access in Visual C++... how? i have had the entire process working in C++ compiled with Dev, using inout32.dll but have been unable to port this across to the visual c++ standard.
Any help in this would be greatly appreciated!
Mark
-- modified at 7:59 Friday 7th July, 2006
|
|
|
|
|
markwalker84 wrote: ...pipeline inspection tractors / vehicles...
I worked for a company once that called these things "pigs."
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Yeah - thats the slang term for them here - but i thought if i started talking about hooking PIGs up to comuters and writing programmes to control them people might start thinking i was a bit weird and get the RSPCA involved! hehe
|
|
|
|
|
Hi Mark,
First, you'll get *much* more out of C++ if you don't just use it as a fancy C. For instance, most people wouldn't make member variables public. There is also, at least among people who grew up with win32, a naming standard that prefixes C to class names and m_ to member variables. It just helps other people reading your code to see what's what.
In any case, I would personally do something like this:
if you have, say, 30 saved tractors:
unsigned int nTractors = 30;
std::string tractorNames[ 30 ];
int bristles[ 30 ];
int pistons[ 30 ];
CTractor* tractors = new CTractor[ nTractors ];
for(unsigned int x=0; x< nTractors; x++)
tractors[x].setData( tractorNames[ x ], bristles[ x ], pistons[ x ]);
delete [] tractors;
Then for win32 stuff that takes LPCTSTR, you can use std::string.c_str() (assuming that the windows function copies your string into internal storage).
As for your dll, what exactly is the problem?
earl
|
|
|
|
|
Thanks for the reply there!
I see what you mean about C++ not just being a fancy C...
Thanks for the pointers there as well - I will have another crack at it today.
As for the dll stuff... i am trying to enable read / write access to the parallel port. I had a console application working (with DEV (Bloodshed) C++ editor) which required inout32.dll to be placed in the system32 folder, and then with the use of a couple of special function calls the enitre process of parallel port access was very straight forward.
The problem was that when i ported that application across to VC++ it stopeed working. i more or less copied and pasted my entire code into the 'action' of a button press. The programme compiled and ran, but clicking the button (which should have simply sent 0x255 to the parallel port) crashed the programme.
Once again, thanks for the help so far - very much appreciated!
Mark
|
|
|
|
|
First, dlls will also be loaded from the working directory. Be aware, however, that in Visual Studio projects are typically organized as a directory and that while <projname>\debug and < progname >\release are the two directories containing the debug and release builds, respectively, the working directory is set to just <projname> . So you should just be able to put that dll into the project directory.
As for the code you pasted, how are you loading the dll? Run time via a lib or run time via LoadLibrary / GetProcAddress? Are you getting valid function pointers? What exactly is crashing? What line? Do you get errors beforehand?
earl
|
|
|
|
|
hi
i made a dialob box now i wnat to put a wallpaper on it from drive d
but i also want that when i put wallpaper then the buttons or other controls which i put on dialog box remain same and they appear over the wallpaper but
only with there value on it as in widows xp
thanks
Ashish Dogra
MCA
Noida
|
|
|
|
|
for load image use CImage and use Load for darw picture you can use WM_PAINT or WM_WM_ERASEBKGND dc.BitBlt(...);
<br />
CImage m_Image;<br />
m_Image.Load(filename);<br />
in Onpaint use <br />
Bitblt(dc.m_hdc,0,0,800,600,m_Image.GetDC(),0,0,SRCCOPY);<br />
i dont test this code
whitesky
|
|
|
|
|
thanks for your reply
i put this code in oninitdialog()
CImage m_Image;
m_Image.Load(filename)//can i put filename as path of that wallpaper or wallpapers name);
and put this in onpaint
Bitblt(dc.m_hdc,0,0,800,600,m_Image.GetDC(),0,0,SRCCOPY);
but this gives errors as Bitblt undeclared identifier
and CImage as undeclared identifier
Ashish Dogra
MCA
Noida
|
|
|
|
|
BitBlt and include AtlImage.h
whitesky
|
|
|
|
|
plz tell me how to handle this problem
thanks but by including #include "AtlImage.h"
there is an error that is
fatal error C1083: Cannot open include file: 'AtlImage.h': No such file or directory
and plz tell me on filename i use thats path or simply wallpaper name
Ashish Dogra
MCA
Noida
-- modified at 8:44 Friday 7th July, 2006
|
|
|
|
|
if you get this error maybe you dont have this file in your computer and use AtlImage with <> but if you using <> if your file is Bmp you can use LoadImage but your file is jpg you can use Graphics::DrawImage and Image::FromFile or you can use OleLoadPicture
whitesky
|
|
|
|
|
ashish dogra wrote: but this gives errors as Bitblt undeclared identifier
and CImage as undeclared identifier
This should come as no surprise since Bitblt() is different than BitBlt() . m_Image is local to the OnInitDialog() method so there is no way that it can be used on the OnPaint() method.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|