views:

96

answers:

2

What happen until now is this:

Any line happens once, and if I use awhile(1) or while (nFlags == MK_LBUTTON) its working as it should but I get a crash.

The other problem, or maybe the same one is the delay if I will be able to do it, maybe using while() with Timer()?

I was thinking about Timer() to recall the function with delay but I can't call OnLButtonDown() because asI understand it only a message can call it with the arguments.

+1  A: 

Instead of using while loops, remember the old mousestate.

if (oldFlags == MK_LBUTTON && nFlags == MK_LBUTTON) 

That way you know that the user is holding the button and didn't just recently click it.

But you can send WM messages to fool your application that the button has been pressed to if you want. I can't really guide you in any particular direction because im not really sure what you want to accomplish ;P This is the best answer I can give you from the little I understood of your question.

Jonas B
This seems to be correct.
ckv
It didn't work, not for me any way......I am trying to create an airbrush effect, that is why i need to call the lbnckicked function again and again untill i stop pushing the button...
Erez
+1  A: 

In OnLButtonDown() call SetTimer() to start a timer running, eg. every 100ms. Then add OnLButtonUp() and call KillTimer() to stop the timer running. Then, do your code in the OnTimer() function (add WM_TIMER to the message map) and it will run while the mouse is held down.

Note if the user clicks and drags the mouse outside your window, you get OnLButtonDown() called but not OnLButtonUp() which can leave the program thinking the mouse button is stuck down. The functions to deal with this are: call SetCapture() at the same time as SetTimer() and ReleaseCapture() at the same time as KillTimer() to keep receiving mouse messages no matter where the mouse is. I'd advise looking up all the functions I've mentioned in this answer on MSDN and reading up on them for more information.

AshleysBrain