-1

I have two functions- draw1() and draw2() that draws a bitmap to DC. I need to call them one after the other. So I do it in ,

void CDlg::OnPaint()
{
for(int i=0;i<10;i++)
   {
     draw1();
     draw2();
    }
}

I also want to add a clickmouse event , i.e, when i click left button of the mouse, the cursor should disappear. So I do it in,

void CDlg::OnLButtonUp(UINT nFlags, CPoint point) {
   ShowCursor(FALSE);
}

But the click mouse event does not occur , unless the 'for loop' in OnPaint() doesn't finish.

I want the for loop to continue , at the same time the click mouse should occur without interrupting the for loop.

How can I make changes or add to get the result?

EDIT: Why the for loop? In draw1() & draw2() , I'm reading first frame of two YUV files respectively, converting to bitmap and then drawing it to DC. I'm toggling between 2 bitmaps after 1 sec. For eg-like a screensaver. Hence the for loop.

mrudulaw
  • 15
  • 1
  • 4
  • 1
    why is there the `for` loop? – cha Mar 16 '16 at 03:13
  • you need multitasking – Ing. Gerardo Sánchez Mar 16 '16 at 03:29
  • 1
    You need to put your loop inside a thread. But I'm not sure why are you drawing more than once. – Captain Wise Mar 16 '16 at 03:43
  • 1
    Painting should never take such a long time, and why do you have a loop like that? Handle the drawing and just return, the mouse event will be handled. Otherwise you ´have to extract the "long time taking routine" in another thread. – xMRi Mar 16 '16 at 06:58
  • Explain more details of what you _actually _ try to achieve. – Jabberwocky Mar 16 '16 at 07:55
  • @everyone--In draw1() & draw2() , I'm reading first frame of two YUV files respectively, converting to bitmap and then drawing it to DC. I'm toggling between 2 bitmaps after 1 sec. For eg-like a screensaver. Hence the for loop. – mrudulaw Mar 16 '16 at 12:53

2 Answers2

0

you have not initialized the variable.

for(int i=;i<10;i++)

initialize the variable

for(int i=0;i<10;i++)// initialize with any value
Himanshu
  • 4,327
  • 16
  • 31
  • 39
-1

Multitasking.

I started a thread in onPaint() - AfxBeginThread(Process, this, THREAD_PRIORITY_NORMAL, 0, 0, NULL);

In Process()- called the for loop function.

It's working now.

Thank you.

mrudulaw
  • 15
  • 1
  • 4
  • Multithreading and GUI programming are orthogonal. While it is possible to properly serialize rendering across threads, you did nothing to do so. This is not an answer. – IInspectable Mar 20 '16 at 13:54
  • You don't even grasp the amount of havok this created. Good luck when things start to break in the most undebuggable ways. This is not an answer to your question. A single-threaded application, using a timer, on the other hand, is a solution. It requires that you learn about the event-based nature of a Windows application. – IInspectable Mar 28 '16 at 19:46