|
This can be only done if u exactly know how many times the timer will be called.. Suppose the timer will be calle only five times.. thne before calling the settimer, u must call the SetRange(0,5)..
nave
|
|
|
|
|
The bar won't move alone, you have to constantly step it yourself during the process (call the Step function). If you want to update the bar from within your thread, the best way to do it is to send user-defined messages to your status dialog. Write then a handler function in your dialog class for these messages and step the bar in it.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
for easy and secure access make the worker thread static to the class and pass the object to the thread function. that is the standard way to do that.
just press "." after your object visual studio will show the whole functions. it is easy to understand "SetScrollRange" and "SetScrollPos" etc.
-Sarath
|
|
|
|
|
Never manipulate GUI object from a worker thread!
Read this[^] excellent article about how to use worker threads and why you should not touch GUI parts from worker threads.
--
Roger
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
sudeep_br wrote: UINT WorkerThreadProc(LPVOID Param)
{
CStatusDlg* status = (CStatusDlg *)Param;
// I want the progress bar to start here
INDX.startIndex();
// I want the progress bar to stop here
return true;
}
Create a GUI thread. The one you are creating is a worker thread which is not meant for GUI manipulation.
Nibu thomas
Software Developer
Faqs by Michael dunn
|
|
|
|
|
Since you are a beginner, especially with threads, I would advise you to read about worker threads and UI threads.
The WorkerThreadProc() function should not touch the UI (since it does not own it). Have it post a message back to the primary thread (the one that owns the UI).
Threads are usually not something that a beginner should embark on, especially when so many other fundamental subjects have yet to be learned.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
I am trying to build an application that draws images, scrolls, draws lines and all that. I use the device context by calling GetDC() and I then call CreateCompatibleDC to get a second DC. In first instance, I drew the current image using the original DC, then copied the complete image usging BitBlt into the compatible DC. When scrolling, or restoring pieces of the image when drawing a line for example, I tried to copy the relevant part of the iamge back into the original DC from the compatible DC using BitBlt, but nothing happens. Next, I tried inversing the process, by passing the compatible DC to the drawing functions, and then copying the completed image into the original DC, but again, this leaves me with a blank screen.
Code snippet:
m_pDC = GetDC ();
m_CompatibleDC.CreateCompatibleDC (m_pDC);
DrawSomething (&m_CompatibleDC); // This also fills a RECT structure
// with the dimensions of the generated
// image: m_RectDC
BOOL r = m_pDC->BitBlt (0, 0, m_RectDC.right, m_RectDC.bottom, &m_CompatibleDC, 0, 0, SRCCOPY);
The return value of BitBlt is 1, so it claims everything went well, but again: nothing happens. The drawing functions do work, since if I pass m_DC into them in stead of &m_CompatibleDC, I get what I expect directly on screen.
Anyone any ideas?
Thanks in advance
William
|
|
|
|
|
I'm not sure,
have u selected bitmap object before drawing?
-Sarath
|
|
|
|
|
Engberts wrote: m_CompatibleDC.CreateCompatibleDC (m_pDC);
After this step u have to select a bitmap into m_CompatibleDC
nave
|
|
|
|
|
Try using PatBlt..
The PatBlt function paints the specified rectangle using the brush that is currently selected into the specified device context.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
All the selection is done in the drawing routines. They use statements like pDC->MoveTo, pDC->LineTo, pDC->FillSolidRect, pDC->RoundRect, pDC->DrawIcon, etc. Again, if I pass the m_pDC variable directly into the drawing routine, all works fine (except that I don't get a copy in the m_CompatibleDC that I can use to restore parts of the image from). I therefore assume that paiting in the m_CompatibleDC probably also works, I just don't get copies into the m_pDC for some reason.
Using the PatBlt routine would not work for me, since my image is composed of lines, rectangles, icon's and all other sorts of things.
William
|
|
|
|
|
William,
You cannot draw to Memory device context until you select a bitmap into it. The code should look something like this:
<br />
CDC* mDC = new CDC();<br />
mDC->CreateCompatibleDC(m_pDC);<br />
<br />
CBitmap* mBM = new CBitmap();<br />
mBM->CreateCompatibleBitmap(pDC, int nWidth, int nHeight) <br />
<br />
<br />
mDC->SelectObject(mBM);<br />
From here you can use all GDI calls on mDC. Hope this helps.
|
|
|
|
|
can I prevent any copy constructor being called for my class.
|
|
|
|
|
Yes, just make it private (or protected).
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
Then it won't compile.
Maxwell Chen
|
|
|
|
|
It won't compile if somebody that uses your class tries to use the copy constructor. So, that was the purpose of his question no ? Preventing people to copy the class. Maybe I misunderstood the question
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
Maybe your suggestion is what he needed.
I was thinking if he was trying to seek a method which redirects copy ctor to other methods ...
Maxwell Chen
|
|
|
|
|
Maxwell Chen wrote: I was thinking if he was trying to seek a method which redirects copy ctor to other methods ...
In Other Method!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Cedric Moonen wrote: Maybe I misunderstood the question
I think not.
The same guy asked about the Singleton pattern a few threads down and the correct way to implement the Singleton pattern is to declare constructors, copy constructor and the assignment operator as protected or private.
A compile time error is expected if the class implemented as a singleton is used in a way it shouldn't.
--
Roger
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
Hi !!!
If you don't define copy constructor in your class, the compiler creates one automatically. YOu cannot prevent that the compiler creates one, but you can implement one with aan empty body.
By !!!
-:KNOX:-
|
|
|
|
|
Is it mandatory to use KillTimer() if a SetTimer is used?
For example, i use
SetTimer(ID1,100,NULL). After 100milliseconds the timer expires and it is handled in the OnTimer() function. Now if i have to start a timer again with the same ID do i have to use KillTimer(ID1)?
|
|
|
|
|
It wont get expired untill you "kill" it. It keeps ticking.
Now if i have to start a timer again with the same ID do i have to use KillTimer(ID1)?
It'll overwrite the existing timer. For example, if you had set the interval as 2000, now the new SetTimer with the same ID but the interval set as 1000, it will start ticking everysecond (1000).
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[V]--
[My Current Status]
|
|
|
|
|
you don't have to use killtimer function to kill the timer.The statement for that function in the msdn shows that if you use an id that is existed,the old timer will be replaced.
|
|
|
|
|
|
Sure thing it is good practice, how else would you make the system free the resources allocated for this timer?
Chances are that when you replace the timer the whole thing deallocates correctly in the SetTimer API. Still better to be absolutely sure and kill the timer by hand.
The name of the function (KillTimer) sounds terrifying, but it's safe to use unlike other functions with frightening names (e.g. TerminateThread).
|
|
|
|