Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Losing mouse wheel events after for deactivated

Status
Not open for further replies.

dguttman

Programmer
Apr 4, 2011
8
Hello,
I am using Builder C++ 6.
I have a TForm descendent which zooms when the mouse wheel is moved. When I deactivate the the form by clicking on something else (e.g. TEdit or TCheckListBox), then click back into the form, other mouse events are handled correctly, but I lose the mouse wheel events. How can I force the form to catch everything again? Minimizing and restoring the form fixes it.

Thanks.
 
Without seeing your code I can only assume some things but have you looked at the OnActivate event for the form?
From Help File said:
Use OnActivate to perform special processing when the form receives focus. A form becomes active when focus is transferred to it (when the user clicks on the form, for example).

Note: The OnActivate event of the application (TApplication), not the form, occurs when Windows switches control from another application.


James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Yes, it hits the OnActivate event correctly, and some of the mouse events, including middle mouse click, are working. It's only the mouse wheel scrolling that seems to be lost. I've tried using SetCaptureControl when the form activates, but so far it doesn't have any effect.
 
Is the zoom feature one that you wrote? If so, can you put a stop in that call and see if you click on the form?

James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Thanks for your help.

No, Zoom() is never called when I encounter this problem, because it's inside OnMouseWheel of the form. It does hit when I use the hotkey.

I found another interesting part of this problem, which is that OnKeyPress events are lost as well. OnKeyDown events still hit as usual.

I have a workaround; if there is a second form open, focusing on that one and back fixes the events. The events only break when the form is deactivated because I click on certain non-form objects, not because I click between two forms.

 
The events only break when the form is deactivated because I click on certain non-form objects . . .
Just out of curiosity, what happens when you put Zoom() in those components' OnExit event?


James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
It looks like it never hits OnExit, even when the object is no longer visible.
 
Odd. A component's OnExit event should fire whenever you move from one component to another. I think I understand why the form's OnActivate event doesn't fire. The form still has focus when you click on another component but loses focus when you minimize it or go to another form. I don't understand why the component's exit event doesn't fire, though.

James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
According to help, "The OnExit event does not occur when switching between forms or between another application and your application." So, I guess it's not firing because I'm moving between a form and a TCheckListBox.

So far today I've tried SetFocus() and UpdateWindowState(); no luck yet. I want to use Activate() to reactivate the form when the TCheckListBox is clicked, but it's telling me it's not accessible there.

I'm thinking I may be able to fix it by changing the checklist to a form, but I still want to find a solution as it is now, in case we add more components with the same problem.
 
Did you put it on the TCheckList's OnExit? That should fire whenever you move from component to component.

James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
The OnExit never fires. OnEnter fires once, the first time I click on it.
 
OnEnter fires once, the first time I click on it.
That is what should happen. When you click on another component in the form or tab to another component, TCheckList's OnExit should then fire. How many components are on the form? If it's the only component, maybe it's not firing because there is nothing else to go to.


James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
I think you're right; I added a TEdit to my main form to test the OnExit event, and it fired correctly. But I guess my TMDIChild objects are not considered components of the mainform? Unfortunately, clicking on another component seems to just transfer the zoom problem.



 
So we know that OnExit fires but you still have the same problem, correct?


James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Yes, the only thing that fixed it was adding a component to the TMDIChild (a button), or switching between forms. Even when I can make the OnExit fire, putting SetFocus() to the form doesn't seem to do anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top