|
In multithreading application we do pass RUNTIME CLASS.
In that runtime class we write the all the stuff which the thread is suppose to do.
Now my thread is going to draw something on document. My question is how to
achieve device context for the same purpose, and where to achieve
Moreover my application is crashing as I am not getting device context at the point
where I start using device context
|| ART OF LIVING ||
-- modified at 9:43 Tuesday 27th June, 2006
|
|
|
|
|
shivditya wrote: Now my thread is going to draw something on document.
How? The document is not something that can be drawn on. You can only draw on CWnd -derived objects (e.g., CView ).
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Friend sorry Its Single document interface application,CView is there.
|| ART OF LIVING ||
|
|
|
|
|
Of course. It stands to reason that if you have a document, you will also have a view. What makes no sense is that you wanted to draw on the document.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Actually I dint get your question.
It is possible to get device context by passing Window handle to ::GetDC function.
SaRath.
"It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
I tried all the stuff but how to get handle of SDI window from the class instance which is used inside runtimeclass which is being called by SDI using
AfxBeginThread
void CMy5CYLINDERView::support()
{
for(int ii = 0;ii < 1;ii++)
{
x[ii] = AfxBeginThread(RUNTIME_CLASS(SHIV)); //SHIV is my RunTime class.
}
}
//FOllowing is constructor which is using another simulate class instance engine.
SHIV::SHIV()
{
engine.getdata(0);
engine.nextpos();
}
//And this nextpos method requires DC to draw
void simulate::nextpos()
{
CWnd* cc;
cc = (CWnd*)GetWindow(();
CDC* pDC = cc->GetDC();
CBrush bluebrush,old,white;
white.CreateSolidBrush(RGB(200,
|| ART OF LIVING ||
|
|
|
|
|
shivditya wrote: CWnd* cc;
cc = (CWnd*)GetWindow(();
CDC* pDC = cc->GetDC();
CBrush bluebrush,old,white;
white.CreateSolidBrush(RGB(200,
which windows DC you want? MainFrame? Try AfxGetMainWnd() instead of GetWindow
SaRath.
"It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
See AfxGetApp()->m_pMainWnd->GetDC()
whitesky
|
|
|
|
|
Thanks A Lot
Your suggestion worked very very well.
Yours faithfully
Aditya
|| ART OF LIVING ||
|
|
|
|
|
This is something you can check with Spy++, but i'll expect at least something like WM_CLOSE or/and WM_DESTROY or/and WM_NOTIFY.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
hi all
plz tell me how can i made animated a text or picture on a dialog box
i have made a dialog based application in which i want to show some data as animated
plz help
Ashish Dogra
|
|
|
|
|
Use GetDC() to get the DC of the dialog and use that to draw on the dialog.
TextOut to output the text.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
where i use getdc() in oninitdialog on on paint
plz tell me an example for this
Ashish Dogra
MCA
Noida
-- modified at 9:17 Tuesday 27th June, 2006
|
|
|
|
|
You should use the function GetDC() whenever you want to draw something and ReleaseDC() ASAP.It's not suggested to hold on to a device context for long.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
I USE IT IN ONPAINT WHAT I WANT TO ANIMATE THE TEXT ON STATIC OR EDIT CONTROL THEN HOW
WHERE I USE THAT ID BECAUSE GETDC () HAS NO PARAMETER
Ashish Dogra
MCA
Noida
|
|
|
|
|
No need to shout.
GetDC() returns a device context ( a CDC object ), which has plenty of member functions you can use to draw text or anthing. Search for CDC in the MSDN toget some infos about hte possibilities you have.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
PLZ SOLVE MY PROBLEM AS I CAN NOT SOLVE ITP LZ..............
....................................
plz tell me with some example as i am not so intelligent plz yar
and i am not shouting sorry for that.
i am new to vc++
as i do it myself and with the help of u people plz tell me clearly
Ashish Dogra
MCA
Noida
-- modified at 10:02 Tuesday 27th June, 2006
|
|
|
|
|
Create the DC where you need to draw.
You can use ::GetDC(HWND) if you have the handle to a window.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
ashish dogra wrote: plz tell me how can i made animated a text...dialog box
This should give you a general idea.
For an animated picture, can you use an animated GIF file?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
In my project, if I want to stop a work thread without waiting for it, how can I terminate it safely and compulsively as windows task management does?
|
|
|
|
|
There are some ways to stop a thread .
1) AfxEndThread()
2) TerminateThread()
3) _endthreadex()
IT's not safe to terminate a thread using the above functions.
You should check for a condition to be true. Whenever that condition turns true and the thread is still running, use return to exit safely from the thread function.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
zouchao1112 wrote: stop a work thread without waiting for it
Bad design. Why would you want to do this ?
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
zouchao1112 wrote: if I want to stop a work thread without waiting for it, how can I terminate it safely...
You can't. While TerminateThread() does indeed terminate a thread, it does so immediately and the thread has no chance to execute any user-mode code and its initial stack is not deallocated. DLLs attached to the thread are not notified that the thread is terminating. TerminateThread() is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread() only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
The general method is for the thread to periodically check a value and terminate if it matches some criteria. The simplest method is to check a bool and cleanup/exit if it goes to false. The preferred method is to use a manual set event handle and check it with a timeout of zero; if it goes signaled, I then can cleanup/exit. (The big advantage of the latter is that threads are often in a waiting state. With an event handle, you can do a WaitForMultipleObjects .)
(You would then set the "closing" event, and wait for say 5 seconds on the thread handle. If it doesn't close, log an event and call TerminateThread().)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|