• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 429
  • Last Modified:

Q about CButton: BN_CLICK + BN_DISBALE

Hi guys,

I want to do different actions while a button is clicked, held and when it's released.
If anyone could give me a piece of code for that I would appreciate it.

Following to do:
When the button is clicked, function "start" is called and camera starts moving.
While it is clicked, nothing happens (= camera is still moving).
When button is released, function "stop" is called and camera stops.

How can I realize this ?
I played with GetState() but this seems to be the wrong way...?

Regards
Heike

P.S.:
Please tell me if the points aren't enough.
(unfortunately, this is the profile of my friend and he has just 65 left)
0
mitrakis
Asked:
mitrakis
  • 8
  • 2
  • 2
1 Solution
 
psdavisCommented:
OK, override the WM_KEYDOWN and WM_KEYUP.  

In your OnKeyDown, move the camera, set a flag, and start a timer.
In your timer function, move the camera... (or do nothing).

In your OnKeyUp, turn off your camera, (and turn off your timer if you used one).

Phillip
0
 
mitrakisAuthor Commented:
I do not have OnKeyUp nor OnKeyDown ?...I use CButton.

CButton just gives me "MyClass::OnMyButton".
I have to get the button status myself I think !
(but how can I determine when user releases the mouse button ?)
In message map I have ON_BN_CLICKED and ON_BN_DISABLE available for the button I want to do this.
My Problem now:
I have just ::OnMyButton, but have to check two button states (clicked and released)...have no idea how to find out *when* user releases button !
Some lines of code could be very helpful...

If you need more details please let me know.

Thank you very much
Heike
0
 
mitrakisAuthor Commented:
Hm...maybe I understood right now what you meant by "override on_Keydown"...but I don't know what to do with this info regarding my buttons (not keyboard keys) =;-(

Heike
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
mitrakisAuthor Commented:
Aehh...in case it wasn't clear:
I offer a dialog.
Therein there are lots of buttons.
One of these buttons should behave as described above.

Thanks (and sorry)
Heike
0
 
Tommy HuiCommented:
You will need to subclass CButton (i.e. derive a class from CButton) and use the new class instead of CButton for that particular button. Then in the new class, override WM_LBUTTONDOWN and WM_LBUTTONUP. In the OnLButtonDown() you will need to start a timer and call SetCapture(). OnTimer() will need to move the camera. OnLButtonUp() will call ReleaseCapture() and kill the timer.
0
 
mitrakisAuthor Commented:
thui,

sounds very good !
Unfortunately I cannot imagine how to generate code for this...maybe you can post some here ?
How about a few lines of the interaction between WM_LBUTTONUP and SetCapture ?

Spent my last points and hope I'll get help on that :)

Heike
0
 
mitrakisAuthor Commented:
I would like to credit psdavis :-)

After my friend came back he told me that it would be the easiest to use statics (instead of buttons) and lay bitmaps over these statics.
This way I can use WM_KEYDOWN, WM_KEYUP without overriding any CButton methods.
So psdavis' suggestion showed us the right/easiest way.

Thank you all
Heike
0
 
mitrakisAuthor Commented:
Oopss !
My fault...I meant LButtonUp and LButtonDown...and this was suggested by thui.
So sorry thui...please post an answer again, and you'll get credits...definitely.

Uhh, shame on me =;-))

Heike
0
 
mitrakisAuthor Commented:
thui,

please post an answer !

-Stavi-
0
 
mitrakisAuthor Commented:
ok...don't want to leave this Q unlocked till next year =;-)

psdavis:
Since thui didn't answer just post your answer again to get credits...

Regards
-Stavi-
0
 
Tommy HuiCommented:
Glad you got things working.
0
 
psdavisCommented:
Glad you saw your point thui!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 8
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now